Jump to content

Recommended Posts

Theres such code in one of Drupals modules:

<?php

 

/**

* Implementation of hook_menu().

*/

function me_menu($may_cache) {

  $items=array();

 

  if ($may_cache) {

$aliases = explode("\n",variable_get('me_aliases','user/me'));

foreach($aliases as $alias) {

  // check to see if there's a 'me' to replace;

  // either '.../me/...', 'me/...' or '.../me' but eg 'readme/...' does not count

  $alias = preg_split('/[?#]/',$alias);

  $alias = trim(check_url($alias[0]),"/ \t\nr\");

  if(preg_match('/(/m|^m)(e$|e/)/',$alias,$matches)>0){

$items[] = array(

  'path' => $alias,

  'type' => MENU_CALLBACK,

  'callback' => 'me_relay',

  'access' => true, // we're handing over access control to the destiation page

);

  }

}

 

$items[] = array(

  'path' => 'admin/settings/me',

  'title' => t('\'me\' Aliases'),

  'description' => t('Define URL paths for Me aliasing.'),

  'callback' => 'drupal_get_form',

  'callback arguments' => array('me_settings'),

  'access' => user_access('administer site configuration'),

  'type' => MENU_NORMAL_ITEM, // optional

);

  }

 

  return $items;

}

 

/**

* Implementation of hook_settings().

*

* Provide a single textbox that allows admins to enter any number of paths containing 'me'

*/

function me_settings() {

  $form['me_aliases'] = array(

'#type'=>'textarea',

'#title'=>t('Aliases to create'),

'#default_value'=>variable_get('me_aliases',"user/me"),

'#cols'=>50,

'#rows'=>6 ,

'#description'=>t('The per-user aliases to create. Each alias must contain the \'me\' fragment or it will be ignored. Enter one alias per line, and do not include trailing or leading slashes.'),

  );

 

  return system_settings_form($form);

}

 

/**

* Forward to same url with proper username this time.

*

* The paths have already been checked to contain 'me' in the _menu hook.

* We don't have to check node access, drupal_goto will take care of that.

*/

function me_relay() {

  global $user;

 

  if($user->uid!=0) {

$index = 0;

$destination = '';

$fragment = arg(0);

while($fragment) {

  $destination.=(($destination=='')?'':'/').(($fragment=='me')?$user->uid:$fragment);

  $index++;

  $fragment = arg($index);

}

drupal_goto($destination);

  } else {

// user is not logged in

drupal_set_message(t('Please login to access this personalised page.'));

$destination = "destination=". drupal_urlencode($_GET['q']);

drupal_goto('user/login', $destination);

  }

}

?>

 

its all about changing in the url word "me" to current user_id (uid), but i want it to be changed to user name. This is no problem i change uid to name and done, but it doesnt work. So i want it to be stable and work this way:

 

the url is: http://mypage.com/gallery/me (cause then this module works) and it travels me into: http://mypage.com/v/Utilisateur/pturkowski (because "pturkowski" is name of me and im currently logged in)

 

I believe its about changing this thing:

      $destination.=(($destination=='')?'':'/').(($fragment=='me')?$user->name:$fragment);

 

but how.. ?

thx in advance

 

best regards, Piotr

Link to comment
https://forums.phpfreaks.com/topic/66307-redirect-this-is-not-about-mod_rewrite/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.