Skip to content

Commit 9100f1f

Browse files
committed
Merge branch 'feature/clean-url-for-disp-user' into 7.2dev
# Conflicts: # htsrv/profile_update.php # inc/_blog_main.inc.php # inc/collections/model/_blog.class.php # inc/collections/views/_coll_seo.form.php # inc/collections/views/_coll_urls.form.php # inc/links/model/_link.funcs.php # inc/widgets/widgets/_basic_menu_link.widget.php # inc/widgets/widgets/_coll_common_links.widget.php # plugins/_autolinks.plugin.php
2 parents 87b9eaf + 30328f5 commit 9100f1f

12 files changed

Lines changed: 142 additions & 16 deletions

File tree

htsrv/login.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@
302302
$Collection = $Blog = $BlogCache->get_by_ID( $blog );
303303
if( $Blog )
304304
{
305-
$changepwd_url = $Blog->get( 'userurl', array( 'url_suffix' => 'disp=pwdchange&reqID='.$reqID, 'glue' => '&' ) );
305+
$changepwd_url = $Blog->get( 'pwdchangeurl', array( 'url_suffix' => 'reqID='.$reqID, 'glue' => '&' ) );
306306
}
307307
}
308308

htsrv/profile_update.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@
201201
}
202202
elseif( ! empty( $Blog ) )
203203
{
204-
header_redirect( url_add_param( $Blog->get( 'userurl' ), 'user_ID='.$user_ID, '&' ), 303 ); // Will EXIT
204+
header_redirect( $Blog->get( 'userurl', array( 'user_ID' => $user_ID ) ), 303 ); // Will EXIT
205205
}
206206
// We have EXITed already at this point!!
207207
break;
@@ -238,7 +238,7 @@
238238
}
239239
elseif( ! empty( $Blog ) )
240240
{
241-
header_redirect( url_add_param( $Blog->get( 'userurl' ), 'user_ID='.$user_ID, '&' ), 303 ); // Will EXIT
241+
header_redirect( $Blog->get( 'userurl', array( 'user_ID' => $user_ID ) ), 303 ); // Will EXIT
242242
}
243243
// We have EXITed already at this point!!
244244
break;
@@ -271,7 +271,7 @@
271271
// Redirect so that a reload doesn't write to the DB twice:
272272
if( ! empty( $Blog ) )
273273
{
274-
header_redirect( url_add_param( $Blog->get( 'userurl' ), 'user_ID='.$user_ID, '&' ), 303 ); // Will EXIT
274+
header_redirect( $Blog->get( 'userurl', array( 'user_ID' => $user_ID ) ), 303 ); // Will EXIT
275275
}
276276
// We have EXITed already at this point!!
277277
break;
@@ -309,7 +309,7 @@
309309

310310
if( empty( $redirect_to ) )
311311
{ // Redirect to display user page for cases when redirect param cannot be defined above by some reason:
312-
$redirect_to = $Blog->get( 'userurl', array( 'glue' => '&' ) );
312+
$redirect_to = $Blog->get( 'userurl', array( 'glue' => '&', 'user_ID' => $current_User->ID, 'user_login' => $current_User->login ) );
313313
}
314314
break;
315315
case 'upload_avatar':

