diff --git a/CHANGELOG.txt b/CHANGELOG.txt
new file mode 100644
index 0000000..bcf5404
--- /dev/null
+++ b/CHANGELOG.txt
@@ -0,0 +1,19 @@
+Dec 18, 2010
+  - Fixed bug selecting the wrong revision id
+  - Fixed notice errors in PressFlow 
+
+Oct 3, 2010
+  - Added UPGRADE instructions file
+  - added .install file
+
+Sept 2, 2010
+  - Changed name of module to Similar By Terms 2
+  - added more documentation to README and changed to markdown format
+
+Aug 29, 2010
+  - Moved the generation of tids to the arguments section
+  - Allow limiting to specific vocabularies
+  - Allow passing in of multiple nodes
+  - Added "don't show this node in results" checkbox to nid argument section
+  - Created a displayable field which shows the % of similarity rather than count
+  
\ No newline at end of file
diff --git a/LICENSE.txt b/LICENSE.txt
new file mode 100644
index 0000000..2c095c8
--- /dev/null
+++ b/LICENSE.txt
@@ -0,0 +1,274 @@
+GNU GENERAL PUBLIC LICENSE
+
+              Version 2, June 1991
+
+Copyright (C) 1989, 1991 Free Software Foundation, Inc. 675 Mass Ave,
+Cambridge, MA 02139, USA. Everyone is permitted to copy and distribute
+verbatim copies of this license document, but changing it is not allowed.
+
+                  Preamble
+
+The licenses for most software are designed to take away your freedom to
+share and change it. By contrast, the GNU General Public License is
+intended to guarantee your freedom to share and change free software--to
+make sure the software is free for all its users. This General Public License
+applies to most of the Free Software Foundation's software and to any other
+program whose authors commit to using it. (Some other Free Software
+Foundation software is covered by the GNU Library General Public License
+instead.) You can apply it to your programs, too.
+
+When we speak of free software, we are referring to freedom, not price. Our
+General Public Licenses are designed to make sure that you have the
+freedom to distribute copies of free software (and charge for this service if
+you wish), that you receive source code or can get it if you want it, that you
+can change the software or use pieces of it in new free programs; and that
+you know you can do these things.
+
+To protect your rights, we need to make restrictions that forbid anyone to
+deny you these rights or to ask you to surrender the rights. These restrictions
+translate to certain responsibilities for you if you distribute copies of the
+software, or if you modify it.
+
+For example, if you distribute copies of such a program, whether gratis or for
+a fee, you must give the recipients all the rights that you have. You must make
+sure that they, too, receive or can get the source code. And you must show
+them these terms so they know their rights.
+
+We protect your rights with two steps: (1) copyright the software, and (2)
+offer you this license which gives you legal permission to copy, distribute
+and/or modify the software.
+
+Also, for each author's protection and ours, we want to make certain that
+everyone understands that there is no warranty for this free software. If the
+software is modified by someone else and passed on, we want its recipients
+to know that what they have is not the original, so that any problems
+introduced by others will not reflect on the original authors' reputations.
+
+Finally, any free program is threatened constantly by software patents. We
+wish to avoid the danger that redistributors of a free program will individually
+obtain patent licenses, in effect making the program proprietary. To prevent
+this, we have made it clear that any patent must be licensed for everyone's
+free use or not licensed at all.
+
+The precise terms and conditions for copying, distribution and modification
+follow.
+
+           GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND
+               MODIFICATION
+
+0. This License applies to any program or other work which contains a notice
+placed by the copyright holder saying it may be distributed under the terms
+of this General Public License. The "Program", below, refers to any such
+program or work, and a "work based on the Program" means either the
+Program or any derivative work under copyright law: that is to say, a work
+containing the Program or a portion of it, either verbatim or with
+modifications and/or translated into another language. (Hereinafter, translation
+is included without limitation in the term "modification".) Each licensee is
+addressed as "you".
+
+Activities other than copying, distribution and modification are not covered
+by this License; they are outside its scope. The act of running the Program is
+not restricted, and the output from the Program is covered only if its contents
+constitute a work based on the Program (independent of having been made
+by running the Program). Whether that is true depends on what the Program
+does.
+
+1. You may copy and distribute verbatim copies of the Program's source
+code as you receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice and
+disclaimer of warranty; keep intact all the notices that refer to this License
+and to the absence of any warranty; and give any other recipients of the
+Program a copy of this License along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and you
+may at your option offer warranty protection in exchange for a fee.
+
+2. You may modify your copy or copies of the Program or any portion of it,
+thus forming a work based on the Program, and copy and distribute such
+modifications or work under the terms of Section 1 above, provided that you
+also meet all of these conditions:
+
+a) You must cause the modified files to carry prominent notices stating that
+you changed the files and the date of any change.
+
+b) You must cause any work that you distribute or publish, that in whole or in
+part contains or is derived from the Program or any part thereof, to be
+licensed as a whole at no charge to all third parties under the terms of this
+License.
+
+c) If the modified program normally reads commands interactively when run,
+you must cause it, when started running for such interactive use in the most
+ordinary way, to print or display an announcement including an appropriate
+copyright notice and a notice that there is no warranty (or else, saying that
+you provide a warranty) and that users may redistribute the program under
+these conditions, and telling the user how to view a copy of this License.
+(Exception: if the Program itself is interactive but does not normally print such
+an announcement, your work based on the Program is not required to print
+an announcement.)
+
+These requirements apply to the modified work as a whole. If identifiable
+sections of that work are not derived from the Program, and can be
+reasonably considered independent and separate works in themselves, then
+this License, and its terms, do not apply to those sections when you distribute
+them as separate works. But when you distribute the same sections as part
+of a whole which is a work based on the Program, the distribution of the
+whole must be on the terms of this License, whose permissions for other
+licensees extend to the entire whole, and thus to each and every part
+regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest your rights to
+work written entirely by you; rather, the intent is to exercise the right to
+control the distribution of derivative or collective works based on the
+Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of a
+storage or distribution medium does not bring the other work under the scope
+of this License.
+
+3. You may copy and distribute the Program (or a work based on it, under
+Section 2) in object code or executable form under the terms of Sections 1
+and 2 above provided that you also do one of the following:
+
+a) Accompany it with the complete corresponding machine-readable source
+code, which must be distributed under the terms of Sections 1 and 2 above
+on a medium customarily used for software interchange; or,
+
+b) Accompany it with a written offer, valid for at least three years, to give
+any third party, for a charge no more than your cost of physically performing
+source distribution, a complete machine-readable copy of the corresponding
+source code, to be distributed under the terms of Sections 1 and 2 above on
+a medium customarily used for software interchange; or,
+
+c) Accompany it with the information you received as to the offer to distribute
+corresponding source code. (This alternative is allowed only for
+noncommercial distribution and only if you received the program in object
+code or executable form with such an offer, in accord with Subsection b
+above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source code
+means all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control compilation and
+installation of the executable. However, as a special exception, the source
+code distributed need not include anything that is normally distributed (in
+either source or binary form) with the major components (compiler, kernel,
+and so on) of the operating system on which the executable runs, unless that
+component itself accompanies the executable.
+
+If distribution of executable or object code is made by offering access to
+copy from a designated place, then offering equivalent access to copy the
+source code from the same place counts as distribution of the source code,
+even though third parties are not compelled to copy the source along with the
+object code.
+
+4. You may not copy, modify, sublicense, or distribute the Program except as
+expressly provided under this License. Any attempt otherwise to copy,
+modify, sublicense or distribute the Program is void, and will automatically
+terminate your rights under this License. However, parties who have received
+copies, or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+5. You are not required to accept this License, since you have not signed it.
+However, nothing else grants you permission to modify or distribute the
+Program or its derivative works. These actions are prohibited by law if you
+do not accept this License. Therefore, by modifying or distributing the
+Program (or any work based on the Program), you indicate your acceptance
+of this License to do so, and all its terms and conditions for copying,
+distributing or modifying the Program or works based on it.
+
+6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the original
+licensor to copy, distribute or modify the Program subject to these terms and
+conditions. You may not impose any further restrictions on the recipients'
+exercise of the rights granted herein. You are not responsible for enforcing
+compliance by third parties to this License.
+
+7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues), conditions
+are imposed on you (whether by court order, agreement or otherwise) that
+contradict the conditions of this License, they do not excuse you from the
+conditions of this License. If you cannot distribute so as to satisfy
+simultaneously your obligations under this License and any other pertinent
+obligations, then as a consequence you may not distribute the Program at all.
+For example, if a patent license would not permit royalty-free redistribution
+of the Program by all those who receive copies directly or indirectly through
+you, then the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under any
+particular circumstance, the balance of the section is intended to apply and
+the section as a whole is intended to apply in other circumstances.
+
+It is not the purpose of this section to induce you to infringe any patents or
+other property right claims or to contest validity of any such claims; this
+section has the sole purpose of protecting the integrity of the free software
+distribution system, which is implemented by public license practices. Many
+people have made generous contributions to the wide range of software
+distributed through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing to
+distribute software through any other system and a licensee cannot impose
+that choice.
+
+This section is intended to make thoroughly clear what is believed to be a
+consequence of the rest of this License.
+
+8. If the distribution and/or use of the Program is restricted in certain
+countries either by patents or by copyrighted interfaces, the original copyright
+holder who places the Program under this License may add an explicit
+geographical distribution limitation excluding those countries, so that
+distribution is permitted only in or among countries not thus excluded. In such
+case, this License incorporates the limitation as if written in the body of this
+License.
+
+9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will be
+similar in spirit to the present version, but may differ in detail to address new
+problems or concerns.
+
+Each version is given a distinguishing version number. If the Program specifies
+a version number of this License which applies to it and "any later version",
+you have the option of following the terms and conditions either of that
+version or of any later version published by the Free Software Foundation. If
+the Program does not specify a version number of this License, you may
+choose any version ever published by the Free Software Foundation.
+
+10. If you wish to incorporate parts of the Program into other free programs
+whose distribution conditions are different, write to the author to ask for
+permission. For software which is copyrighted by the Free Software
+Foundation, write to the Free Software Foundation; we sometimes make
+exceptions for this. Our decision will be guided by the two goals of
+preserving the free status of all derivatives of our free software and of
+promoting the sharing and reuse of software generally.
+
+               NO WARRANTY
+
+11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE,
+THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT
+PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE
+STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT
+WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
+INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND
+PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
+NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR
+AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR
+ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE
+LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL,
+SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES
+ARISING OUT OF THE USE OR INABILITY TO USE THE
+PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA
+OR DATA BEING RENDERED INACCURATE OR LOSSES
+SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE
+PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN
+IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF
+THE POSSIBILITY OF SUCH DAMAGES.
+
+          END OF TERMS AND CONDITIONS
diff --git a/README.markdown b/README.markdown
new file mode 100644
index 0000000..6754d24
--- /dev/null
+++ b/README.markdown
@@ -0,0 +1,58 @@
+## Similar By Terms 2 ##
+module for Drupal  
+created by Jeff Robbins / Lullabot
+- - - - - - - - - - - - - - - - - -
+
+This is a from-scratch rewrite of [Similar By Terms](http://drupal.org/project/similarterms) as a [Views](http://drupal.org/project/views) plug-in. The module creates lists of nodes sorted by their similarity to a given node based on commonality of taxonomy terms. Similar By Terms 2 uses Views to create its database queries and display its results. This means that you can define what fields to show, additional sorting, filters, displays, etc. Super flexible!
+
+### Set up: ###
+
+1) Put the module in your modules directory (usually sites/all/modules) and enable it.
+2) Your now have a block called "Related Content" which you can place on your site. This block will *only* appear on node pages and it will list other content similar to this node based on taxonomy terms. The block will also not appear if the node has no taxonomy terms associated with it.
+
+The simplest way to set things up is to add a free tagging vocabulary to the nodes which you'd like to show similarity and then add a bunch (more than 3, less than 20) terms to your content. Then enable the "Similar By Terms" block on the page. Ta da!
+
+### Views integration: ###
+
+If you would like to customize this block or create a new view listing content by similarity, visit admin/build/views. You'll find a view called "Similar By Terms". You can override the default view to customize the block or clone it if you want to create a new view.
+
+- **Arguments** - Similar to what? First off, Similar By Terms needs to know what node it is going to show stuff similar to. This is done through the "Arguments" section of the Views interface. Adding *"Similar By Terms: Nid"* here will allow you to pass in a node id. You can usually set this to 'Provide default argument' > 'Node ID from URL' if you want to show a block on the same page as a node, or a tab on the node page. The settings here will also allow you to limit similarity to terms within certain vocabularies and you can choose whether to show the original node in the listing or not.
+
+- **Sort criteria** - Similar By Terms's magic happens in the "Sort criteria". Simply add *"Similar By Terms: Similarity"* as your first sort criteria and results will be sorted by similarity to the node given as an argument to the view. Set sort order to "Descending" to show most similar stuff at the top. You may also want to provide secondary sorting, so that nodes with the same number of common terms are sorted either alphabetically, or by date.
+
+- **Fields** - There's also a field titled *"Similar By Terms: Similarity"* which shows the commonality between the terms associated with the listed nodes and those of the node being passed in as an argument. This can be output either as a percentage (recommended), or as a raw count of the number of terms which the nodes have in common. This field is particularly useful in testing to make sure that you've got everything set up correctly.
+
+Keep in mind that the more terms used, the better for finding similarity. However, more terms will create slower database queries. Be sure to cache blocks and Views output where possible.
+
+### Example ###
+
+    Given node (passed as argument):
+      Node 1
+        Terms: A, B, C, D, E, F
+        (6 terms total)
+  
+    Results:
+      Node 2
+        Terms: [B, C, D, E, F,] G
+        (5 terms in common with given = similarity 83%)
+      Node 3
+        Terms: [A, B, C, D, E,] H
+        (5 terms in common  = similarity 83%)
+      Node 4
+        Terms: [B, C, D, F,] I, J, K, L, M
+        (4 terms in common = similarity 67%)
+      Node 5
+        Terms: [A, B, C]
+        (3 terms in common = similarity 50%)
+      Node 6
+        Terms: [A, B,] J, K, L, M, N, O, P, Q
+        (2 terms in common = similarity 33%)
+        
+
+### Alternate Uses ###
+Since this is a Views plug-in, it is possible to create listings of related images, videos, or just about anything which you can show with Views. Here are a few tricks you might try:
+
+- __Related tab__: Create a (page display) tab called "Related" on node pages. This page shows teaser listings of similar content.
+- __Advertising using Similar By Terms__: Create an "advertisement" node type with CCK fields for "image" and "URL". Add your "tags" vocabulary to this content type and create some ads. Create a block which shows the linked image of the most similar advertisement node.
+
+Other ideas? Let us know!
\ No newline at end of file
diff --git a/README.txt b/README.txt
deleted file mode 100644
index 312b71f..0000000
--- a/README.txt
+++ /dev/null
@@ -1,24 +0,0 @@
-
-Similar By Terms (similarterms.module)
-by Jeff Robbins
-
-This Drupal module attempts to provide context for content items by 
-displaying a block with links to other similar content. Similarity is 
-based on the taxonomy terms assigned to content. Blocks are available 
-based on similarity within each of the defined vocabularies for a site 
-as well as a block for similarity within all vocabularies.
-
-What does this really mean? How should you use this module?
-
-1) Create a freetagging vocabulary called "Tags" assigned to the content 
-types on which you'd like to display the "Similar" block.
-2) Enable the block called "Similar entries from the Tags vocabulary".
-3) Add keyword tags to the content.
-
-Done!
-
-Now when you go to the page for a tagged content item, a block will show
-up displaying other content in descending order of common tags (terms).
-
-We're using this on Lullabot.com, click on any of the articles at 
-http://www.lullabot.com/articles in order to see the "Similar" block.
\ No newline at end of file
diff --git a/UPGRADE.markdown b/UPGRADE.markdown
new file mode 100644
index 0000000..9dc802d
--- /dev/null
+++ b/UPGRADE.markdown
@@ -0,0 +1,24 @@
+## Upgrading from _Similar By Terms 1_ to _Similar By Terms 2_ ##
+
+Similar By Terms 2 (SBT2) is a Views plug-in, so it works quite differently from Similar By Terms 1 (SBT1). Please read this document thoroughly before upgrading your site. Here are the steps to go through in order to upgrade your site if you were previously using SBT1:
+
+1. Make note of which SBT1 blocks you have enabled, the region assignments, and the settings for each. Write 'em on a piece of paper! You're going to want to remember how you had things set up.
+2. Make sure that you have Views installed and enabled.
+3. Download SBT2 and replace your existing "similarterms" module directory.
+4. Visit update.php and run the update to clear the block cache and remove any cached SBT1 blocks from your site.
+5. Visit admin/build/block and assign the "similarterms: Block" block to the region where you had your SBT1 assigned.
+
+If you were using only the "Similar entries from ANY vocabulary" block, then you can jump below to find out how to map your settings. Otherwise, you'll want to visit admin/build/views and edit the "similarterms" view.
+
+If you were previously using one of SBT1's "Similar entries from the {foo} vocabulary" blocks, then you will probably want to edit the view's *Arguments > Similar By Terms: Nid* configuration and change the "Limit similarity to terms within these vocabularies" setting to match that of {foo}.
+
+If you had multiple "Similar entries from the {foo} vocabulary" blocks enabled then you can create multiple block displays within your view, set the *Arguments* section to override the default display, and then set up blocks with the necessary vocabulary limitations.
+
+### Mapping settings from SBT1 to SBT2 ###
+
+Settings for blocks in SBT1 are found at admin/build/block/configure/similarterms/0 and similar. For the SBT2 blocks, most of these settings are changed using Views. Here's the list of SBT1 options and how they map to Views:
+
+* __Block title:__ This can either be set in the admin/build/block options or by changing the view's *Basic settings > Title* configuration
+* __Item count:__ This is changed in the view's *Basic settings > Items to display* configuration
+* __Show current node as active in list:__ Visit the view's *Arguments > Similar By Terms: Nid* configuration and change the "Include argument node(s) in results"
+* __Content type limit:__ Add a filter to the view to limit by "Node: Type"
diff --git a/similarterms.admin.inc b/similarterms.admin.inc
deleted file mode 100644
index 0b1eff1..0000000
--- a/similarterms.admin.inc
+++ /dev/null
@@ -1,110 +0,0 @@
-<?php
-
-/**
- * @file
- * Settings form.
- */
-
-/**
- * Module settings page.
- */
-function similarterms_admin_settings(&$form_state) {
-  $vocabularies_options = array(
-    'multi_select_and_tags' => t('Display multi-select and tags types only'),
-    'all' => t('Display all vocabularies types'),
-    );
-  $form['similarterms_vocabularies'] = array(
-    '#type' => 'radios',
-    '#title' => t('Vocabularies types to list'),
-    '#default_value' => variable_get("similarterms_vocabularies", 'multi_select_and_tags'),
-    '#options' => $vocabularies_options,
-    '#required' => FALSE,
-  );
-  $display_options = array(
-    'title_only' => t('Display titles only'),
-    'teaser' => t('Display titles and teaser'),
-    );
-  $form['similarterms_display_options'] = array(
-    '#type' => 'radios',
-    '#title' => t('Display Options'),
-    '#default_value' => variable_get('similarterms_display_options', 'title_only'),
-    '#options' => $display_options,
-    '#required' => FALSE,
-    '#prefix' => '<div>',
-    '#suffix' => '</div>',
-  );
-
-  $ncount_options = array(
-    'default' => t('Default sort order'),
-    'unique' => t('Prefer more unique order'),
-    );
-  $form['similarterms_ncount_options'] = array(
-    '#type' => 'radios',
-    '#title' => t('Unique Order Options (Recommended you clear cache at the same time.)'),
-    '#default_value' => variable_get('similarterms_ncount_options', 'default'),
-    '#options' => $ncount_options,
-    '#required' => FALSE,
-    '#prefix' => '<div>',
-    '#suffix' => '</div>',
-  );
-
-  $yesno_opts = array(
-    1 => t('yes'),
-    0 => t('no'),
-  );
-  $form['similarterms_override_options'] = array(
-    '#title' => t('Override Options'),
-    '#description' => t('Allow override of similarterms choices.'),
-    '#default_value' => variable_get('similarterms_override_options', 0),
-    '#options' => $yesno_opts,
-    '#required' => FALSE,
-    '#prefix' => '<div>',
-    '#suffix' => '</div>',
-  );
-
-  $cache_options = drupal_map_assoc(array(0, 300, 600, 900, 1800, 3600, 7200, 21600, 43200, 86400, 604800, 1209600, 2419200, 4838400, 9676800, 31536000),  'format_interval');
-  $cache_options[0] = t('Never');
-
-  $form['similarterms_cache_options'] = array(
-    '#type' => 'select',
-    '#title' => t('Cache Options'),
-    '#default_value' => variable_get('similarterms_cache_options', 3600),
-    '#options' => $cache_options,
-    '#required' => FALSE,
-//      '#prefix' => '<div>',
-//      '#suffix' => '</div>',
-  );
-
-  $form['similarterms_clear_cache'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Clear Cache'),
-    '#description' => t('Clear Similarterms Block Cache'),
-//      '#prefix' => '<div>',
-//      '#suffix' => '</div>',
-  );
-  // Get the weblinks categories to add to the blogroll
-//  $result = db_query('SELECT tid, name FROM {term_data} WHERE vid = %d ORDER BY weight, name', _weblinks_get_vocid());
-
-//  while ($row = db_fetch_object($result)) {
-    // Set which link categories get displayed on the links page
-
-//    $form[$row->tid]['weblinks_page_'. $row->tid] = array(
-//      '#type' => 'checkbox',
-//      '#title' => t($row->name),
-//      '#default_value' => variable_get('weblinks_page_'. $row->tid, 1),
-//      '#required' => FALSE,
-//      '#description' => t('Check to enable this category'),
-//    );
-//  }
-  $form['#submit'][] = 'similarterms_admin_settings_submit';
-  return system_settings_form($form);
-}
-
-function similarterms_admin_settings_submit($form, &$form_state) {
-  if ($form_state['values']['similarterms_clear_cache']) {
-    cache_clear_all('*', 'cache_similarterms', TRUE);
-    drupal_set_message(t('Similarterms Block Cache is now cleared'));
-  }
-}
-
-
diff --git a/similarterms.info b/similarterms.info
index 00c0ed6..36e5cfc 100644
--- a/similarterms.info
+++ b/similarterms.info
@@ -1,6 +1,9 @@
-name = Similar By Terms
+name = "Similar By Terms"
+description = "Use Views to show similar content based on taxonomy terms"
 core = 7.x
