~stefanor/drupal/sr

« back to all changes in this revision

Viewing changes to modules/xmlsitemap/xmlsitemap_user/xmlsitemap_user.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_user.module,v 1.12.2.16 2009/01/01 16:06:27 kiam Exp $
 
2
// $Id: xmlsitemap_user.module,v 1.12.2.20 2009/01/31 15:28:06 kiam Exp $
3
3
 
4
4
/**
5
5
 * @file
132
132
    case 'insert':
133
133
      $row = new stdClass();
134
134
      $row->uid = $account->uid;
135
 
      $row->last_changed = time();
 
135
      $row->changed = time();
136
136
      if ($edit['xmlsitemap_user_priority'] != -2.0) {
137
137
        $row->priority_override = $edit['xmlsitemap_user_priority'];
138
138
      }
144
144
      if (($result = db_fetch_object(db_query("SELECT * FROM {xmlsitemap_user} WHERE uid = %d", $account->uid))) === FALSE) {
145
145
        $row = new stdClass();
146
146
        $row->uid = $account->uid;
147
 
        $row->last_changed = time();
 
147
        $row->changed = time();
148
148
      }
149
149
      else {
150
150
        $row = $result;
151
 
        $row->previously_changed = $row->last_changed;
152
 
        $row->last_changed = time();
 
151
        $row->previously_changed = $row->changed;
 
152
        $row->changed = time();
153
153
      }
154
154
      if ($edit['xmlsitemap_user_priority'] != -2.0) {
155
155
        $row->priority_override = $edit['xmlsitemap_user_priority'];
166
166
}
167
167
 
168
168
/**
169
 
 * Implementation of hook_xmlsitemap_database_batch_operation().
170
 
 */
171
 
function xmlsitemap_user_xmlsitemap_database_batch_operation() {
172
 
  return array(
173
 
    'file' => 'xmlsitemap_user.batch.inc',
174
 
    'add function' => 'xmlsitemap_user_update_database',
175
 
  );
176
 
}
177
 
 
178
 
/**
179
169
 * Implementation of hook_xmlsitemap_links().
180
170
 */
181
171
function xmlsitemap_user_xmlsitemap_links() {
184
174
      case 'mysql':
185
175
      case 'mysqli':
186
176
        $coalesce = 'COALESCE';
187
 
        $cast = 'CHAR';
188
177
        break;
189
178
      case 'pgsql':
190
179
        $coalesce = 'FIRST';
191
 
        $cast = 'VARCHAR';
192
180
        break;
193
181
    }
194
182
    $uid = 0;
196
184
    if (count($frontpage) == 2 && $frontpage[0] == 'user' && is_numeric($frontpage[1])) {
197
185
      $uid = $frontpage[1];
198
186
    }
199
 
    $result = db_query("SELECT u.uid, xu.last_changed, xu.previously_changed, xu.priority_override, SUM(xur.priority) as priority, $coalesce(ua.dst) AS alias
 
187
    $result = db_query("SELECT u.uid, xu.changed, xu.previously_changed, xu.priority_override, SUM(xur.priority) as priority, $coalesce(ua.dst) AS alias
200
188
      FROM {xmlsitemap_user} xu
201
189
      INNER JOIN {users} u ON xu.uid = u.uid
202
190
      LEFT JOIN {users_roles} ur ON xu.uid = ur.uid
203
191
      LEFT JOIN {xmlsitemap_user_role} xur ON ur.rid = xur.rid
204
 
      LEFT JOIN {url_alias} ua ON ua.src = CONCAT('user/', CAST(u.uid AS $cast))
 
192
      LEFT JOIN {url_alias} ua ON ua.src = CONCAT('user/', u.uid)
205
193
      WHERE u.status <> 0
206
194
        AND u.uid <> %d
207
 
      GROUP BY u.uid, xu.last_changed, xu.previously_changed, xu.priority_override
 
195
      GROUP BY u.uid, xu.changed, xu.previously_changed, xu.priority_override
208
196
      HAVING MIN(xur.priority) <> -1 OR SUM(xur.priority) IS NULL",
209
197
      $uid
210
198
    );
211
199
    while ($user = db_fetch_object($result)) {
212
 
      $age = time() - $user->last_changed;
213
 
      $interval = empty($user->previously_changed) ? 0 : $user->last_changed - $user->previously_changed;
 
200
      $age = time() - $user->changed;
 
201
      $interval = empty($user->previously_changed) ? 0 : $user->changed - $user->previously_changed;
214
202
      if ($user->priority_override != -2.0) {
215
203
        $priority = $user->priority_override;
216
204
      }
218
206
        $priority = min(isset($user->priority) ? $user->priority : variable_get('xmlsitemap_user_default_priority', 0.5), 1);
219
207
      }
220
208
      db_query("INSERT INTO {xmlsitemap} (loc, lastmod, changefreq, priority) VALUES ('%s', %d, %d, %f)",
221
 
        xmlsitemap_url('user/'. $user->uid, $user->alias, NULL, NULL, TRUE),
222
 
        $user->last_changed, max($age, $interval), $priority);
 
209
        array(
 
210
          xmlsitemap_url('user/'. $user->uid, $user->alias, NULL, NULL, TRUE),
 
211
          $user->changed, max($age, $interval), $priority,
 
212
        )
 
213
      );