inc/_blog_main.inc.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,8 @@
318318
{
319319
// TAG? Does the pathinfo end with a / or a ; ?
320320
$last_len = strlen( $last_part );
321+
$user_page_prefix = $Blog->get_setting( 'user_prefix' ).':';
322+
$user_page_prefix_length = strlen( $user_page_prefix );
321323
if( ( $last_char == '-' && ( ! $tags_dash_fix || $last_len != 40 ) ) // In very old b2evo version we had ITEM slugs truncated at 40 and possibly ending with `-`
322324
|| $last_char == ':'
323325
|| $last_char == ';' )
@@ -334,6 +336,24 @@
334336
}
335337
$disp = 'posts';
336338
}
339+
elseif( $user_page_prefix_length > 1 &&
340+
strlen( $path_elements[0] ) > $user_page_prefix_length &&
341+
substr( $path_elements[0], 0, $user_page_prefix_length ) == $user_page_prefix )
342+
{ // Alias for disp=user:
343+
$user_ID = -1; // Set -1 for case when user is not detected by login and ID
344+
$user_request = substr( $path_elements[0], $user_page_prefix_length );
345+
346+
$UserCache = & get_UserCache();
347+
if( $User = & $UserCache->get_by_login( $user_request ) ||
348+
( is_number( $user_request ) && $User = & $UserCache->get_by_ID( $user_request, false, false ) ) )
349+
{ // If user is detected in DB by login or ID:
350+
$user_ID = $User->ID;
351+
}
352+
353+
// Set disp to user with ID of user which was detected from request URL:
354+
$disp = 'user';
355+
set_param( 'user_ID', $user_ID );
356+
}
337357
elseif( ( $tags_dash_fix && $last_char == '-' && $last_len == 40 ) || $last_char != '/' )
338358
{ // NO ENDING SLASH or ends with a dash, is 40 chars long and $tags_dash_fix is true
339359
// -> We'll consider this to be a ref to a post.

inc/collections/model/_blog.class.php

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,17 @@ function load_from_Request( $groups = array() )
876876
// Tag posts per page:
877877
$this->set_setting( 'tag_posts_per_page', param( 'tag_posts_per_page', 'integer', NULL ), true );
878878

879+
if( param( 'user_prefix', 'string', NULL ) !== NULL )
880+
{ // User profile page prefix:
881+
param_check_regexp( 'user_prefix', '#^[a-z0-9\-_]*$#i', sprintf( T_('User profile page prefix can contain only letters, digits, %s or %s.'), '<code>-</code>', '<code>_</code>' ) );
882+
$this->set_setting( 'user_prefix', get_param( 'user_prefix' ) );
883+
}
884+
885+
if( param( 'user_links', 'string', NULL ) !== NULL )
886+
{ // User profile URLs:
887+
$this->set_setting( 'user_links', get_param( 'user_links' ) );
888+
}
889+
879890
if( param( 'single_links', 'string', NULL ) !== NULL )
880891
{ // Single post link type:
881892
$this->set_setting( 'single_links', get_param( 'single_links' ) );
@@ -1430,6 +1441,7 @@ function load_from_Request( $groups = array() )
14301441
$this->set_setting( 'tags_structured_data', param( 'tags_structured_data', 'integer', 0 ) );
14311442
$this->set_setting( 'download_noindex', param( 'download_noindex', 'integer', 0 ) );
14321443
$this->set_setting( 'download_nofollowto', param( 'download_nofollowto', 'integer', 0 ) );
1444+
$this->set_setting( 'canonical_user_urls', param( 'canonical_user_urls', 'integer', 0 ) );
14331445
}
14341446

14351447
if( in_array( 'credits', $groups ) )
@@ -3420,11 +3432,52 @@ function get( $parname, $params = array() )
34203432
}
34213433

