Index: modules/mysite/plugins/types/path.inc
===================================================================
--- modules/mysite/plugins/types/path.inc (revision 964)
+++ modules/mysite/plugins/types/path.inc (working copy)
@@ -8,7 +8,7 @@
*
*/
function mysite_type_path($get_options = TRUE) {
- if (module_exists('path')) {
+ if (module_exists('path') && !module_exists('pathauto')) {
$type = array(
'name' => t('Path'),
'description' => t('Path Aliases: Creates mysite/USERNAME path aliases for all MySite users.'),
@@ -40,16 +40,17 @@
*
*/
function mysite_type_path_updated($uid) {
- $types = variable_get('mysite_content', NULL);
- if (!empty($types['path']) && $uid > 0) {
- $alias = variable_get('mysite_path_rules', 0);
- $sql = "SELECT uid, name FROM {users} WHERE uid = %d";
- $result = db_query($sql, $uid);
- $myuser = db_fetch_object($result);
- $path = "mysite/$myuser->name";
- $check = drupal_lookup_path('alias', $path);
- if ($check == FALSE) {
- path_set_alias("mysite/$myuser->uid/view", $path);
- }
+ if ($uid > 0) return; // authenticated users only
+ $account = user_load(array('uid' => $uid));
+ $src = 'mysite/'. $account->uid .'/view';
+
+ if (module_exists('pathauto')) { // pathauto is enabled
+ $alias = pathauto_create_alias('mysite', 'update', $placeholders = array( // let pathauto handle this
+ t('[user]') => pathauto_cleanstring($account->name),
+ t('[uid]') => $account->uid,
+ ), $src);
+ } else if (($types = variable_get('mysite_content', NULL)) && !empty($types['path'])) { // user enabled MySite path aliases
+ path_set_alias($src); // nuke existing aliases for this user's MySite page
+ path_set_alias($src, $alias); // create a new url alias for this user's MySite page
}
-}
\ No newline at end of file
+}
\ No newline at end of file
Index: modules/mysite/mysite.module
===================================================================
--- modules/mysite/mysite.module (revision 973)
+++ modules/mysite/mysite.module (working copy)
@@ -3574,4 +3574,53 @@
$top = drupal_render($form);
$output = $top . $table . $buttons;
return $output;
-}
\ No newline at end of file
+}
+
+/**
+ * Implementation of hook_pathauto() for MySite pages.
+ *
+ */
+function mysite_pathauto($op) {
+ switch ($op) {
+ case 'settings':
+ $settings = array();
+ $settings['module'] = 'mysite';
+ $settings['groupheader'] = t('MySite path settings');
+ $settings['patterndescr'] = t('Pattern for MySite page paths');
+ $settings['patterndefault'] = t('mysite/[user]');
+ $settings['placeholders'] = array(
+ t('[user]') => t('The name of the user.'),
+ t('[uid]') => t('The id number of the user.')
+ );
+ $settings['bulkname'] = t('Bulk update MySite paths');
+ $settings['bulkdescr'] = t('Generate aliases for all existing MySite pages which do not already have aliases.');
+ return (object) $settings;
+ default:
+ break;
+ }
+}
+
+/**
+ * Implementation of hook_pathauto_bulkupdate().
+ *
+ * Generate aliases for all users without aliases.
+ *
+ */
+function mysite_pathauto_bulkupdate() {
+ $count = 0;
+ $placeholders = array();
+
+ $result = db_query('SELECT m.uid, u.name FROM {mysite} m INNER JOIN {users} u ON m.uid = u.uid WHERE u.status = 1');
+ while ($account = db_fetch_object($result)) {
+ if ($alias = pathauto_create_alias('mysite', 'bulkupdate', $placeholders = array(
+ t('[user]') => pathauto_cleanstring($account->name),
+ t('[uid]') => $account->uid,
+ ), $src = 'mysite/'. $account->uid .'/view')) {
+ $count++;
+ }
+ }
+
+ drupal_set_message(format_plural($count,
+ "Bulk update of MySite pages completed, one alias generated.",
+ "Bulk update of MySite pages completed, @count aliases generated."));
+}
\ No newline at end of file