~stefanor/drupal/sr

« back to all changes in this revision

Viewing changes to modules/xmlsitemap/xmlsitemap_node/xmlsitemap_node.module

  • Committer: Stefano Rivera
  • Date: 2009-02-03 13:46:19 UTC
  • Revision ID: stefano@rivera.za.net-20090203134619-qtah2mm7178s3gla
Updated:
* swfobject to 2.0 (jquery_media)
* path_redirect beta1
* xmlsitemap update

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
<?php
2
 
// $Id: xmlsitemap_node.module,v 1.19.2.20 2009/01/01 16:06:27 kiam Exp $
 
2
// $Id: xmlsitemap_node.module,v 1.19.2.29 2009/02/02 20:56:07 kiam Exp $
3
3
 
4
4
/**
5
5
 * @file
25
25
    case 'update':
26
26
    case 'moderate':
27
27
    case 'delete':
28
 
      db_query("UPDATE {xmlsitemap_node} SET previous_comment = last_comment, last_comment = %d WHERE nid = %d", $comment->timestamp, $comment->nid);
 
28
      db_query("UPDATE {xmlsitemap_node} SET previous_comment = last_comment, last_comment = %d WHERE nid = %d",
 
29
        array(
 
30
          $comment->timestamp,
 
31
          $comment->nid,
 
32
        )
 
33
      );
29
34
      if (variable_get('xmlsitemap_node_count_comments', TRUE)) {
30
35
        xmlsitemap_update_sitemap();
31
36
      }
118
123
        FROM {xmlsitemap_node} WHERE nid = %d",
119
124
        $node->nid)
120
125
      );
121
 
      $node->priority_override = $priority !== FALSE ? $priority : -2.0;
122
 
      break;
 
126
      return array('priority_override' => $priority !== FALSE ? $priority : -2.0);
123
127
    case 'insert':
124
 
      db_query("INSERT INTO {xmlsitemap_node} (nid, last_changed, priority_override) VALUES (%d, %d, %s)",
125
 
        $node->nid, $node->changed, $node->priority_override
 
128
      db_query("INSERT INTO {xmlsitemap_node} (nid, changed, priority_override) VALUES (%d, %d, %s)",
 
129
        array(
 
130
          $node->nid,
 
131
          $node->changed,
 
132
          isset($node->priority_override) ? $node->priority_override : -2.0,
 
133
        )
126
134
      );
127
135
      if ($node->status) {
128
136
        xmlsitemap_update_sitemap();
130
138
      break;
131
139
    case 'update':
132
140
      db_query("UPDATE {xmlsitemap_node}
133
 
        SET previously_changed = last_changed, last_changed = %d, priority_override = %s
 
141
        SET previously_changed = changed, changed = %d, priority_override = %s
134
142
        WHERE nid = %d",
135
 
        array($node->changed, $node->priority_override, $node->nid)
 
143
        array(
 
144
          $node->changed,
 
145
          isset($node->priority_override) ? $node->priority_override : -2.0,
 
146
          $node->nid
 
147
        )
136
148
      );
137
149
      if ($node->status || $node->xmlsitemap_node_status) {
138
150
        xmlsitemap_update_sitemap();
155
167
}
156
168
 
157
169
/**
158
 
 * Implementation of hook_xmlsitemap_database_batch_operation().
159
 
 */
160
 
function xmlsitemap_node_xmlsitemap_database_batch_operation() {
161
 
  return array(
162
 
    'file' => 'xmlsitemap_node.batch.inc',
163
 
    'add function' => 'xmlsitemap_node_update_database_01',
164
 
    'update function' => 'xmlsitemap_node_update_database_02',
165
 
  );
166
 
}
167
 
 
168
 
/**
169
170
 * Implementation of hook_xmlsitemap_links().
170
171
 */
171
172
function xmlsitemap_node_xmlsitemap_links() {
174
175
    case 'mysql':
175
176
    case 'mysqli':
176
177
      $coalesce = 'COALESCE';
177
 
      $cast = 'CHAR';
178
178
      break;
179
179
    case 'pgsql':
180
180
      $coalesce = 'FIRST';
181
 
      $cast = 'VARCHAR';
182
181
      break;
183
182
  }
184
183
  if (module_exists('comment')) {
185
 
    $columns = 'n.nid, n.type, n.promote, n.changed, xn.previously_changed, xn.priority_override, s.comment_count, s.last_comment_timestamp, xn.previous_comment';
 
184
    $columns = 'n.nid, n.type, n.promote, xn.changed, xn.previously_changed, xn.priority_override, s.comment_count, s.last_comment_timestamp, xn.previous_comment';
186
185
    $left_join = "LEFT JOIN {node_comment_statistics} s ON n.nid = s.nid";
187
186
  }