34223434
if( $this_Blog->get_setting( 'front_disp' ) == $disp_param )
3423-
{ // Get home page of this blog because front page displays current disp
3435+
{ // Get home page of this blog because front page displays current disp:
34243436
$url = $this_Blog->gen_blogurl( 'default' );
34253437
}
3438+
elseif( $disp_param == 'user' && ( isset( $params['user_login'] ) || isset( $params['user_ID'] ) ) )
3439+
{ // Use alias if user login or ID is provided:
3440+
$UserCache = & get_UserCache();
3441+
if( ! isset( $params['user_ID'] ) &&
3442+
( $this_Blog->get_setting( 'user_links' ) == 'params' || $this_Blog->get_setting( 'user_links' ) == 'prefix_id' ) )
3443+
{ // We need get user ID by login:
3444+
if( $param_User = & $UserCache->get_by_login( $params['user_login'] ) )
3445+
{ // Set user ID if it is detected by login:
3446+
$params['user_ID'] = $param_User->ID;
3447+
}
3448+
else
3449+
{ // Wrong request:
3450+
debug_die( 'Undefined param "user_ID" for Blog->get( "userurl" )' );
3451+
}
3452+
}
3453+
if( ! isset( $params['user_login'] ) &&
3454+
$this_Blog->get_setting( 'user_links' ) == 'prefix_login' )
3455+
{ // We need get user login by ID:
3456+
if( $param_User = & $UserCache->get_by_ID( $params['user_ID'], false, false ) )
3457+
{ // Use login if user is detected in DB:
3458+
$params['user_login'] = $param_User->get( 'login' );
3459+
}
3460+
else
3461+
{ // Wrong request:
3462+
debug_die( 'Undefined param "user_login" for Blog->get( "userurl" )' );
3463+
}
3464+
}
3465+
3466+
if( $this_Blog->get_setting( 'user_links' ) == 'params' || $this_Blog->get_setting( 'user_prefix' ) == '' )
3467+
{ // Use params E-g: ?disp=user&user_ID=4
3468+
$url = url_add_param( $this_Blog->gen_blogurl(), 'disp=user'.$params['glue'].'user_ID='.$params['user_ID'], $params['glue'] );
3469+
}
3470+
elseif( $this_Blog->get_setting( 'user_links' ) == 'prefix_id' )
3471+
{ // Use prefix with user ID:
3472+
$url = url_add_tail( $this_Blog->gen_blogurl(), '/'.$this_Blog->get_setting( 'user_prefix' ).':'.$params['user_ID'] );
3473+
}
3474+
else // 'prefix_login'
3475+
{ // Use prefix with user login:
3476+
$url = url_add_tail( $this_Blog->gen_blogurl(), '/'.$this_Blog->get_setting( 'user_prefix' ).':'.$params['user_login'] );
3477+
}
3478+
}
34263479
else
3427-
{ // Add disp param to blog's url when current disp is not a front page
3480+
{ // Add disp param to blog's url when current disp is not a front page:
34283481
$url = url_add_param( $this_Blog->gen_blogurl(), 'disp='.$disp_param, $params['glue'] );
34293482
}
34303483

inc/collections/model/_collsettings.class.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ class CollectionSettings extends AbstractSettings
5555
'paged_noindex' => '1', // META NOINDEX on following blog pages
5656
'paged_nofollowto' => '0', // NOFOLLOW on links to following blog pages
5757

58+
// User profile page settings:
59+
'user_prefix' => 'user',
60+
'user_links' => 'params',
61+
5862
// Single post settings:
5963
'single_noindex' => 0, // META NOINDEX on Single/Page pages
6064
'canonical_item_urls' => 1, // Redirect posts to their canonical Url?
@@ -148,6 +152,9 @@ class CollectionSettings extends AbstractSettings
148152
'tag_prefix' => '', // fp> fp> we want this changed to prefix only for new blogs only
149153
'tag_rel_attrib' => 1, // rel="tag" attribute for tag links (http://microformats.org/wiki/rel-tag) -- valid only in prefix-only mode
150154

155+
// User profile page settings:
156+
'canonical_user_urls' => 1, // Redirect user profile pages to their canonical Url?
157+
151158
// Other filtered pages:
152159
'filtered_noindex' => '1', // META NOINDEX on other filtered pages
153160
'filtered_content' => 'excerpt',

inc/collections/views/_coll_seo.form.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,12 @@ function() {
326326

327327

328328
<?php
329+
$Form->begin_fieldset( TB_('User profile pages').get_manual_link( 'user_pages_seo' ), array( 'id' => 'user_links_fieldset' ) );
330+
$Form->checklist( array(
331+
array( 'canonical_user_urls', 1, TB_('301 redirect to canonical URL when possible'), $edited_Blog->get_setting( 'canonical_user_urls' ) ),
332+
), 'canonical_user_urls_options', TB_('Make canonical') );
333+
$Form->end_fieldset();
334+
329335
$Form->begin_fieldset( TB_('Other filtered pages').get_manual_link('other-filtered-pages-seo') );
330336
$Form->checklist( array(
331337
array( 'filtered_noindex', 1, TB_('META NOINDEX for filtered pages without intro'), $edited_Blog->get_setting( 'filtered_noindex' ) ),

inc/collections/views/_coll_urls.form.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,21 @@ function() {
592592

593593

594594
<?php
595+
$Form->begin_fieldset( TB_('User profile page URLs') . get_manual_link('user-profile-page-url-settings') );
596+
597+
$Form->text_input( 'user_prefix', $edited_Blog->get_setting( 'user_prefix' ), 30, TB_('Prefix'),
598+
TB_('A prefix to be added to the URLs of the user profile pages'),
599+
array( 'maxlength' => 120 ) );
600+
601+
$Form->radio( 'user_links', $edited_Blog->get_setting( 'user_links' ),
602+
array(
603+
array( 'params', TB_('Use params'), TB_('E-g: ').'<code>?disp=user&user_ID=4</code>' ),
604+
array( 'prefix_id', TB_('Use prefix with user ID'), TB_('E-g: ').'<code>prefix:4</code>' ),
605+
array( 'prefix_login', TB_('Use prefix with user login'), TB_('E-g: ').'<code>prefix:login</code>' ),
606+
), TB_('User profile URLs'), true );
607+
608+
$Form->end_fieldset();
609+
595610
$Form->begin_fieldset( TB_('Single post URLs') . get_manual_link('single-post-url-settings') );
596611

597612
$Form->radio( 'single_links', $edited_Blog->get_setting('single_links'),

inc/links/model/_link.funcs.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,22 @@ function get_file_links( $file_ID, $params = array() )
806806
{
807807
if( $current_User->ID != $User->ID && ! check_user_perm( 'users', 'view' ) )
808808
{ // No permission to view other users in admin form
809-
$r .= $params['user_prefix'].'<a href="'.url_add_param( $baseurl, 'disp=user&amp;user_ID='.$User->ID ).'">'.$User->get_username().'</a>';
809+
$BlogCache = & get_BlogCache();
810+
$BlogCache->load_user_blogs();
811+
$user_url = '';
812+
if( ! empty( $BlogCache->cache ) )
813+
{ // Try to use alias user url:
814+
foreach( $BlogCache->cache as $user_Blog )
815+
{ // Use first found collection:
816+
$user_url = $user_Blog->get( 'userurl', array( 'user_ID' => $User->ID, 'user_login' => $User->login ) );
817+
break;
818+
}
819+
}
820+
if( empty( $user_url ) )
821+
{ // Use standard user url:
822+
$user_url = url_add_param( $baseurl, 'disp=user&amp;user_ID='.$User->ID );
823+
}
824+
$r .= $params['user_prefix'].'<a href="'.$user_url.'">'.$User->get_username().'</a>';
810825
}
811826
else
812827
{ // Build a link to display a user in admin form

inc/menus/model/_sitemenuentry.class.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ function get_url()
668668
return $entry_Blog->get( 'lastcommentsurl' );
669669

670670
case 'owneruserinfo':
671-
return url_add_param( $entry_Blog->get( 'userurl' ), 'user_ID='.$entry_Blog->owner_user_ID );
671+
return $entry_Blog->get( 'userurl', array( 'user_ID' => $entry_Blog->owner_user_ID ) );
672672

673673
case 'ownercontact':
674674
return $entry_Blog->get_contact_url();
@@ -810,7 +810,8 @@ function get_url()
810810
{ // Don't show this link for not logged in users:
811811
return false;
812812
}
813-
return $entry_Blog->get( 'userurl' );
813+
global $current_User;
814+
return $entry_Blog->get( 'userurl', array( 'user_ID' => $current_User->ID, 'user_login' => $current_User->login ) );
814815
break;
815816

816817
case 'admin':

inc/skins/_skin.funcs.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ function skin_init( $disp )
945945
$Messages->add( 'User has been added to your contacts.', 'success' );
946946
}
947947
}
948-
header_redirect( $Blog->get( 'userurl', array( 'url_suffix' => 'user_ID='.$user_ID, 'glue' => '&' ) ) );
948+
header_redirect( $Blog->get( 'userurl', array( 'user_ID' => $user_ID ) ) );
949949
}
950950
break;
951951

@@ -978,7 +978,7 @@ function skin_init( $disp )
978978
}
979979
else
980980
{ // Redirect to the user profile page
981-
header_redirect( $Blog->get( 'userurl', array( 'url_suffix' => 'user_ID='.$user_ID, 'glue' => '&' ) ) );
981+
header_redirect( $Blog->get( 'userurl', array( 'user_ID' => $user_ID ) ) );
982982
}
983983
}
984984
}
@@ -1449,6 +1449,15 @@ function skin_init( $disp )
14491449
// Check if current user has an access to view a profile of the requested user:
14501450
check_access_user_profile( $user_ID );
14511451

1452+
if( $Blog->get_setting( 'canonical_user_urls' ) && $redir == 'yes' )
1453+
{ // Check if current user profile URL can be canonical:
1454+
$canonical_url = $Blog->get( 'userurl', array( 'user_ID' => $user_ID, 'glue' => '&' ) );
1455+
if( ! is_same_url( $ReqURL, $canonical_url, $Blog->get_setting( 'http_protocol' ) == 'allow_both' ) )
1456+
{ // Redirect to canonical user profile URL:
1457+
header_redirect( $canonical_url, true );
1458+
}
1459+
}
1460+
14521461
// Initialize users list from session cache in order to display prev/next links:
14531462
// It is used to navigate between users
14541463
load_class( 'users/model/_userlist.class.php', 'UserList' );

0 commit comments

Comments
 (0)