Pomoc - Szukaj - U¿ytkownicy - Kalendarz
Pe³na wersja: [php] przekierowanie (to nie jest mod_rewrite)
Forum PHP.pl > Forum > PHP
pturkowski
Jest sobie taki kod w jednym z modu³ów drupala:
  1. <?php
  2.  
  3. /**
  4.  * Implementation of hook_menu().
  5.  */
  6. function me_menu($may_cache) {
  7. $items=array();
  8.  
  9. if ($may_cache) {
  10. $aliases = explode("\n",variable_get('me_aliases','user/me'));
  11. foreach($aliases as $alias) {
  12. // check to see if there's a 'me' to replace;
  13. // either '.../me/...', 'me/...' or '.../me' but eg 'readme/...' does not count
  14. $alias = preg_split('/[?#]/',$alias);
  15. $alias = trim(check_url($alias[0]),"/ \t\nr\");
  16. if(preg_match('/(/m|^m)(e$|e/)/',$alias,$matches)>0){
  17. $items[] = array(
  18. 'path' => $alias,
  19. 'type' => MENU_CALLBACK,
  20. 'callback' => 'me_relay',
  21. 'access' => true, // we're handing over access control to the destiation page
  22. );
  23. }
  24. }
  25.  
  26. $items[] = array(
  27. 'path' => 'admin/settings/me',
  28. 'title' => t(''me' Aliases'),
  29. 'description' => t('Define URL paths for Me aliasing.'),
  30. 'callback' => 'drupal_get_form',
  31. 'callback arguments' => array('me_settings'),
  32. 'access' => user_access('administer site configuration'),
  33. 'type' => MENU_NORMAL_ITEM, // optional
  34. );
  35. }
  36.  
  37. return $items;
  38. }
  39.  
  40. /**
  41.  * Implementation of hook_settings().
  42.  *
  43.  * Provide a single textbox that allows admins to enter any number of paths cont
    aining 'me'
  44.  */
  45. function me_settings() {
  46. $form['me_aliases'] = array(
  47. '#type'=>'textarea',
  48. '#title'=>t('Aliases to create'),
  49. '#default_value'=>variable_get('me_aliases',"user/me"),
  50. '#cols'=>50,
  51. '#rows'=>6 ,
  52. '#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 tr
    ailing or leading slashes.'),
  53. );
  54.  
  55. return system_settings_form($form);
  56. }
  57.  
  58. /**
  59.  * Forward to same url with proper username this time.
  60.  *
  61.  * The paths have already been checked to contain 'me' in the _menu hook.
  62.  * We don't have to check node access, drupal_goto will take care of that.
  63.  */
  64. function me_relay() {
  65. global $user;
  66.  
  67. if($user->uid!=0) {
  68. $index = 0;
  69. $destination = '';
  70. $fragment = arg(0);
  71. while($fragment) {
  72. $destination.=(($destination=='')?'':'/').(($fragment=='me')?$user->name:$fragment);
  73. $index++;
  74. $fragment = arg($index);
  75. }
  76. drupal_goto($destination);
  77. } else {
  78. // user is not logged in
  79. drupal_set_message(t('Please login to access this personalised page.'));
  80. $destination = "destination=". drupal_urlencode($_GET['q']);
  81. drupal_goto('user/login', $destination);
  82. }
  83. }
  84. ?>


o co chodzi? chodzi o to ze jak mam link na stronie: "gallery/me" to przekieruje mnie na strone "gallery/piotr" (bo jestem zalogowany jako "piotr"
a ja bym chcial, zeby majac link absolutny: "http://mojastrona.fr/gallery/me" przekierowalo mnie na "http://mojastrona.fr/v/Utilisateur/piotr".

Prawdopodobnie trzeba zmieniæ tylko to:
$destination.=(($destination=='')?'':'/').(($fragment=='me')?$user->name:$fragment);

ale patrze na to i nie widze...

dzieki z gory i pozdrawiam
kicaj
Fragment:
  1. <?php
  2. //...
  3. if($user->uid!=0) {
  4. $index = 0;
  5. $destination = 'http://mojastrona.fr/v/Utilisateur/';
  6. $fragment = arg(0);
  7. //...
  8. ?>

Ale moge sie mylic...
To jest wersja lo-fi g³ównej zawarto¶ci. Aby zobaczyæ pe³n± wersjê z wiêksz± zawarto¶ci±, obrazkami i formatowaniem proszê kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.