188
187
  else {
189
 
    $columns = 'n.nid, n.type, n.promote, n.changed, xn.previously_changed, xn.priority_override';
 
188
    $columns = 'n.nid, n.type, n.promote, xn.changed, xn.previously_changed, xn.priority_override';
190
189
    $left_join = '';
191
190
  }
192
191
  $query = "SELECT $columns, $coalesce(ua.dst) AS alias FROM {node} n
193
192
    LEFT JOIN {xmlsitemap_node} xn ON n.nid = xn.nid
194
193
    $left_join
195
 
    LEFT JOIN {url_alias} ua ON ua.src = CONCAT('node/', CAST(n.nid AS $cast))
 
194
    LEFT JOIN {url_alias} ua ON ua.src = CONCAT('node/', n.nid)
196
195
    WHERE n.status > 0
197
196
      AND n.type NOT IN (". db_placeholders($excludes, 'varchar') .")
198
197
      AND (xn.priority_override = -2 OR xn.priority_override >= 0)
207
206
  $result = db_query(db_rewrite_sql($query), $query_args);
208
207
  while ($node = db_fetch_object($result)) {
209
208
    db_query("INSERT INTO {xmlsitemap} (loc, lastmod, changefreq, priority) VALUES ('%s', %d, %d, %f)",
210
 
      xmlsitemap_url('node/'. $node->nid, $node->alias, NULL, NULL, TRUE),
211
 
      variable_get('xmlsitemap_node_count_comments', TRUE) ? max($node->changed, $node->last_comment_timestamp) : $node->changed,
212
 
      xmlsitemap_node_frequency($node), xmlsitemap_node_priority($node)
 
209
      array(
 
210
        xmlsitemap_url('node/'. $node->nid, $node->alias, NULL, NULL, TRUE),
 
211
        variable_get('xmlsitemap_node_count_comments', TRUE) ? max($node->changed, $node->last_comment_timestamp) : $node->changed,
 
212
        xmlsitemap_node_frequency($node), xmlsitemap_node_priority($node),
 
213
      )
213
214
    );
214
215
  }
215
216
}
245
246
    '#description' => t('If enabled, the frequency of comments on a post will affect its change frequency and last modification date.'),
246
247
  );
247
248
}
 
249
 
 
250
/**
 
251
 * Implementation of hook_xmlsitemap_update_module_tables_batch_operations().
 
252
 */
 
253
function xmlsitemap_node_xmlsitemap_update_module_tables_batch_operations() {
 
254
  return array(
 
255
    '_xmlsitemap_node_module_table_delete_rows',
 
256
    '_xmlsitemap_node_module_table_update_rows',
 
257
    '_xmlsitemap_node_module_table_add_rows',
 
258
  );
 
259
}
 
260
 
248
261
/*****************************************************************************
249
262
 * Menu callbacks / form builders, submit/validate functions.
250
263
 ****************************************************************************/
