[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/xmlsitemap/ -> xmlsitemap.inc (source)

   1  <?php
   2  // $Id: xmlsitemap.inc,v 1.1.2.55 2010/04/29 16:22:09 davereid Exp $
   3  
   4  /**
   5   * @file
   6   * Miscellaneous functions for the xmlsitemap module.
   7   *
   8   * @ingroup xmlsitemap
   9   */
  10  
  11  /**
  12   * Condition builder for queries.
  13   */
  14  function _xmlsitemap_build_conditions(array &$conditions = array(), array &$args = array(), $operator = '=', $update = FALSE) {
  15    $operators = array(
  16      'null' => array('=' => 'IS', '<>' => 'IS NOT'),
  17      'in' => array('=' => 'IN', '<>' => 'NOT IN'),
  18    );
  19  
  20    foreach ($conditions as $field => $value) {
  21      if (is_int($field)) {
  22        continue;
  23      }
  24      elseif ($value === NULL) {
  25        if ($update) {
  26          $conditions[$field] = "$field = NULL";
  27        }
  28        else {
  29          $conditions[$field] = "$field {$operators['null'][$operator]} NULL";
  30        }
  31      }
  32      elseif (is_array($value)) {
  33        if ($update) {
  34          trigger_error(strtr('Update not supported for field %field in @function.', array('%field' => theme('placeholder', $field), '@function' => __FUNCTION__)));
  35          unset($conditions[$field]);
  36        }
  37        else {
  38          $type = _xmlsitemap_get_field_type('xmlsitemap', $field);
  39          $conditions[$field] = "$field {$operators['in'][$operator]} (" . db_placeholders($value, $type) . ")";
  40          $args = array_merge($args, $value);
  41        }
  42      }
  43      else {
  44        $placeholder = db_type_placeholder(_xmlsitemap_get_field_type('xmlsitemap', $field));
  45        $conditions[$field] = "$field $operator $placeholder";
  46        $args[] = $value;
  47      }
  48    }
  49  
  50    return $args;
  51  }
  52  
  53  /**
  54   * Special implementation of drupal_write_record() to allow NULL values.
  55   *
  56   * @todo Remove when http://drupal.org/node/227677 is fixed.
  57   */
  58  function xmlsitemap_write_record($table, &$object, $update = array()) {
  59    // Standardize $update to an array.
  60    if (is_string($update)) {
  61      $update = array($update);
  62    }
  63  
  64    $schema = drupal_get_schema($table);
  65    if (empty($schema)) {
  66      return FALSE;
  67    }
  68  
  69    // Convert to an object if needed.
  70    if (is_array($object)) {
  71      $object = (object) $object;
  72      $array = TRUE;
  73    }
  74    else {
  75      $array = FALSE;
  76    }
  77  
  78    $fields = $defs = $values = $serials = $placeholders = array();
  79    $object_fields = get_object_vars($object);
  80  
  81    // Go through our schema, build SQL, and when inserting, fill in defaults for
  82    // fields that are not set.
  83    foreach ($schema['fields'] as $field => $info) {
  84      // Special case -- skip serial types if we are updating.
  85      if ($info['type'] == 'serial') {
  86        if (empty($update)) {
  87          // Track serial fields so we can helpfully populate them after the query.
  88          $serials[] = $field;
  89        }
  90        continue;
  91      }
  92  
  93      // For inserts, populate defaults from Schema if not already provided
  94      if (!isset($object->$field) && !count($update) && isset($info['default']) && !array_key_exists($field, $object_fields)) {
  95        $object->$field = $info['default'];
  96      }
  97  
  98      // Build arrays for the fields, placeholders, and values in our query.
  99      if (isset($object->$field) || (array_key_exists($field, $object_fields) && empty($info['not null']))) {
 100        $fields[] = $field;
 101        if (isset($object->$field)) {
 102          $placeholders[] = db_type_placeholder($info['type']);
 103          $values[] = empty($info['serialize']) ? $object->$field : serialize($object->$field);
 104        }
 105        else {
 106          $placeholders[] = '%s';
 107          $values[] = 'NULL';
 108        }
 109      }
 110    }
 111  
 112    // Build the SQL.
 113    $query = '';
 114    if (!count($update)) {
 115      $query = "INSERT INTO {". $table ."} (". implode(', ', $fields) .') VALUES ('. implode(', ', $placeholders) .')';
 116      $return = SAVED_NEW;
 117    }
 118    else {
 119      $query = '';
 120      foreach ($fields as $id => $field) {
 121        if ($query) {
 122          $query .= ', ';
 123        }
 124        $query .= $field .' = '. $placeholders[$id];
 125      }
 126  
 127      foreach ($update as $key) {
 128        $conditions[] = "$key = ". db_type_placeholder($schema['fields'][$key]['type']);
 129        $values[] = $object->$key;
 130      }
 131  
 132      $query = "UPDATE {". $table ."} SET $query WHERE ". implode(' AND ', $conditions);
 133      $return = SAVED_UPDATED;
 134    }
 135  
 136    // Execute the SQL.
 137    if (db_query($query, $values)) {
 138      if ($serials) {
 139        // Get last insert ids and fill them in.
 140        foreach ($serials as $field) {
 141          $object->$field = db_last_insert_id($table, $field);
 142        }
 143      }
 144    }
 145    else {
 146      $return = FALSE;
 147    }
 148  
 149    // If we began with an array, convert back so we don't surprise the caller.
 150    if ($array) {
 151      $object = (array) $object;
 152    }
 153  
 154    return $return;
 155  }
 156  
 157  /**
 158   * Fetch a short blurb string about module maintainership and sponsors.
 159   *
 160   * This message will be FALSE in 'official' releases.
 161   */
 162  function _xmlsitemap_get_blurb($check_version = TRUE) {
 163    static $blurb;
 164  
 165    if (!isset($blurb)) {
 166      $blurb = FALSE;
 167      if (!$check_version || (($version = _xmlsitemap_get_version()) && preg_match('/dev|unstable|alpha|beta|HEAD/i', $version))) {
 168        $sponsors = array(
 169          l('Symantec', 'http://www.symantec.com/'),
 170          l('WebWise Solutions', 'http://www.webwiseone.com/'),
 171          l('Volacci', 'http://www.volacci.com/'),
 172          l('lanetro', 'http://www.lanetro.com/'),
 173          l('Coupons Dealuxe', 'http://couponsdealuxe.com/'),
 174        );
 175        // Don't extract the following string for translation.
 176        $blurb = '<div class="description"><p>Thank you for helping test the XML sitemap module rewrite. Please consider helping offset developer free time by <a href="http://davereid.chipin.com/">donating</a> or if your company is interested in sponsoring the rewrite or a specific feature, please <a href="http://davereid.net/contact">contact the developer</a>. Thank you to the following current sponsors: ' . implode(', ', $sponsors) . ', and all the indivduals that have donated. This message will not be seen in the stable versions.</p></div>';
 177        //http://drupalmodules.com/module/xml-sitemap
 178      }
 179    }
 180  
 181    return $blurb;
 182  }
 183  
 184  function _xmlsitemap_get_version() {
 185    static $version;
 186    if (!isset($version)) {
 187      $modules = module_rebuild_cache();
 188      $version = $modules['xmlsitemap']->info['version'];
 189    }
 190    return $version;
 191  }
 192  
 193  /**
 194   * Check the status of all hook_requirements() from any xmlsitemap modules.
 195   */
 196  function xmlsitemap_check_status() {
 197    $messages = &xmlsitemap_static(__FUNCTION__);
 198  
 199    if (!isset($messages)) {
 200      // Cache the list of modules that are checked.
 201      if ($cache = cache_get('xmlsitemap:registry:requirements')) {
 202        $modules = $cache->data;
 203      }
 204      else {
 205        $modules = array();
 206        module_load_all_includes('install');
 207        foreach (module_implements('requirements') as $module) {
 208          if (strpos($module, 'xmlsitemap') !== FALSE) {
 209            $modules[] = $module;
 210          }
 211        }
 212        cache_set('xmlsitemap:registry:requirements', $modules);
 213      }
 214  
 215      $messages = array();
 216      foreach ($modules as $module) {
 217        module_load_install($module);
 218        $requirements = module_invoke($module, 'requirements', 'runtime');
 219        foreach ($requirements as $requirement) {
 220          if (isset($requirement['severity']) && max(REQUIREMENT_OK, $requirement['severity'])) {
 221            $messages[] = $requirement['description'];
 222          }
 223        }
 224      }
 225  
 226      if ($messages) {
 227        $message = t('One or more problems were detected with your XML sitemap configuration: !messages', array('!messages' => theme('item_list', $messages)));
 228        if (user_access('access site reports')) {
 229          $message .= t('Check the <a href="@status-report">status report</a> for more information.', array('@status-report' => url('admin/reports/status')));
 230        }
 231        drupal_set_message($message, 'warning', FALSE);
 232      }
 233    }
 234  
 235    return !empty($messages);
 236  }


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7