223
214
    }
224
215
  }
225
216
}
226
217
 
 
218
/**
 
219
 * Implementation of hook_xmlsitemap_update_module_tables_batch_operations().
 
220
 */
 
221
function xmlsitemap_user_xmlsitemap_update_module_tables_batch_operations() {
 
222
  return array(
 
223
    '_xmlsitemap_user_module_table_delete_rows',
 
224
    '_xmlsitemap_user_module_table_add_rows',
 
225
  );
 
226
}
 
227
 
227
228
/*****************************************************************************
228
229
 * Menu callbacks / form builders, submit/validate functions.
229
230
 ****************************************************************************/
255
256
  }
256
257
}
257
258
 
 
259
/*****************************************************************************
 
260
 * Private functions - database batch operation.
 
261
 ****************************************************************************/
 
262
 
 
263
/**
 
264
 * Batch function used to update the module tables.
 
265
 * @param $context
 
266
 *  The context parameter passed from batch_process().
 
267
 */
 
268
function _xmlsitemap_user_module_table_add_rows(&$context) {
 
269
  if (!isset($context['sandbox']['progress'])) {
 
270
    $context['sandbox']['progress'] = 0;
 
271
    $context['sandbox']['current_user'] = 0;
 
272
    $context['sandbox']['max'] = (integer) db_result(db_query('SELECT COUNT(u.uid)
 
273
      FROM {users} u
 
274
      LEFT JOIN {xmlsitemap_user} xu ON xu.uid = u.uid
 
275
      WHERE u.uid <> 0
 
276
        AND xu.uid IS NULL')
 
277
    );
 
278
  }
 
279
  if ($context['sandbox']['max']) {
 
280
    $result = db_query_range('SELECT u.uid, u.created AS changed
 
281
      FROM {users} u
 
282
      LEFT JOIN {xmlsitemap_user} xu ON xu.uid = u.uid
 
283
      WHERE xu.uid IS NULL
 
284
        AND u.uid > %d
 
285
      ORDER BY u.uid ASC',
 
286
      $context['sandbox']['current_user'], 0, 1
 
287
    );
 
288
    if ($row = db_fetch_object($result)) {
 
289
      drupal_write_record('xmlsitemap_user', $row);
 
290
      $context['sandbox']['progress']++;
 
291
      $context['sandbox']['current_user'] = $row->uid;
 
292
      $context['results']['added'] = $context['sandbox']['progress'];
 
293
    }
 
294
    if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
 
295
      $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
 
296
    }
 
297
  }
 
298
}
 
299
 
 
300
/**
 
301
 * Batch function used to update the module tables.
 
302
 * @param $context
 
303
 *  The context parameter passed from batch_process().
 
304
 */
 
305
function _xmlsitemap_user_module_table_delete_rows(&$context) {
 
306
  if (!isset($context['sandbox']['progress'])) {
 
307
    $context['sandbox']['progress'] = 0;
 
308
    $context['sandbox']['current_user'] = 0;
 
309
    $context['sandbox']['max'] = (integer) db_result(db_query('SELECT COUNT(u.uid)
 
310
      FROM {xmlsitemap_user} xu
 
311
      LEFT JOIN {users} u ON u.uid = xu.uid
 
312
      WHERE u.uid IS NULL')
 
313
    );
 
314
  }
 
315
  if ($context['sandbox']['max']) {
 
316
    $uid = db_result(
 
317
      db_query("SELECT xu.uid
 
318
        FROM {xmlsitemap_user} xu
 
319
        LEFT JOIN {users} u ON u.uid = xu.uid
 
320
        WHERE u.uid IS NULL
 
321
          AND xu.uid > %d",
 
322
        $context['sandbox']['current_user']
 
323
      )
 
324
    );
 
325
    if ($uid === FALSE) {
 
326
      $context['finished'] = 1;
 
327
    }
 
328
    else {
 
329
      db_query('DELETE FROM {xmlsitemap_user} WHERE uid = %d', $uid);
 
330
      $context['sandbox']['progress']++;
 
331
      $context['sandbox']['current_user'] = $uid;
 
332
      $context['results']['deleted'] = $context['sandbox']['progress'];
 
333
      if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
 
334
        $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
 
335
      }
 
336
    }
 
337
  }
 
338
}
 
339
 
258
340
/**
259
341
 * @} End of "addtogroup xmlsitemap".
260
342
 */