-description = "Display a block of other content that is similar by keywords (taxonomy terms)."
-
-files[] = similarterms.module
-files[] = similarterms.install
+dependencies[] = "views"
+package = "Views"
+files[] = similarterms.test
+files[] = views/similarterms_handler_argument_node_nid.inc
+files[] = views/similarterms_handler_field_similar.inc
+files[] = views/similarterms_handler_sort_similar.inc
diff --git a/similarterms.install b/similarterms.install
index 70250af..1e5882c 100644
--- a/similarterms.install
+++ b/similarterms.install
@@ -1,108 +1,28 @@
 <?php
-
 /**
  * @file
- * Similar By Terms install file
+ * Install, update and uninstall functions for the similarterms module.
+ *
  */
 
-/**
- * Implements hook_schema().
- */
-function similarterms_schema() {
-  $schema['similarterms_override'] = array(
-    'module' => 'similarterms',
-    'description' => 'Override information for the similarterms blocks implemented as node type.',
-    'fields' => array(
-      'nid' => array(
-        'description' => 'Node identifier',
-        'type' => 'int',
-        'unsigned' => TRUE,
-        'not null' => TRUE,
-        'default' => 0,
-      ),
-      'vid' => array(
-        'description' => 'Version identifier',
-        'type' => 'int',
-        'unsigned' => TRUE,
-        'not null' => TRUE,
-        'default' => 0,
-      ),
-      'path' => array(
-        'description' => 'Node Id to point to of overide',
-        'type' => 'int',
-        'not null' => TRUE,
-        'default' => 0,
-        'size' => 'tiny',
-      ),
-      'weight' => array(
-        'description' => 'Node weight',
-        'type' => 'int',
-        'not null' => TRUE,
-        'default' => 0,
-        'size' => 'tiny',
-      ),
-    ),
-    'indexes' => array(
-      'nid' => array('nid'),
-      'vid' => array('vid'),
-    ),
-  );
-  $schema['cache_similarterms'] = drupal_get_schema_unprocessed('system', 'cache');
-  $schema['cache_similarterms']['module'] = 'similarterms';
-  $schema['cache_similarterms']['description'] = 'Cache table for the Similar by Terms Module.';
 
-  return $schema;
-}
 
 /**
  * Implements hook_update().
  */
