[development] Making a whole site location aware - a design question

Agaric Design pwgdarchive at gmail.com
Tue Aug 29 17:47:58 UTC 2006

I'm very much looking forward to this module being contributed back to
Drupal.  I hope someone can help Scott out with the very last part--
disabling in specific cases the hook_db_rewrite_sql logic that filters
by location.

- ben melançon

On 8/25/06, Scott McLewin <drupal at mclewin.com> wrote:
> Dave Cohen wrote:
> > Consider...
> >
> > Write a module which stores this data however you see fit.  (Could be a table
> > you create that joins the users table on uid).
> >
> > Then, use hook_db_rewrite_sql to filter out any nodes which have location
> > information which is not within the users radius.  This way, your work
> > applies to any node with location information, not just events.  And the
> > event (or any other) module does not have to change at all.
> >
> > If you take this approach, your module is essentially a location-based access
> > control module.  Read up on how node.module uses hook_db_rewrite_sql to
> > filter nodes based on the node_access table and emulate that.
> >
> >
> >
> The use of hook_db_rewrite_sql did what I wanted for making displays
> only return nodes that are near the visitor's location.  I use the term
> visitor here carefully to distinguish from $user - even anonymous users
> are given a lat/lon location based on their IP, a configured site
> default or self-selected.  Every visitor has a valid lat/lon.  Checking
> for anonymous users to control the hook_db_rewrite_sql behavior is not
> an option for me in this circumstance.
> There are a handful of side effects to using db_rewrite_sql that I am
> working through.  Some are rather subtle (at least to me).  They include
> the following cases:
> While I want displays such as event calendars and taxonomy lists to
> restrict display on location aware node type to nodes which are
> geographically close to the user, I do want search to search the entire
> site.  Without exception logic, search results are restricted only to
> those nodes that are within the geographic search radius of the current
> visitor.
> For search to work, the indexer also needs to be able to see all nodes.
> Even hook_cron() triggered page loads end up with a location (the site's
> configured default). Thus the indexer never sees nodes that are outside
> of the default search radius from the site's default location.
> For a module that I don't intend to contribute back I'd twiddle the
> order of my module in the system table so that it loaded first, then use
> the module's hook_cron() and hook_search() functions to disable my
> hook_db_rewrite_sql() for that page load (I've got a global to control
> that).  I intent to contribute the location based filter module.
> What I am looking for are early entry points in the call path where I
> can disable the location filter.
> For example, to handle data entered into the search form, I tried
> hook_form_alter to add a hidden element with a validation function that
> just disabled the location filter for that page load.  That didn't do
> the trick as it appears that the page reloads after my validation
> function is called (and the page reload resets the global that disables
> location filtering for the page load).
> Are there more general purpose entry points that will allow me to
> disable the hook_db_rewrite_sql logic that filters by location in cases
> such as cron jobs and search form entry (I'm certain that there will be
> others), or are there status/state information tidbits within Drupal
> that I can peek at to know, for example, that cron is running?
> Scott

More information about the development mailing list