325
338
function xmlsitemap_node_priority($node) {
326
339
  static $maxcomments;
327
340
  if (!isset($maxcomments)) {
328
 
    $maxcomments = 1;
 
341
    $maxcomments = 0;
329
342
    if (module_exists('comment')) {
330
343
      $maxcomments = db_result(db_query("SELECT MAX(comment_count) FROM {node_comment_statistics}"));
331
344
    }
339
352
  if ($node->promote) {
340
353
    $priority += variable_get('xmlsitemap_node_promote_priority', 0.3);
341
354
  }
342
 
  if ($maxcomments != 1) {
 
355
  if ($maxcomments > 1) {
343
356
    $priority += $node->comment_count / $maxcomments * variable_get('xmlsitemap_node_comment_priority', 0.2);
344
357
  }
345
358
  $priority = min(round($priority, 1), 1);
346
359
  return $priority;
347
360
}
348
361
 
 
362
/*****************************************************************************
 
363
 * Private functions - database batch operations.
 
364
 ****************************************************************************/
 
365
 
 
366
/**
 
367
 * Batch function used to update the module database tables.
 
368
 * @param $context
 
369
 *  The context parameter passed from batch_process().
 
370
 */
 
371
function _xmlsitemap_node_module_table_add_rows(&$context) {
 
372
  if (!isset($context['sandbox']['progress'])) {
 
373
    $context['sandbox']['current_node'] = 0;
 
374
    $context['sandbox']['max'] = (integer) db_result(db_query('SELECT COUNT(n.nid)
 
375
      FROM {node} n
 
376
      LEFT JOIN {xmlsitemap_node} xn ON xn.nid = n.nid
 
377
      WHERE xn.nid IS NULL')
 
378
    );
 
379
    $context['sandbox']['progress'] = 0;
 
380
  }
 
381
  if ($context['sandbox']['max']) {
 
382
    $result = db_query_range('SELECT n.nid, n.created AS previously_changed, n.changed
 
383
      FROM {node} n
 
384
      LEFT JOIN {xmlsitemap_node} xn ON xn.nid = n.nid
 
385
      WHERE xn.nid IS NULL
 
386
        AND n.nid > %d
 
387
      ORDER BY n.nid ASC',
 
388
      $context['sandbox']['current_node'], 0, 1
 
389
    );
 
390
    if ($row = db_fetch_object($result)) {
 
391
      drupal_write_record('xmlsitemap_node', $row);
 
392
      $context['sandbox']['progress']++;
 
393
      $context['sandbox']['current_node'] = $row->nid;
 
394
      $context['results']['added'] = $context['sandbox']['progress'];
 
395
    }
 
396
    if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
 
397
      $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
 
398
    }
 
399
  }
 
400
}
 
401
 
 
402
/**
 
403
 * Batch function used to update the module database tables.
 
404
 * @param $context
 
405
 *  The context parameter passed from batch_process().
 
406
 */
 
407
function _xmlsitemap_node_module_table_delete_rows(&$context) {
 
408
  if (!isset($context['sandbox']['progress'])) {
 
409
    $context['sandbox']['current_node'] = 0;
 
410
    $context['sandbox']['max'] = (integer) db_result(db_query('SELECT COUNT(xn.nid)
 
411
      FROM {xmlsitemap_node} xn
 
412
      LEFT JOIN {node} n ON n.nid = xn.nid
 
413
      WHERE n.nid IS NULL')
 
414
    );
 
415
    $context['sandbox']['progress'] = 0;
 
416
  }
 
417
  if ($context['sandbox']['max']) {
 
418
    $nid = db_result(
 
419
      db_query("SELECT xn.nid
 
420
        FROM {xmlsitemap_node} xn
 
421
        LEFT JOIN {node} n ON n.nid = xn.nid
 
422
        WHERE n.nid IS NULL
 
423
          AND xn.nid > %d",
 
424
        $context['sandbox']['current_node']
 
425
      )
 
426
    );
 
427
    if ($nid === FALSE) {
 
428
      $context['finished'] = 1;
 
429
    }
 
430
    else {
 
431
      db_query('DELETE FROM {xmlsitemap_node} WHERE nid = %d', $nid);
 
432
      $context['sandbox']['progress']++;
 
433
      $context['sandbox']['current_node'] = $nid;
 
434
      $context['results']['deleted'] = $context['sandbox']['progress'];
 
435
      if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
 
436
        $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
 
437
      }
 
438
    }
 
439
  }
 
440
}
 
441
 
 
442
/**
 
443
 * Batch function used to update the module database tables.
 
444
 * @param $context
 
445
 *  The context parameter passed from batch_process().
 
446
 */
 
447
function _xmlsitemap_node_module_table_update_rows(&$context) {
 
448
  if (!isset($context['sandbox']['progress'])) {
 
449
    $context['sandbox']['current_node'] = 0;
 
450
    $context['sandbox']['max'] = (integer) db_result(db_query('SELECT COUNT(n.nid)
 
451
      FROM {node} n
 
452
      INNER JOIN {xmlsitemap_node} xn ON xn.nid = n.nid
 
453
      WHERE n.changed > xn.changed')
 
454
    );
 
455
    $context['sandbox']['progress'] = 0;
 
456
  }
 
457
  if ($context['sandbox']['max']) {
 
458
    $result = db_query_range('SELECT n.nid, xn.changed AS previously_changed, n.changed
 
459
      FROM {node} n
 
460
      INNER JOIN {xmlsitemap_node} xn ON xn.nid = n.nid
 
461
      WHERE n.nid > %d
 
462
        AND n.changed > xn.changed
 
463
      ORDER BY n.nid ASC',
 
464
      $context['sandbox']['current_node'], 0, 1
 
465
    );
 
466
    if ($row = db_fetch_object($result)) {
 
467
      drupal_write_record('xmlsitemap_node', $row, 'nid');
 
468
      $context['sandbox']['progress']++;
 
469
      $context['sandbox']['current_node'] = $row->nid;
 
470
      $context['results']['updated'] = $context['sandbox']['progress'];
 
471
    }
 
472
    if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
 
473
      $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
 
474
    }
 
475
  }
 
476
}
 
477
 
349
478
/**
350
479
 * @} End of "addtogroup xmlsitemap".
351
480
 */