-function similarterms_update_7102() {
-  $schema['similarterms_override'] = array(
-    'module' => 'similarterms',
-    'description' => 'Override information for the similarterms blocks implemented as node type.',
-    'fields' => array(
-      'nid' => array(
-        'description' => 'Node identifier',
-        'type' => 'int',
-        'unsigned' => TRUE,
-        'not null' => TRUE,
-        'default' => 0,
-      ),
-      'vid' => array(
-        'description' => 'Version identifier',
-        'type' => 'int',
-        'unsigned' => TRUE,
-        'not null' => TRUE,
-        'default' => 0,
-      ),
-      'path' => array(
-        'description' => 'Node Id to point to of overide',
-        'type' => 'int',
-        'not null' => TRUE,
-        'default' => 0,
-        'size' => 'tiny',
-      ),
-      'weight' => array(
-        'description' => 'Node weight',
-        'type' => 'int',
-        'not null' => TRUE,
-        'default' => 0,
-        'size' => 'tiny',
-      ),
-    ),
-    'indexes' => array(
-      'nid' => array('nid'),
-      'vid' => array('vid'),
-    ),
-  );
-  $schema['cache_similarterms'] = drupal_get_schema_unprocessed('system', 'cache');
-  $schema['cache_similarterms']['module'] = 'similarterms';
-  $schema['cache_similarterms']['description'] = 'Cache table for the Similar by Terms Module.';
+function similarterms_update_6200() {
   $ret = array();
 
-  db_drop_table('cache_similarterms');
-  db_create_table('cache_similarterms', $schema['cache_similarterms']);
-  db_create_table('similarterms_override', $schema['similarterms_override']);
-  return $ret;
+  // Intentially removed to prevent confusion.
+  //   I don't want administrators to think that their settings have been converted.
+
+  // only the 'ANY vocabulary' block is converted... without any settings:
+  //$ret[] = update_sql("UPDATE {block} SET module='views', delta='similarterms-block_1' WHERE module='similarterms' AND delta=0");
+
+  cache_clear_all('*', 'cache_block', TRUE);
+  cache_clear_all('*', 'cache_views', true);
+  // hook_update_N() no longer returns a $ret array. Instead, return
+  // nothing or a translated string indicating the update ran successfully.
+  // See http://drupal.org/node/224333#update_sql.
+  return t('TODO Add a descriptive string here to show in the UI.') /* $ret */;
 }
diff --git a/similarterms.module b/similarterms.module
index 118dd86..9cdf8ea 100644
--- a/similarterms.module
+++ b/similarterms.module
@@ -1,541 +1,12 @@
 <?php
-// by Jeff Robbins
 
 /**
- * @file
- * Similar By Terms module displays a block with similar content
- * based on taxonomy terms.
+ * Implements hook_views_api().
+ * Notifies the Views module that we're compatible with a particular API revision.
  */
-
-/**
- * Display help and module information
- * @param path which path of the site we're displaying help
- * @param arg array that holds the current path as would be returned from arg() function
- * @return help text for the path
- */
-
-function similarterms_help($path, $arg) {
-  $output = '';
-  switch ($path) {
-    case "admin/help#similarterms":
-      $output = '<p>' . t("Displays a block with similar content based on taxonomy terms.") . '</p>';
-      break;
-  }
-  return $output;
-} // function similarterms_help
-
-/**
- * Valid permissions for this module
- * @return array An array of valid permissions for the similarterms module
- */
-function similarterms_permission() {
+function similarterms_views_api() {
   return array(
-    'access similarterms content' => array(
-      'title' => t('access similarterms content'),
-      'description' => t('Allows role the abilty to see similar by terms content'),
-    ),
-    'administer similarterms content' => array(
-      'title' => t('administer similarterms content'),
-      'description' => t('Allows role the abilty to see administer similar by terms settings'),
-    ),
+    'api' => 3,
+    'path' => drupal_get_path('module', 'similarterms') . '/views',
   );
-} // function similarterms_perm()
-
-
-/**
- * Implements hook_block_info().
- */
-function similarterms_block_info() {
-  $blocks['all'] = array(
-    'info' => t('Similar entries from ANY vocabulary.'),
-    'cache' => DRUPAL_CACHE_PER_ROLE | DRUPAL_CACHE_PER_PAGE,
-  );
-  if (variable_get("similarterms_vocabularies", 'multi_select_and_tags') == 'all') {
-    foreach (taxonomy_get_vocabularies() as $v) {
-      $blocks[$v->vid] = array(
-        'info' => t('Similar entries from the @vocab vocabulary.', array('@vocab' => $v->name)),
-        'cache' => DRUPAL_CACHE_PER_ROLE | DRUPAL_CACHE_PER_PAGE
-      );
-    }
-  }
-  else {
-    foreach (taxonomy_get_vocabularies() as $v) {
-      // this only makes sense for multi-select vocabularies and free tagging
-      if ($v->multiple || $v->tags) {
-        $blocks[$v->vid] = array(
-          'info' => t('Similar entries from the @vocab vocabulary.', array('@vocab' => $v->name)),
-          'cache' => DRUPAL_CACHE_PER_ROLE | DRUPAL_CACHE_PER_PAGE
-        );
-      }
-    }
-  }
-  return $blocks;
 }
-
-/**
- * Implements hook_block_view().
- */
-function similarterms_block_view($delta = '') {
-  $block = array(
-    'subject' => t('Similar'),
-    'content' => theme('similarterms', variable_get('similarterms_display_options', 'title_only'), similarterms_list($delta))
-  );
-  return $block;
-}
-
-/**
- * Implements hook_block_view().
- */
-function similarterms_block_configure($delta = '') {
-  $form['count'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Item count'),
-    '#default_value' => variable_get('simterms_count_' . $delta, 5),
-    '#size' => 3,
-    '#description' => t('The maximum number of similar items to display'),
-  );
-  //petertj addition to configuration to permit display of current node in list
-  $form['showcurrentnode'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Show current node as active in the list'),
-    '#default_value' => variable_get('similarterms_showcurrentnode_' . $delta, FALSE),
-    '#required' => FALSE,
-  );
-  //mimo addition to configuration to limit to same page type
-  $types = array('0' => t('<none>'), '1' => t('same as current'));
-  $arr_types_obj = node_type_get_types();
-  foreach ($arr_types_obj as $type => $obj) {
-    $types[$type] = $obj->name;
-  }
-  $form['sametype'] = array(
-    '#type' => 'select',
-    '#title' => t('Content type limit'),
-    '#default_value' => variable_get('simterms_sametype_' . $delta, FALSE),
-    '#options' => $types,
-    '#description' => t('Limit to pages of this or these content type(s)'),
-    '#multiple' => TRUE
-  );
-  if ($delta != 'all') {
-    $terms = array();
-    $tree = taxonomy_get_tree($delta);
-    foreach ($tree as $term) {
-      $terms[$term->tid] = $term->name;
-    }
-    $form['ignoreterms'] = array(
-      '#type' => 'select',
-      '#title' => t('Terms to be ignored'),
-      '#default_value' => variable_get('simterms_ignoreterms_' . $delta, array()),
-      '#options' => $terms,
-      '#description' => t('Ignore selected terms here from being used to search for similar entries'),
-      '#multiple' => TRUE
-    );
-  }
-  return $form;
-}
-
-/**
- * Perform the "save" op for hook_block().
- *
- * @param $delta
- *   String specifying which block to proocess.
- * @param $edit
- *   Array containg the form input.
- *
- * @return
- *   None. Values are saved as system variables.
- */
-function similarterms_block_save($delta = '', $edit = array()) {
-  variable_set('simterms_count_' . $delta, $edit['count']);
-  variable_set('simterms_sametype_' . $delta, $edit['sametype']);
-  variable_set('simterms_ignoreterms_' . $delta, $edit['ignoreterms']);
-  variable_set('similarterms_showcurrentnode_' . $delta, $edit['showcurrentnode']);
-}
-
-/**
- * Output the block
- *
- * @param $vocid
- *   integer - vocabulary id, leave out to use ALL terms for this node
- * @param $nid
- *   integer - nid, leave out to use the current node
- * @return
- *   an array of node objects
- */
-function similarterms_list($vocid = 'all', $nid = NULL) {
-  $lists = array();
-  $nodes = array();
-  $args = array();
-  $list_num = 0;
-  $sql = "";
-  $cache_lifetime = variable_get('similarterms_cache_options', 3600);
-  $count = variable_get('simterms_count_' . $vocid, 5);
-
-  if (arg(0) == 'node' && is_numeric(arg(1)) && !$nid) {
-    $nid = arg(1);
-  }
-
-  if ($nid != NULL) {
-    $cid = "$vocid:$nid";
-    if ($cache_lifetime) {
-      if ($cached = cache_get($cid, 'cache_similarterms')) {
-        return $cached->data;
-      }
-    }
-    if (variable_get('similarterms_override_options', 0)) {
-      $lists = similarterms_get_overrides($nid, $vocid);
-      if ($lists[$vocid]) {
-        foreach ($lists[$vocid] as $nid_list) {
-          if (is_numeric($nid_list)) {
-            if ($list_num <= $count) {
-              $list_num = $list_num + 1;
-              $nodes[] = node_load($nid_list);
-            }
-          }
-        }
-      }
-    }
-    $node_obj = node_load($nid);
-
-    if ($vocid == 'all') {
-      $terms = array_keys(taxonomy_node_get_terms($node_obj));
-    }
-    else {
-      $terms = array_keys(taxonomy_node_get_terms_by_vocabulary($node_obj, $vocid));
-    }
-
-    // Filter out some terms
-    $terms_filter = variable_get('simterms_ignoreterms_' . $vocid, array());
-
-    foreach ($terms_filter as $v) {
-      $idx = array_search($v, $terms);
-      if ($idx >= 0) {
-        unset($terms[$idx]);
-      }
-    }
-
-    if (!empty($terms)) {
-      //past events
-      $pasts = array();
-
-      $query = db_select('node', 'n', $options)
-        ->addField('n', 'nid')
-        ->addField('n', 'title')
-        ->addExpression('COUNT(nid)', 'ncount')
-        ->innerJoin('term_node', 'tn', 'n.vid = tn.vid')
-        ->condition('tn.tid', $terms, 'IN');
-
-      $types = variable_get('simterms_sametype_' . $vocid, FALSE);
-      if (($types !== FALSE) && is_array($types) && count($types) > 0 && ($types['0'] == NULL) ) {
-        if ($types[1]) {
-          $node_obj = node_load($nid);
-          $types[1] = $node_obj->type;
-        }
-        $query->condition('n.type', $types, 'IN');
-      }
-
-      //if showcurrentnode option is false (default state), create filter for query.
-      if (!variable_get('similarterms_showcurrentnode_' . $vocid, FALSE)) {
-        $query->condition('n.nid', $nid, '<>');
-      }
-
-      $query
-        ->condition('n.status', 1)
-        ->condition('n.moderate', 0)
-        ->condition('n.language', '')
-        ->condition('n.language', $node_obj->language)
-        ->groupBy('n.nid')
-        ->groupBy('n.title')
-        ->groupBy('n.created');
-
-      if (variable_get('similarterms_ncount_options', 'default') == 'default') {
-        $query->orderBy('ncount', 'DESC');
-      }
-      else {
-        $query->orderBy('ncount', 'ASC');
-      }
-      $query->orderBy('n.created', 'DESC');
-      $query->range(0, $count);
-
-      $result = $query->execute();
-      foreach ($result as $record) {
-        $r = $record->fetchObject();
-        $nodes[] = node_load($r->nid);
-      }
-
-      // Allow modules to alter the list of nodes by implementing a hook.
-      // Design pattern from comment_invoke_comment().
-      foreach (module_implements('similarterms') as $name) {
-        $function = $name . '_similarterms';
-        $function($nodes, $node_obj);
-      }
-
-      if ($cache_lifetime) {
-        cache_set($cid, $nodes, 'cache_similarterms', REQUEST_TIME + $cache_lifetime);
-      }
-    }
-  }
-  return $nodes;
-}
-
-/**
- * Implements hook_flush_caches().
- */
-function similarterms_flush_caches() {
-  return array('cache_similarterms');
-}
-
-/**
- * Implements hook_form_alter().
- */
-function similarterms_form_alter(&$form, &$form_state, $form_id) {
-  if (!empty($form['#node_edit_form'])) {
-    if (!variable_get('similarterms_override_options', 0)) {
-      return;
-    }
-    // no need to alter form if block module is off
-    if (! module_exists('block')) {
-      return;
-    }
-    $blocks = similarterms_get_active_block_vocabularies();
-    // no need to alter form if no similarterms blocks are active
-    if (sizeof($blocks) == 0) {
-      return;
-    }
-    $overrides = array();
-    if (is_numeric($form['nid']['#value'])) {
-      $overrides = similarterms_get_overrides($form['nid']['#value']);
-    }
-    $form['similarterms'] = array(
-      '#type' => 'fieldset',
-      '#title' => t('Similar Terms'),
-      '#description' => t('Override the links generated by similar terms module.'),
-      '#collapsible' => 1,
-      '#collapsed' => sizeof($overrides) ? 0 : 1,
-    );
-    $node_type = $form['type']['#value'];
-    $no_similarterms = 1;
-    foreach (similarterms_taxonomy_get_vocabularies() as $v) {
-      if (! $blocks[$v->vid]) {
-        continue;
-      }
-      $types = variable_get('simterms_sametype_' . $v->vid, array('0' => '0'));
-      if (! $types[$node_type] && ! isset($types[0])) {
-        continue;
-      }
-      $no_similarterms = 0;
-      $form['similarterms']['similarterms_vid_' . $v->vid] = array(
-        '#type' => 'fieldset',
-        '#title' => $v->name,
-        '#collapsible' => 1,
-        '#collapsed' => sizeof($overrides[$v->vid]) ? 0 : 1,
-        '#tree' => 1,
-      );
-      $form['similarterms']['similarterms_vid_' . $v->vid]['similarterms_paths'] = array(
-        '#type' => 'fieldset',
-        '#title' => t('Paths'),
-        '#tree' => 1,
-      );
-      $count = variable_get('simterms_count_' . $v->vid, 5);
-      for ($i = 0; $i < $count; $i++) {
-        $default_value = '';
-        if ($overrides[$v->vid][$i]) {
-          $default_value = drupal_lookup_path('alias', 'node/' . $overrides[$v->vid][$i]);
-          if (! $default_value) {
-            $default_value = 'node/' . $overrides[$v->vid][$i];
-          }
-        }
-        $form['similarterms']['similarterms_vid_' . $v->vid]['similarterms_paths'][$i] = array(
-          '#type' => 'textfield',
-          '#title' => t('Path %d', array('%d' => $i + 1)),
-          '#default_value' => $default_value ? $default_value : '',
-        );
-      }
-      $form['similarterms']['similarterms_vid_' . $v->vid]['similarterms_override_delete'] = array(
-        '#type' => 'checkbox',
-        '#title' => t('Delete Similar Terms Overrides?'),
-        '#description' => t('If this option is checked all paths will be deleted for this vocabulary.'),
-        '#default_value' => 0,
-      );
-    }
-    if ($no_similarterms) {
-      unset($form['similarterms']);
-    }
-  }
-}
-
-/**
- * This function returns a list of overrides
- */
-function similarterms_get_overrides($nid, $vid = NULL) {
-  $paths = array();
-  $query = "SELECT * FROM {similarterms_override} WHERE nid = '%s'";
-  $args = array($nid);
-  if ($vid) {
-    $query .= " AND vid = %s";
-    $args[] = $vid;
-  }
-  $result = db_query($query, $args);
-  while ($object = db_fetch_object($result)) {
-    $paths[$object->vid][] = $object->path;
-  }
-  return $paths;
-}
-
- /**
- * Implements hook_node_delete().
- */
-function similarterms_node_delete($node, $vid = NULL) {
-  if (!variable_get('similarterms_override_options', 0)) {
-    return;
-  }
-  $query = "DELETE FROM {similarterms_override} WHERE nid = %d";
-  $args = array($node->nid);
-  if ($vid) {
-    $query .= " AND vid = %d";
-    $args[] = $vid;
-  }
-  db_query($query, $args);
-}
-
-/**
- * Implements hook_node_update().
- */
-function similarterms_node_update($node) {
-  similarterms_node_save($node);
-}
-
-/**
- * Implements hook_node_insert().
- */
-function similarterms_node_insert($node) {
-  similarterms_node_save($node);
-}
-
-/**
- * Function to populate overrides table
- */
-function similarterms_node_save($node) {
-  if (!variable_get('similarterms_override_options', 0)) {
-    return;
-  }
-  $result = array();
-  $query = "INSERT INTO {similarterms_override} (nid, path, vid) VALUES(%d, %d, %d)";
-  foreach (similarterms_taxonomy_get_vocabularies() as $v) {
-    $vid = 'similarterms_vid_' . $v->vid;
-    $alias =& $node->$vid;
-    similarterms_node_delete($node, $v->vid);
-    if ($alias['similarterms_override_delete']) {
-      continue;
-    }
-    foreach ($alias['similarterms_paths'] as $id => $path) {
-      $pieces = explode('/', $path);
-      if (sizeof($pieces) == 2 && $pieces[0] == "node" && is_numeric($pieces[1])) {
-        $nid = $pieces[1];
-      }
-      else {
-        $path = drupal_lookup_path('source', $path);
-        $pieces = explode('/', $path);
-        $nid = $pieces[1];
-      }
-      if ($nid) {
-        $args = array(
-        $node->nid,
-        $nid,
-        $v->vid
-        );
-        $result[$id] = db_query($query, $args);
-      }
-    }
-  }
-}
-
-/**
- * Implements hook_node_validate().
- */
-function similarterms_node_validate($node, $form) {
-  if (!variable_get('similarterms_override_options', 0)) {
-    return;
-  }
-  foreach (similarterms_taxonomy_get_vocabularies() as $v) {
-    $vid = 'similarterms_vid_' . $v->vid;
-    $alias =& $node->$vid;
-    // Make sure that the paths are valid
-    foreach ($alias['similarterms_paths'] as $id => $path) {
-      $pieces = explode('/', $path);
-      if (sizeof($pieces) == 2 && $pieces[0] == "node" && is_numeric($pieces[1])) {
-        // If there's a better way to check if a node exists, replace this code
-        $thisnode = node_load($pieces[1]);
-        if (! $thisnode->nid) {
-          form_set_error("$vid][similarterms_paths][$id", t('%path is not a valid path', array('%path' => $path)));
-        }
-      }
-      elseif ($path == '') {
-        continue;
-      }
-      elseif (! drupal_lookup_path('source', $path)) {
-        form_set_error("$vid][similarterms_paths][$id", t('%vocab %path is not a valid path', array('%path' => $path, '%vocab' => $v->name)));
-      }
-    }
-  }
-}
-
-/**
- * This function returns a list of all blocks for similarterms
- *
- * Note: I could not find a public function in the block module to do this
- * so I wrote this function based on _block_rehash(). If there's a better
- * way to do this, this code should be refactored
- */
-function similarterms_get_active_block_vocabularies() {
-  // TODO: add in code to check for blockcache module
-  global $theme_key;
-  init_theme();
-  $result = db_query("SELECT * FROM {blocks} WHERE theme = '%s' AND module = '%s'", $theme_key, 'similarterms');
-  while ($object = db_fetch_object($result)) {
-    if ($object->status) {
-      $blocks[$object->delta] = 1;
-    }
-  }
-  return $blocks;
-}
-
-/**
- * This function gets taxonomy vocabularies and add in 0 for "all vocabs";
- */
-function similarterms_taxonomy_get_vocabularies() {
-  $object = taxonomy_get_vocabularies();
-  $object[0]->vid = 0;
-  $object[0]->name = t('Any Vocabulary');
-  return $object;
-}
-
-/**
- * Implements hook_menui().
- */
-function  similarterms_menu() {
-  // Admin settings for the site.
-  $items['admin/settings/similarterms'] = array(
-    'title' => 'Similar By Terms',
-    'description' => 'Basic Settings for similar term most settings are in the blocks config.',
-    'page callback' => 'drupal_get_form',
-    'page arguments' => array('similarterms_admin_settings'),
-    'file' => 'similarterms.admin.inc',
-    'access arguments' => array('administer site configuration'),
-    'type' => MENU_NORMAL_ITEM, // optional
-  );
-  return $items;
-}
-
-/**
- * Theme function for similar block
- *
- */
-function similarterms_theme() {
-  return array(
-    'similarterms' => array(
-      'template'  => 'similarterms',
-      'arguments' => array('display_options' => NULL, 'items' => NULL),
-    ),
-  );
-}
-
diff --git a/similarterms.test b/similarterms.test
new file mode 100644
index 0000000..96d33e8
--- /dev/null
+++ b/similarterms.test
@@ -0,0 +1,303 @@
+<?php
+
+/**
+ * @file
+ * Definition of similarTermsTestCase.
+ *
+ * @todo
+ * - Test the vocbular option in the argument handler.
+ * - Test the field_similar, sort_similar handler.
+ */
+
+/**
+ * Tests functionality of similar terms module.
+ */
+class similarTermsTestCase extends TaxonomyWebTestCase {
+  /**
+   * Stores all nids.
+   * @var array
+   */
+  public $nids;
+
+  /**
+   * Stores all tids.
+   * @var array
+   */
+  public $tids;
+
+  /**
+   * Stores all node-id's keyed by tid.
+   * @var array
+   */
+  public $nodes_per_term;
+
+  /**
+   * Contains the used vocabulary.
+   */
+  public $vocabulary;
+  public $node_type;
+  public $field;
+  public $field_name;
+
+  public static function getInfo() {
+    return array(
+      'name' => 'Similarterms',
+      'description' => 'Test the Similarterms module',
+      'group' => 'Similarterms',
+    );
+  }
+  protected function setUp() {
+    parent::setUp('views', 'taxonomy', 'node', 'similarterms');
+
+    // Create a vocabulary and some terms.
+    $this->vocabulary = $this->createVocabulary();
+    for ($i = 0; $i < 3; $i++) {
+      $term = $this->createTerm($this->vocabulary);
+      $this->tids[] = $term->tid;
+    }
+
+    // Create a nodetype and attach a taxonomy field to it.
+    $this->node_type = $this->drupalCreateContentType();
+    $this->field_name = 'field_test_taxonomy';
+    $this->field = array(
+      'field_name' => $this->field_name,
+      'type' => 'taxonomy_term_reference',
+      'cardinality' => FIELD_CARDINALITY_UNLIMITED,
+      'settings' => array(
+        'allowed_values' => array(
+          array(
+            'vocabulary' => $this->vocabulary->machine_name,
+            'parent' => 0,
+          ),
+        ),
+      ),
+    );
+    field_create_field($this->field);
+    $this->instance = array(
+      'field_name' => $this->field_name,
+      'bundle' => $this->node_type->type,
+      'entity_type' => 'node',
+      'widget' => array(
+        'type' => 'options_select',
+      ),
+      'display' => array(
+        'default' => array(
+          'type' => 'taxonomy_term_reference_link',
+        ),
+      ),
+    );
+    field_create_instance($this->instance);
+
+
+    // Create the used nodes.
+    // First create a node with a term which is not used by other nodes.
+    $this->createNodeWithTerm($this->tids[0]);
+    // Create a node with a term which is is used by the third node as well.
+    $this->createNodeWithTerm($this->tids[1]);
+    // The third node should have the term of the second and forth.
+    $this->createNodeWithTerm(array($this->tids[1], $this->tids[2]));
+    $this->createNodeWithTerm(array($this->tids[2]));
+  }
+
+  /**
+   * Create a node with certain terms.
+   * @param array $tids
+   *   An array of all taxonomy terms.
+   * @param array $edit
+   *   The edit array @see DrupalWebTestCase::drupalCreateNode.
+   */
+  public function createNodeWithTerm($tids, array $edit = array()) {
+    $tids = (array) $tids;
+    if (!isset($edit['type'])) {
+      $edit['type'] = $this->node_type->type;
+    }
+    foreach ($tids as $tid) {
+      $edit[$this->field_name][LANGUAGE_NONE][] = array('tid' => $tid);
+    }
+
+    $node = $this->drupalCreateNode($edit);
+    $this->nids[] = $node->nid;
+    foreach ($tids as $tid) {
+      $this->nodes_per_term[$tid][] = $node->nid;
+    }
+  }
+
+  function testSimilarTerms() {
+    $nid_alias = 'node_nid';
+
+    foreach ($this->nids as $nid) {
+      $node = node_load($nid);
+      $view = $this->viewSimilarTerms();
+      $view->set_display();
+      $view->pre_execute(array($nid));
+      $view->execute();
+      switch ($nid) {
+        case 1:
+          $this->assertEqual(count($view->result), 0, "Take sure that a node without a similar term doesn't generate a view result");
+          break;
+        case 2:
+          $this->assertEqual(count($view->result), 1, "Take sure that the right amount of result are returned");
+          $this->assertIdenticalResultset($view, array(array($nid_alias => 3)));
+          break;
+
+        case 3:
+          $this->assertEqual(count($view->result), 2, "Take sure that the right amount of result are returned");
+          $this->assertIdenticalResultset($view, array(array($nid_alias => 2), array($nid_alias => 4)));
+          break;
+
+        case 4:
+          $this->assertEqual(count($view->result), 1, "Take sure that the right amount of result are returned");
+          $this->assertIdenticalResultset($view, array(array($nid_alias => 4)));
+          break;
+
+      }
+
+      $view->destroy();
+    }
+  }
+
+  function testSimilarTermsIncludeArgs() {
+    foreach ($this->nids as $nid) {
+      $node = node_load($nid);
+      $view = $this->viewSimilarTerms();
+      $view->set_display();
+      $view->pre_execute(array($nid));
+      $view->argument['nid']->options['include_args'] = TRUE;
+      $view->execute();
+      switch ($nid) {
+        case 1:
+          $this->assertEqual(count($view->result), 1, "Take sure that a node without a similar term doesn't generate a view result");
+          $this->assertIdenticalResultset($view, array(array('nid' => 1)), array('node_nid' => 'nid'));
+          break;
+        case 2:
+          $this->assertEqual(count($view->result), 2, "Take sure that the right amount of result are returned");
+          $this->assertIdenticalResultset($view, array(array('nid' => 2), array('nid' => 3)), array('node_nid' => 'nid'));
+          break;
+
+        case 3:
+          $this->assertEqual(count($view->result), 3, "Take sure that the right amount of result are returned");
+          $this->assertIdenticalResultset($view, array(array('nid' => 2), array('nid' => 3), array('nid' => 4)), array('node_nid' => 'nid'));
+          break;
+
+        case 4:
+          $this->assertEqual(count($view->result), 2, "Take sure that the right amount of result are returned");
+          $this->assertIdenticalResultset($view, array(array('nid' => 3), array('nid' => 4)), array('node_nid' => 'nid'));
+          break;
+
+      }
+
+      $view->destroy();
+    }
+  }
+
+  public function viewSimilarTerms() {
+    $view = new view;
+    $view->name = 'test_similarterms';
+    $view->description = '';
+    $view->tag = 'default';
+    $view->base_table = 'node';
+    $view->human_name = 'test_similarterms';
+    $view->core = 7;
+    $view->api_version = '3.0';
+    $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
+
+    /* Display: Master */
+    $handler = $view->new_display('default', 'Master', 'default');
+    $handler->display->display_options['title'] = 'test';
+    $handler->display->display_options['access']['type'] = 'perm';
+    $handler->display->display_options['cache']['type'] = 'none';
+    $handler->display->display_options['query']['type'] = 'views_query';
+    $handler->display->display_options['query']['options']['distinct'] = TRUE;
+    $handler->display->display_options['exposed_form']['type'] = 'basic';
+    $handler->display->display_options['pager']['type'] = 'full';
+    $handler->display->display_options['pager']['options']['items_per_page'] = '10';
+    $handler->display->display_options['style_plugin'] = 'default';
+    $handler->display->display_options['row_plugin'] = 'fields';
+    /* Contextual filter: Similar By Terms: Nid */
+    $handler->display->display_options['arguments']['nid']['id'] = 'nid';
+    $handler->display->display_options['arguments']['nid']['table'] = 'similarterms';
+    $handler->display->display_options['arguments']['nid']['field'] = 'nid';
+    $handler->display->display_options['arguments']['nid']['default_argument_type'] = 'fixed';
+    $handler->display->display_options['arguments']['nid']['summary']['number_of_records'] = '0';
+    $handler->display->display_options['arguments']['nid']['summary']['format'] = 'default_summary';
+    $handler->display->display_options['arguments']['nid']['summary_options']['items_per_page'] = '25';
+    $handler->display->display_options['arguments']['nid']['vocabularies'] = array(
+      1 => 0,
+    );
+    $handler->display->display_options['arguments']['nid']['include_args'] = 0;
+    /* Sort criterion: Content: Nid */
+    $handler->display->display_options['sorts']['nid']['id'] = 'nid';
+    $handler->display->display_options['sorts']['nid']['table'] = 'node';
+    $handler->display->display_options['sorts']['nid']['field'] = 'nid';
+
+    return $view;
+  }
+
+  /**
+   * Helper function: verify a result set returned by view.
+   *
+   * The comparison is done on the string representation of the columns of the
+   * column map, taking the order of the rows into account, but not the order
+   * of the columns.
+   *
+   * @param $view
+   *  An executed View.
+   * @param $expected_result
+   *  An expected result set.
+   * @param $column_map
+   *  An associative array mapping the columns of the result set from the view
+   *  (as keys) and the expected result set (as values).
+   */
+  protected function assertIdenticalResultset($view, $expected_result, $column_map = array(), $message = 'Identical result set') {
+    return $this->assertIdenticalResultsetHelper($view, $expected_result, $column_map, $message, 'assertIdentical');
+  }
+
+  /**
+   * Helper function: verify a result set returned by view..
+   *
+   * Inverse of ViewsTestCase::assertIdenticalResultset().
+   *
+   * @param $view
+   *  An executed View.
+   * @param $expected_result
+   *  An expected result set.
+   * @param $column_map
+   *  An associative array mapping the columns of the result set from the view
+   *  (as keys) and the expected result set (as values).
+   */
+  protected function assertNotIdenticalResultset($view, $expected_result, $column_map = array(), $message = 'Identical result set') {
+    return $this->assertIdenticalResultsetHelper($view, $expected_result, $column_map, $message, 'assertNotIdentical');
+  }
+
+  protected function assertIdenticalResultsetHelper($view, $expected_result, $column_map, $message, $assert_method) {
+    // Convert $view->result to an array of arrays.
+    $result = array();
+    foreach ($view->result as $key => $value) {
+      $row = array();
+      foreach ($column_map as $view_column => $expected_column) {
+        // The comparison will be done on the string representation of the value.
+        $row[$expected_column] = (string) $value->$view_column;
+      }
+      $result[$key] = $row;
+    }
+
+    // Remove the columns we don't need from the expected result.
+    foreach ($expected_result as $key => $value) {
+      $row = array();
+      foreach ($column_map as $expected_column) {
+        // The comparison will be done on the string representation of the value.
+        $row[$expected_column] = (string) (is_object($value) ? $value->$expected_column : $value[$expected_column]);
+      }
+      $expected_result[$key] = $row;
+    }
+
+    // Reset the numbering of the arrays.
+    $result = array_values($result);
+    $expected_result = array_values($expected_result);
+
+    $this->verbose('<pre>Returned data set: ' . print_r($result, TRUE) . "\n\nExpected: ". print_r($expected_result, TRUE));
+
+    // Do the actual comparison.
+    return $this->$assert_method($result, $expected_result, $message);
+  }
+}
diff --git a/similarterms.tpl.php b/similarterms.tpl.php
deleted file mode 100644
index a22766e..0000000
--- a/similarterms.tpl.php
+++ /dev/null
@@ -1,33 +0,0 @@
-<?php
-
-/**
- * @file
- * simterms.tpl.ph
- * Theme implementation to display a list of related content.
- *
- * Available variables:
- * - $display_options:
- *    'title_only' => 'Display titles only',
- *    'teaser' => 'Display titles and teaser',
- * - $items: the list.
- */
-if ($items) {
-$items_ls = array();
-  if ($display_options == 'title_only') {
-    foreach ($items as $node) {
-      $items_ls[] = l($node->title, 'node/'. $node->nid);
-    }
-    print theme('item_list', $items_ls);
-  }
-  if ($display_options == 'teaser') {
-    $output = '';
-    foreach ($items as $node) {
-      $output .= '<li>'. l($node->title, 'node/'. $node->nid);
-      $output .= ' - '. $node->teaser;
-      $output .= "</li>\n";
-    }
-    if ($output) {
-      echo "<ul>" . $output . "</ul>";
-    }
-  }
-}
diff --git a/translations/de.po b/translations/de.po
deleted file mode 100644
index a2289f9..0000000
--- a/translations/de.po
+++ /dev/null
@@ -1,76 +0,0 @@
-#
-# LANGUAGE translation of Drupal (general)
-# Copyright YEAR NAME <EMAIL@ADDRESS>
-# Generated from files:
-#  similarterms.module,v 1.9 2008/06/21 04:18:31 rmiddle
-#  similarterms.info,v 1.2 2008/06/19 16:43:46 rmiddle
-#
-#, fuzzy
-msgid ""
-msgstr ""
-"Project-Id-Version: PROJECT VERSION\n"
-"POT-Creation-Date: 2008-06-29 21:54-0400\n"
-"PO-Revision-Date: YYYY-mm-DD HH:MM+ZZZZ\n"
-"Last-Translator: NAME <EMAIL@ADDRESS>\n"
-"Language-Team: LANGUAGE <EMAIL@ADDRESS>\n"
-"MIME-Version: 1.0\n"
-"Content-Type: text/plain; charset=utf-8\n"
-"Content-Transfer-Encoding: 8bit\n"
-"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
-
-#: similarterms.module:22
-msgid "Displays a block with similar content based on taxonomy terms."
-msgstr "Zeigt einen Block von anderen ähnlichen Inhalten nach Begriffen an."
-
-#: similarterms.module:42
-msgid "Similar entries from ANY vocabulary."
-msgstr "Ähnliche Einträge aus IRGENDEINER Kategorie."
-
-#: similarterms.module:46
-msgid "Similar entries from the @vocab vocabulary."
-msgstr "Ähnliche Einträge aus der Kategorie @vocab."
-
-#: similarterms.module:54
-msgid "Item count"
-msgstr "Anzahl der Einträge"
-
-#: similarterms.module:57
-msgid "The maximum number of similar items to display"
-msgstr "Maximale Anzahl angezeigter ähnlicher Einträge"
-
-#: similarterms.module:60
-msgid "same as current"
-msgstr ""
-
-#: similarterms.module:67
-msgid "Content type limit"
-msgstr ""
-
-#: similarterms.module:70
-msgid "Limit to pages of this or these content type(s)"
-msgstr ""
-
-#: similarterms.module:81;85
-msgid "Similar"
-msgstr "Ähnlich"
-
-#: similarterms.module:33
-msgid "access similarterms content"
-msgstr ""
-
-#: similarterms.module:33
-msgid "administer similarterms content"
-msgstr ""
-
-#: similarterms.module:0
-msgid "similarterms"
-msgstr "similarterms"
-
-#: similarterms.info:0
-msgid "Similar By Terms"
-msgstr "Ähnliche Einträge zu Begriffen"
-
-#: similarterms.info:0
-msgid "Display a block of other content that is similar by keywords (taxonomy terms)."
-msgstr "Zeigt einen Block von anderen ähnlichen Inhalten nach Begriffen an."
-
diff --git a/translations/hu.po b/translations/hu.po
deleted file mode 100644
index 050f250..0000000
--- a/translations/hu.po
+++ /dev/null
@@ -1,120 +0,0 @@
-# Hungarian translation of Similar By Terms (6.x-1.18)
-# Copyright (c) 2010 by the Hungarian translation team
-#
-msgid ""
-msgstr ""
-"Project-Id-Version: Similar By Terms (6.x-1.18)\n"
-"POT-Creation-Date: 2010-07-17 22:02+0000\n"
-"PO-Revision-Date: 2010-07-17 22:01+0000\n"
-"Language-Team: Hungarian\n"
-"MIME-Version: 1.0\n"
-"Content-Type: text/plain; charset=utf-8\n"
-"Content-Transfer-Encoding: 8bit\n"
-"Plural-Forms: nplurals=2; plural=(n!=1);\n"
-
-msgid "<none>"
-msgstr "< nincs >"
-msgid "Never"
-msgstr "Soha"
-msgid "Similar entries from ANY vocabulary."
-msgstr "Hasonló bejegyzések BÁRMELY szótárból."
-msgid "Similar entries from the @vocab vocabulary."
-msgstr "Hasonló bejegyzések @vocab szótárból."
-msgid "Item count"
-msgstr "Elemszám"
-msgid "The maximum number of similar items to display"
-msgstr "A hasonló kifejezések megjelenítésének küszöbértéke"
-msgid "Similar"
-msgstr "Hasonló"
-msgid "Similar By Terms"
-msgstr "Hasonló kifejezések"
-msgid ""
-"Display a block of other content that is similar by keywords (taxonomy "
-"terms)."
-msgstr ""
-"Megjelenít egy blokkot hasonló tartalmakkal kulcsszavak alapján "
-"(taxonómia kifejezések)."
-msgid "Display Options"
-msgstr "Megjelenítési lehetőségek"
-msgid "Primary Key: Unique cache ID."
-msgstr "Elsődleges kulcs: egyedi gyorstár azonosító."
-msgid "A collection of data to cache."
-msgstr "A gyorstárazandó adatok gyűjteménye."
-msgid ""
-"A Unix timestamp indicating when the cache entry should expire, or 0 "
-"for never."
-msgstr ""
-"Unix időbélyeg, mely a bejegyzés lejárati idejét jelöli, vagy 0, "
-"ha nem jár le."
-msgid "A Unix timestamp indicating when the cache entry was created."
-msgstr "Unix időbélyeg, mely a bejegyzés létrehozását jelöli."
-msgid "Any custom HTTP headers to be added to cached data."
-msgstr "Egyedi HTTP fejlécek, amelyeket a gyorstárazott adathoz kell adni."
-msgid "A flag to indicate whether content is serialized (1) or not (0)."
-msgstr "1, ha a tartalom sorosított, 0 egyébként."
-msgid "Display titles only"
-msgstr "Csak a cím megjelenítése"
-msgid "Show current node as active in the list"
-msgstr "Az aktuális tartalom aktívnak jelölése a listában"
-msgid "same as current"
-msgstr "mint a jelenlegi"
-msgid "Content type limit"
-msgstr "Tartalomtípus határ"
-msgid "Limit to pages of this or these content type(s)"
-msgstr "Erre, vagy ezekre a tartalomtípusokra korlátozza a lapokat"
-msgid "Terms to be ignored"
-msgstr "Figyelmen kívül hagyott kifejezések"
-msgid ""
-"Ignore selected terms here from being used to search for similar "
-"entries"
-msgstr ""
-"Az itt kiválasztott kifejezéseket nem veszi figyelembe, amikor "
-"hasonló tartalmakat keres"
-msgid ""
-"Basic Settings for similar term most settings are in the blocks "
-"config."
-msgstr ""
-"A hasonló kifejezések alapvető beállításai, a legtöbb a blokkok "
-"beállításánál van."
-msgid "Vocabularies types to list"
-msgstr "Szótártípusok listázása"
-msgid "Default sort order"
-msgstr "Alapértelmezés szerinti rendezés"
-msgid "Prefer more unique order"
-msgstr "Több egyedi rendezés támogatása"
-msgid "Unique Order Options"
-msgstr "Egyedi sorrend lehetőségek"
-msgid "Cache Options"
-msgstr "Gyorstár lehetőségek"
-msgid "Clear Cache"
-msgstr "Gyorstár törlése"
-msgid "Clear Similarterms Block Cache"
-msgstr "Hasonló kifejezések blokk gyorstárának törlése"
-msgid "Similarterms Block Cache is now cleared"
-msgstr "A hasonló kifejezések blokk gyorstára törölve lett"
-msgid "Display multi-select and tags types only"
-msgstr "Csak a többszörös választású és a címkés típusok"
-msgid "Display all vocabularies types"
-msgstr "Minden szótártípus megjelenítése"
-msgid "Display titles and teaser"
-msgstr "Cím és bevezető megjelenítése"
-msgid "Displays a block with similar content based on taxonomy terms."
-msgstr ""
-"Megjelenít egy blokkot hasonló tartalmakkal a taxonómia "
-"kifejezések alapján."
-msgid "access similarterms content"
-msgstr "hasonló kifejezések tartalmának elérése"
-msgid "administer similarterms content"
-msgstr "hasonló kifejezések tartalmának adminisztrációja"
-msgid "similarterms module installed."
-msgstr "A hasonló kifejezések modul telepítése megtörtént."
-msgid ""
-"similarterms table creation failed. Please \"uninstall\" the module "
-"and retry."
-msgstr ""
-"A hasonló kifejezések táblája nem jött létre. El kell "
-"távolítani a modult, és ismét meg kell próbálni a telepítést."
-msgid "Cache table for the Similar by Terms Module."
-msgstr "A hasonló kifejezések modul gyorstárának táblája."
-msgid "similarterms module uninstalled."
-msgstr "A hasonló kifejezések modul el lett távolítva."
diff --git a/translations/similarterms.pot b/translations/similarterms.pot
deleted file mode 100644
index 44b5379..0000000
--- a/translations/similarterms.pot
+++ /dev/null
@@ -1,76 +0,0 @@
-#
-# LANGUAGE translation of Drupal (general)
-# Copyright YEAR NAME <EMAIL@ADDRESS>
-# Generated from files:
-#  similarterms.module,v 1.7 2008/06/20 00:52:48 rmiddle
-#  similarterms.info,v 1.2 2008/06/19 16:43:46 rmiddle
-#
-#, fuzzy
-msgid ""
-msgstr ""
-"Project-Id-Version: PROJECT VERSION\n"
-"POT-Creation-Date: 2008-06-29 20:58-0400\n"
-"PO-Revision-Date: YYYY-mm-DD HH:MM+ZZZZ\n"
-"Last-Translator: NAME <EMAIL@ADDRESS>\n"
-"Language-Team: LANGUAGE <EMAIL@ADDRESS>\n"
-"MIME-Version: 1.0\n"
-"Content-Type: text/plain; charset=utf-8\n"
-"Content-Transfer-Encoding: 8bit\n"
-"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
-
-#: similarterms.module:22 similarterms/similarterms.module:21
-msgid "Displays a block with similar content based on taxonomy terms."
-msgstr ""
-
-#: similarterms.module:42 similarterms/similarterms.module:41
-msgid "Similar entries from ANY vocabulary."
-msgstr ""
-
-#: similarterms.module:46 similarterms/similarterms.module:45
-msgid "Similar entries from the @vocab vocabulary."
-msgstr ""
-
-#: similarterms.module:54 similarterms/similarterms.module:53
-msgid "Item count"
-msgstr ""
-
-#: similarterms.module:57 similarterms/similarterms.module:56
-msgid "The maximum number of similar items to display"
-msgstr ""
-
-#: similarterms.module:60 similarterms/similarterms.module:59
-msgid "same as current"
-msgstr ""
-
-#: similarterms.module:67 similarterms/similarterms.module:66
-msgid "Content type limit"
-msgstr ""
-
-#: similarterms.module:70 similarterms/similarterms.module:69
-msgid "Limit to pages of this or these content type(s)"
-msgstr ""
-
-#: similarterms.module:81;85 similarterms/similarterms.module:80;84
-msgid "Similar"
-msgstr ""
-
-#: similarterms.module:33 similarterms/similarterms.module:32
-msgid "access similarterms content"
-msgstr ""
-
-#: similarterms.module:33 similarterms/similarterms.module:32
-msgid "administer similarterms content"
-msgstr ""
-
-#: similarterms.module:0 similarterms/similarterms.module:0
-msgid "similarterms"
-msgstr ""
-
-#: similarterms.info:0 similarterms/similarterms.info:0
-msgid "Similar By Terms"
-msgstr ""
-
-#: similarterms.info:0 similarterms/similarterms.info:0
-msgid "Display a block of other content that is similar by keywords (taxonomy terms)."
-msgstr ""
-
diff --git a/views/similarterms.views.inc b/views/similarterms.views.inc
new file mode 100644
index 0000000..dcb72fb
--- /dev/null
+++ b/views/similarterms.views.inc
@@ -0,0 +1,33 @@
+<?php
+
+/**
+ * Implements hook_views_data()
+ **/
+function similarterms_views_data_alter(&$data) {
+  $data['similarterms']['similarterms']['moved to'] = array('node', 'similarterms');
+  $data['node']['similarterms'] = array(
+    'title' => t('Similarity'),
+    'group' => t('Similar By Terms'),
+    'help' => t('Percentage/count of terms which node has in common with node given as argument.'),
+    'field' => array(
+      'handler' => 'similarterms_handler_field_similar',
+      'click sortable' => TRUE,
+    ),
+    'sort' => array(
+      'handler' => 'similarterms_handler_sort_similar',
+    ),
+  );
+  $data['similarterms']['nid']['moved to'] = array('node', 'similar_nid');
+  $data['node']['similar_nid'] = array(
+    'title' => t('Nid'),
+    'group' => t('Similar By Terms'),
+    'help' => t('ID of content item(s). Passes term ids to Similar By Terms.'), // The help that appears on the UI,
+    'argument' => array(
+      'handler' => 'similarterms_handler_argument_node_nid',
+      // 'parent' => 'views_handler_argument_numeric', // make sure parent is included
+      'name field' => 'title', // the field to display in the summary.
+      'numeric' => TRUE,
+      'validate type' => 'nid',
+    ),
+  );
+}
diff --git a/views/similarterms.views_default.inc b/views/similarterms.views_default.inc
new file mode 100644
index 0000000..6dad860
--- /dev/null
+++ b/views/similarterms.views_default.inc
@@ -0,0 +1,179 @@
+<?php
+
+// TODO: Upgrade the default view(s) to D7 Views 3.
+
+// /**
+//  * Implements hook_views_default_views().
+//  */
+// function similarterms_views_default_views() {
+//   /*
+//    * View 'similarterms'
+//    */
+//   $view = new view;
+//   $view->name = 'similarterms';
+//   $view->description = 'Similar By Terms';
+//   $view->tag = 'similarterms';
+//   $view->view_php = '';
+//   $view->base_table = 'node';
+//   $view->is_cacheable = FALSE;
+//   $view->api_version = 2;
+//   $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
+//   $handler = $view->new_display('default', 'Defaults', 'default');
+//   $handler->override_option('fields', array(
+//     'title' => array(
+//       'label' => '',
+//       'alter' => array(
+//         'alter_text' => 0,
+//         'text' => '',
+//         'make_link' => 0,
+//         'path' => '',
+//         'link_class' => '',
+//         'alt' => '',
+//         'prefix' => '',
+//         'suffix' => '',
+//         'target' => '',
+//         'help' => '',
+//         'trim' => 0,
+//         'max_length' => '',
+//         'word_boundary' => 1,
+//         'ellipsis' => 1,
+//         'html' => 0,
+//         'strip_tags' => 0,
+//       ),
+//       'empty' => '',
+//       'hide_empty' => 0,
+//       'empty_zero' => 0,
+//       'link_to_node' => 1,
+//       'exclude' => 0,
+//       'id' => 'title',
+//       'table' => 'node',
+//       'field' => 'title',
+//       'relationship' => 'none',
+//       'override' => array(
+//         'button' => 'Override',
+//       ),
+//     ),
+//   ));
+//   $handler->override_option('sorts', array(
+//     'similarterms' => array(
+//       'order' => 'DESC',
+//       'id' => 'similarterms',
+//       'table' => 'similarterms',
+//       'field' => 'similarterms',
+//       'relationship' => 'none',
+//       'override' => array(
+//         'button' => 'Override',
+//       ),
+//     ),
+//   ));
+//   $handler->override_option('arguments', array(
+//     'nid' => array(
+//       'default_action' => 'default',
+//       'style_plugin' => 'default_summary',
+//       'style_options' => array(),
+//       'wildcard' => 'all',
+//       'wildcard_substitution' => 'All',
+//       'title' => '',
+//       'breadcrumb' => '',
+//       'default_argument_type' => 'node',
+//       'default_argument' => '',
+//       'validate_type' => 'node',
+//       'validate_fail' => 'not found',
+//       'break_phrase' => 0,
+//       'not' => 0,
+//       'id' => 'nid',
+//       'table' => 'similarterms',
+//       'field' => 'nid',
+//       'validate_user_argument_type' => 'uid',
+//       'validate_user_roles' => array(
+//         '2' => 0,
+//         '4' => 0,
+//         '3' => 0,
+//       ),
+//       'override' => array(
+//         'button' => 'Override',
+//       ),
+//       'relationship' => 'none',
+//       'default_options_div_prefix' => '',
+//       'default_argument_fixed' => '',
+//       'default_argument_user' => 0,
+//       'default_argument_php' => '',
+//       'validate_argument_node_type' => array(
+//         'blog' => 0,
+//         'product' => 0,
+//         'presenter' => 0,
+//         'playlist_video' => 0,
+//         'standalone_video' => 0,
+//         'page' => 0,
+//       ),
+//       'validate_argument_node_access' => 0,
+//       'validate_argument_nid_type' => 'nid',
+//       'validate_argument_vocabulary' => array(
+//         '1' => 0,
+//         '3' => 0,
+//         '2' => 0,
+//         '4' => 0,
+//       ),
+//       'validate_argument_type' => 'tid',
+//       'validate_argument_transform' => 0,
+//       'validate_user_restrict_roles' => 0,
+//       'validate_argument_node_flag_name' => '*relationship*',
+//       'validate_argument_node_flag_test' => 'flaggable',
+//       'validate_argument_node_flag_id_type' => 'id',
+//       'validate_argument_user_flag_name' => '*relationship*',
+//       'validate_argument_user_flag_test' => 'flaggable',
+//       'validate_argument_user_flag_id_type' => 'id',
+//       'validate_argument_php' => '',
+//     ),
+//   ));
+//   $handler->override_option('filters', array(
+//     'moderate' => array(
+//       'operator' => '=',
+//       'value' => '0',
+//       'group' => '0',
+//       'exposed' => FALSE,
+//       'expose' => array(
+//         'operator' => FALSE,
+//         'label' => '',
+//       ),
+//       'id' => 'moderate',
+//       'table' => 'node',
+//       'field' => 'moderate',
+//       'override' => array(
+//         'button' => 'Override',
+//       ),
+//       'relationship' => 'none',
+//     ),
+//     'status' => array(
+//       'operator' => '=',
+//       'value' => '1',
+//       'group' => '0',
+//       'exposed' => FALSE,
+//       'expose' => array(
+//         'operator' => FALSE,
+//         'label' => '',
+//       ),
+//       'id' => 'status',
+//       'table' => 'node',
+//       'field' => 'status',
+//       'override' => array(
+//         'button' => 'Override',
+//       ),
+//       'relationship' => 'none',
+//     ),
+//   ));
+//   $handler->override_option('access', array(
+//     'type' => 'none',
+//   ));
+//   $handler->override_option('cache', array(
+//     'type' => 'none',
+//   ));
+//   $handler->override_option('title', 'Similar By Terms');
+//   $handler->override_option('items_per_page', 7);
+//   $handler = $view->new_display('block', 'Block', 'block_1');
+//   $handler->override_option('block_description', '');
+//   $handler->override_option('block_caching', '4');
+//   $views[$view->name] = $view;
+// 
+//   return $views;
+// }
diff --git a/views/similarterms_handler_argument_node_nid.inc b/views/similarterms_handler_argument_node_nid.inc
new file mode 100644
index 0000000..2c1da8f
--- /dev/null
+++ b/views/similarterms_handler_argument_node_nid.inc
@@ -0,0 +1,131 @@
+<?php
+/**
+ * Argument handler to accept a node id.
+ * based on node_handler_argument_node_nid except that it doesn't
+ * add a where clause to the query.
+ *
+ * @ingroup views_argument_handlers
+ */
+class similarterms_handler_argument_node_nid extends views_handler_argument_numeric {
+  /**
+   * Override the behavior of title(). Get the title of the node.
+   */
+  function title_query() {
+    $titles = array();
+
+    $select = db_select('node', 'n');
+    $select->addField('n', 'title');
+    $select->condition('n.nid', $this->value, 'IN');
+    $select->addTag('node_access');
+    $result = $select->execute();
+
+    foreach ($result as $term) {
+      $titles[] = check_plain($term->title);
+    }
+
+    return $titles;
+  }
+
+  function option_definition() {
+    $options = parent::option_definition();
+
+    $options['vocabularies'] = array('default' => array());
+    $options['include_args'] = array('default' => FALSE);
+
+    return $options;
+  }
+
+  function options_form(&$form, &$form_state) {
+    parent::options_form($form, $form_state);
+
+    unset($form['not']);
+
+    $vocabularies = array();
+    $result = db_query('SELECT vid, name FROM {taxonomy_vocabulary} ORDER BY weight');
+    foreach ($result as $vocabulary) {
+      $vocabularies[$vocabulary->vid] = $vocabulary->name;
+    }
+
+    $form['similarterms'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Similarity by Terms'),
+      '#collapsible' => FALSE,
+    );
+    $form['similarterms']['vocabularies'] = array(
+      '#type' => 'checkboxes',
+      '#title' => t('Limit similarity to terms within these vocabularies'),
+      '#description' => t('Choosing any vocabularies here will limit the terms used to calculate similarity. It is usually best NOT to limit the terms, but in some cases this is necessary. Leave all checkboxes unselected to not limit terms.'),
+      '#options' => $vocabularies,
+      '#default_value' => empty($this->options['vocabularies']) ? array() : $this->options['vocabularies'],
+    );
+
+    $form['similarterms']['include_args'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Include argument node(s) in results'),
+      '#description' => t('If selected, the node(s) passed as the argument will be included in the view results.'),
+      '#default_value' => !empty($this->options['include_args']),
+    );
+
+  }
+
+  function validate_arg($arg) {
+    // first run the inherited arg validation
+    if (!parent::validate_arg($arg)) {
+      return FALSE;
+    }
+
+    // hmmm... @todo: wildcard validation?
+    // see views_handler_argument.inc for possible code
+
+    if (!empty($this->options['break_phrase'])) {
+      views_break_phrase($this->argument, $this);
+    }
+    else {
+      $this->value = array($this->argument);
+    }
+
+    // $vocabulary_vids is array of vocabulary ids (a.k.a. vids, confusing right?)
+    $vocabulary_vids = empty($this->options['vocabularies']) ? array() : $this->options['vocabularies'];
+    foreach ($vocabulary_vids as $key => $val) {
+      if ($val == 0) {
+        unset($vocabulary_vids[$key]);
+      }
+    }
+
+    $select = db_select('taxonomy_index', 'ti');
+    $select->addField('ti', 'tid');
+
+    if (count($vocabulary_vids)) {
+      $select->join('taxonomy_term_data', 'td', 'ti.tid = td.tid');
+      $select->condition('td.vid', $vocabulary_vids, 'IN');
+    }
+    $select->condition('ti.nid', $this->value, 'IN');
+    $result = $select->execute();
+
+    $this->tids = array();
+    foreach ($result as $row) {
+      $this->tids[$row->tid] = $row->tid;
+    }
+    $this->view->tids = $this->tids;
+
+    if (count($this->tids) == 0) {
+      // there are no terms ... we need to cancel the query and bail out
+      return FALSE;
+    }
+
+    return TRUE;
+  }
+
+  function query($group_by = FALSE) {
+    $this->ensure_my_table();
+
+    $this->query->add_table('taxonomy_index', NULL, NULL, 'similarterms_taxonomy_index');
+    $this->query->add_where(0, "similarterms_taxonomy_index.tid", $this->tids, 'IN');
+
+    // exclude the current node(s)
+    if (empty($this->options['include_args'])) {
+      $this->query->add_where(0, "node.nid", $this->value, 'NOT IN');
+    }
+  }
+
+}
diff --git a/views/similarterms_handler_field_similar.inc b/views/similarterms_handler_field_similar.inc
new file mode 100644
index 0000000..bfc5d4e
--- /dev/null
+++ b/views/similarterms_handler_field_similar.inc
@@ -0,0 +1,57 @@
+<?php
+
+/**
+ * Shows the similarity of the node.
+ *
+ * @ingroup views_field_handlers
+ */
+class similarterms_handler_field_similar extends views_handler_field {
+  function option_definition() {
+    $options = parent::option_definition();
+    $options['count_type'] = array('default' => 1);
+    $options['percent_suffix'] = array('default' => 1);
+    return $options;
+  }
+
+  function options_form(&$form, &$form_state) {
+    parent::options_form($form, $form_state);
+
+    $form['count_type'] = array(
+      '#type' => 'radios',
+      '#title' => t('Display type'),
+      '#default_value' => $this->options['count_type'],
+      '#options' => array(
+        0 => t('Show count of common terms'),
+        1 => t('Show as percentage'),
+      ),
+    );
+
+    $form['percent_suffix'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Append % when showing percentage'),
+      '#default_value' => !empty($this->options['percent_suffix']),
+    );
+  }
+
+  function query() {
+    // we MIGHT want to ensure that the COUNT data is getting added here.
+    $params = array(
+      'function' => 'count',
+    );
+    $this->field_alias = $this->query->add_field('node', 'nid', NULL, $params);
+  }
+
+  function render($values) {
+    if ($this->options['count_type'] == 0) {
+      return $values->{$this->field_alias};
+    }
+    elseif ($this->view->tids) {
+      $output = round($values->{$this->field_alias}/count($this->view->tids) * 100);
+      if (!empty($this->options['percent_suffix'])) {
+        $output .= '%';
+      }
+      return $output;
+    }
+
+  }
+}
diff --git a/views/similarterms_handler_sort_similar.inc b/views/similarterms_handler_sort_similar.inc
new file mode 100644
index 0000000..a060897
--- /dev/null
+++ b/views/similarterms_handler_sort_similar.inc
@@ -0,0 +1,20 @@
+<?php
+/**
+ * Handler which sorts the by the similarity.
+ *
+ * @ingroups views_sort_handlers
+ */
+class similarterms_handler_sort_similar extends views_handler_sort {
+
+  function option_definition() {
+    $options = parent::option_definition();
+    $options['order'] = array('default' => 'DESC');
+    return $options;
+  }
+
+  function query() {
+    $this->ensure_my_table();
+    $this->query->add_orderby($this->table_alias, 'nid', $this->options['order'], NULL, array('function' => 'count'));
+  }
+
+}
