/[drupal]/contributions/modules/google_appliance/DrupalGoogleMini.php
ViewVC logotype

Contents of /contributions/modules/google_appliance/DrupalGoogleMini.php

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Tue Apr 8 17:50:32 2008 UTC (19 months, 2 weeks ago) by jacobsingh
Branch: MAIN
CVS Tags: DRUPAL-5--1-0BETA1, DRUPAL-5--1-0BETA2, HEAD
Branch point for: DRUPAL-5, DRUPAL-6--2
File MIME type: text/x-php
Initial Commit of the google_appliance module!
1 <?php
2 include_once 'GoogleMini.php';
3
4 class DrupalGoogleMini extends GoogleMini {
5
6 var $cache = false;
7
8 function __construct($debug = false, $debug_callback = null) {
9 parent::__construct($debug,$debug_callback);
10 }
11
12 function query($iteratorClass = 'GoogleMiniResultIterator') {
13 if (!db_table_exists('cache_google')) {
14 $this->cache = false;
15 }
16 if (!$this->cache) {
17 return parent::query($iteratorClass);
18 } else {
19 $cached_result_obj = null;
20 $cache_key = md5($this->buildQuery());
21 $_cached_result_xml = cache_get($cache_key,'cache_google');
22 $cached_result_xml = $_cached_result_xml->data;
23 if ($cached_result_xml) {
24 $google_results = GoogleMini::resultFactory($cached_result_xml,$iteratorClass);
25 $google_debug = variable_get('google_debug',0);
26 if ($google_debug >= 2 ){
27 if (function_exists('dpr')) {
28 dpr("got cache for $cache_key");
29 }
30 } elseif ($google_debug == 1) {
31 watchdog('amnestysearch',"got cache for $cache_key at" . $_GET['q']);
32 }
33 } else {
34 $google_results = parent::query($iteratorClass);
35 //10 Min cache by default
36 cache_set($cache_key,'cache_google',$google_results->payload->asXML(),time() + variable_get('google_appliance_cache_timeout',600));
37 $google_debug = variable_get('google_debug',0);
38 if ($google_debug >= 2 ){
39 if (function_exists('dpr')) {
40 dpr("setting cache for $cache_key");
41 }
42 } elseif ($google_debug == 1) {
43 watchdog('amnestysearch',"setting cache for $cache_key at" . $_GET['q']);
44 }
45 }
46 return $google_results;
47 }
48 }
49 }
50 ?>

  ViewVC Help
Powered by ViewVC 1.1.2