Textpattern CMS support forum

You are not logged in. Register | Login | Help

#301 2016-07-01 13:17:10

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,969
Website

Re: smd_bio : store additional biographical info about your users

Destry wrote #300103:

Redirect 301 /people/destry-wion http://csf.dev/author/destry-wion

That won’t work. Txp requires the full author name in the URL (i.e. Destry+Wion) in order to match the user. Also, as a general rule of thumb — aside from the fact you used the Redirect directive — if you use rewrite and put a static URL beginning http:// in it, the browser will do a full redirect. That’s not what you want is it? You want to “hide” the implementation details and leave /people/destry-wion in the URL, right? Because the plus sign is ugly.

In that case you’re probably better off with something like this (untested) :

RewriteRule ^/people/(.*)-(.*)$ /author/$1+$2 [L]

?

EDIT: That probably won’t work with people that have double-barrelled surnames, but they’re all posh anyway ;-)

EDIT 2: I’m frequently amused by how often regexes look like rude ASCII art.

Last edited by Bloke (2016-07-01 13:22:49)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#302 2016-07-01 16:18:46

Destry
Moderator
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,339
Website

Re: smd_bio : store additional biographical info about your users

Bloke wrote #300106:

Txp requires the full author name in the URL (i.e. Destry+Wion) in order to match the user.

Ok. I was tackling it under the misguided notion that smd_wrap would do its voodoo first, then the redirect part would happen. But now that you mention it…

Also, as a general rule of thumb — aside from the fact you used the Redirect directive — if you use rewrite and put a static URL beginning http:// in it, the browser will do a full redirect. That’s not what you want is it? You want to “hide” the implementation details and leave /people/destry-wion in the URL, right? Because the plus sign is ugly.

Well, what I thought I was doing was permanently redirecting old URLs like /people/first-last to new URLs like /author/Destry+Wion that were masked as destry-wion via smd_wrap. Besides search engines, there’s also the bio owners themselves who probably have their pages bookmarked or linked somewhere.

But the only reason I thought to go lowercase and force a - between names was so I could do a bulk redirect on the section path part easier, since on the surface that was the only thing different (again, misguided about how smd_wrap works). I prefer a bulk solution than having to do individual redirects for each bio, but there’s not a million of them so I can live with it.

But if that doesn’t make any sense, then I’m happy just using the true URLs like /author/Destry+Wion, without any smd_wrap magic — you know, let your true colors shine through — as long as I can get the ReWrite rules figured out. I actually don’t mind the + sign. A math symbol is a math symbol is a math symbol. ;) What I didn’t like, however, was the %20 that was showing up. F that S! That should never happen no matter what path someone arrives, ideally.

Offline

#303 2016-07-01 16:36:56

Destry
Moderator
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,339
Website

Re: smd_bio : store additional biographical info about your users

Bloke wrote #300058:

Aha! Since you’re constructing the URLs by hand here in the href attribute, you can put whatever you like.

I’m curious by your reaction here. I thought that was the only way to do it. (Remember, this whole notion of there being a default /author path was completely foreign to me, and still a bit vague in my logic banks.)

But what other means is possible that you might be implying? Are you saying that I don’t have to manually construct a URL to pass? It will just automatically pass as /author/First+Last? What would that look like in code? I mean, what would I have to do there.

Because if we just pass the true /author URL and do ReWrite 301 redirects on that, I’m happy, and we can put this particular snafu to bed.

Offline

#304 2016-07-01 22:08:49

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,969
Website

Re: smd_bio : store additional biographical info about your users

Destry wrote #300112:

Are you saying that I don’t have to manually construct a URL to pass? It will just automatically pass as /author/First+Last?

If you do <txp:author link="1" /> from inside an article, you get a full anchor to /author/Real+Name without having to lift a finger. But that’s only of use from within an article context because it links to other articles by the same author. Since you’re manually setting up an author directory, you don’t have article context and thus have to construct the URLs by hand. The ‘Aha’ utterance was simply because we got to the bit of code I needed.

what I thought I was doing was permanently redirecting old URLs like /people/first-last to new URLs like /author/Destry+Wion that were masked as destry-wion via smd_wrap.

No, smd_wrap was just to fudge the fake /people/first-last URLs from the only user-centric piece of info we have available to us that contains their full name: RealName. For better or worse (usually worse) Txp only recognises URLs for a user’s real name. If an admin changes their real name (e.g. someone getting married) then the URL changes and link juice is eroded. If, however, it linked to their login name /author/destry which is invariable (unless you start dicking around in SQL) then the URL never changes, BUT you leak the user account login info, which could potentially be seen as a security risk.

That latter point is probably why it’s keyed off RealName. I don’t like that much: my take is that it’s likely a historical paranoia paradigm. Even if a username is known, a strong password will keep an account safe. The fact that so many people don’t know how to set a strong password is the real problem, not the fact that an attacker can guess, or knows, your login name too. If you can hand someone your safety deposit box (login name) and a ruddy great hammer (a shitload of fast computers) and they still can’t get in, the key (password) you keep on a chain round your neck is more than adequate.

So, going back to what we were doing:

  • Step 1: Display all users using <txp:smd_bio_authors />. Get RealName from smd_bio tag for each person and construct fake URLs to /people/first-last.
  • Step 2: When clicked, .htaccess silently rewrites rules that match /people/first-last back to /author/first+last and feeds it to Txp.
  • Step 3: Txp sees /author/first+last, thinks it’s an author landing page and serves the URL.
  • Step 4: Inside your <txp:if_author> wrapper in your default Page template, display user’s biographical details, other articles, etc.
  • Step 5: Profit.

I prefer a bulk solution than having to do individual redirects for each bio

That’s what the .htaccess rule I used earlier tried to do: match the regex pattern /people/first-last and sneakily feed Txp with /author/first+last to keep it happy. Case sensitivity doesn’t matter, thank goodness.

I actually don’t mind the + sign… What I didn’t like, however, was the %20 that was showing up.

Well a space gets encoded in web land into %20 — the hexadecimal for the space char (decimal: 32). Perhaps in 4.6.0 we’re encoding it instead of passing through a plain space like in earlier versions. I know there’s a lot of stuff we’ve had to fix because of double-encoded ampersands and such like. Maybe this is another casualty of the security feature of not outputting stuff raw without first transliterating it into something “safe” to avoid XSS injection attacks and such like. But if we can output the user name using a plus symbol instead of a transcoded space, you’re right, it’d look way better.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#305 2016-07-04 06:40:10

Destry
Moderator
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,339
Website

Re: smd_bio : store additional biographical info about your users

Bloke wrote #300121:

  • Step 1: Display all users using <txp:smd_bio_authors />. Get RealName from smd_bio tag for each person and construct fake URLs to /people/first-last.
  • Step 2: When clicked, .htaccess silently rewrites rules that match /people/first-last back to /author/first+last and feeds it to Txp.
  • Step 3: Txp sees /author/first+last, thinks it’s an author landing page and serves the URL.
  • Step 4: Inside your <txp:if_author> wrapper in your default Page template, display user’s biographical details, other articles, etc.
  • Step 5: Profit.

Still broke as a joke, Bloke.

Let me see if I get this right…

Step 1 is saying use <txp:smd_bio_authors /> on the bio list (our faces grid) section, and use the retired people/ section in the path? Here’s the relevant code:

<txp:smd_bio_author author="SMD_PRIVS:1:2:3:4:5:6" sort="RealName asc" wraptag="ul" class="grid authors">
  <txp:smd_bio_info fields="RealName, author_photo">
    <li class="c33 m">
      <a href="<txp:site_url />author/<txp:smd_wrap_all transform="case|lower, replace|| |-"><txp:smd_bio_data field="RealName" /></txp:smd_wrap_all>"><span class="author-photo"><img src="/images/<txp:smd_bio_data field="author_photo" />.jpg" alt="<txp:smd_bio_data field="RealName" />" /></span><span class="author-name"><txp:smd_bio_data field="RealName" /></span></a>
    </li>
  </txp:smd_bio_info>
</txp:smd_bio_author>

Step 2 says ModRewrite will do it’s thing. Here’s my .htaccess file… Maybe the rule is not in the right place?

# BEGIN Textpattern
#DirectoryIndex index.php index.html

#Options +FollowSymLinks
#Options -Indexes
#ErrorDocument 403 default

<IfModule mod_rewrite.c>
    RewriteEngine On
    #RewriteBase /relative/web/path/

	# BEGIN CUSTOM CSF RULES
		## Class B redirection (no "www")
		RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
		RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

		## /people redirects to /author (3 july 2016)
		RewriteRule ^/people/(.*)-(.*)$ /author/$1+$2 [L]
	# END CUSTOM RULES

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^(.+) - [PT,L]

    RewriteCond %{REQUEST_URI} !=/favicon.ico
    RewriteRule ^(.*) index.php

    RewriteCond %{HTTP:Authorization}  !^$
    RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]
</IfModule>

#php_value register_globals 0

<IfModule mod_mime.c>
    AddType image/svg+xml  svg svgz
    AddEncoding gzip       svgz
</IfModule>
# END Textpattern

Step 3, Txp thinks it’s a landing page and outputs the profile on the default page… But this is where I only get a 404. The code on that page uses an <txp:if_author> conditional to negotiate whether a profile or regular homepage content, calling a form in the case of the profile…

<txp:if_author>
<txp:hide> =============  AUTHORS  =========== </txp:hide>

<main class="main grid" role="main">
  	<div class="c11 m"> 
	  <txp:hide> + AUTHOR PROFILE + </txp:hide>
	  <txp:output_form form="authors" />
	</div>

	<div class="rail c5 push-down" role="complementary">
		<txp:output_form form="rail-authors" />
	</div>
</main> <!-- end of role=main -->

<txp:else />

... 

And here is the full <txp:output_form form="authors" /> form…

<txp:if_author>
<txp:smd_bio_author author='<txp:author title="0" />'>
  <txp:smd_bio_info fields="RealName, bio, author_photo, caption, website, twitter, gplus">
    <article class="principle profile grid">
      <h1><txp:smd_bio_data field="RealName" /></h1>
			<section class="c10 m">
				<txp:smd_wrap transform="textile">
					<txp:smd_bio_data field="bio" />
				</txp:smd_wrap>
				<h2>Articles written</h2>
				<txp:smd_bio_articles wraptag="ul" break="li" author='<txp:smd_bio_data field="RealName" />' section="articles"><txp:permlink><txp:title /></txp:permlink></txp:smd_bio_articles>
			</section>
		<figure class="biofigure c6">
			<txp:smd_if_bio field="author_photo">
				<txp:image width="0" height="0" id="<txp:smd_bio_data field="author_photo" />" />
			<txp:else />
				<img src="/assets/img/nohead.png" alt="typewriter">
			</txp:smd_if_bio>
			<figcaption class="headcap">
				<txp:smd_if_bio field="caption">
					<txp:smd_bio_data field="caption" />
				</txp:smd_if_bio>
				<txp:smd_wrap_all wraptag="ul" class="biocaptionlinks">
					<txp:smd_wrap wraptag="li" transform="link|Website">
						<txp:smd_bio_data field="website" />
					</txp:smd_wrap>
					<txp:smd_if_bio field="twitter">
						<txp:smd_if field='<txp:smd_bio_data field="twitter" />' operator="begins" value="http">
							<txp:smd_wrap wraptag="li">
								<a href='<txp:smd_bio_data field="twitter" />'>Twitter</a>
							</txp:smd_wrap>
						<txp:else />
							<txp:smd_wrap wraptag="li" transform="replace||@">
								<a href='https://twitter.com/<txp:smd_bio_data field="twitter" />'>Twitter</a>
							</txp:smd_wrap>
						</txp:smd_if>
					</txp:smd_if_bio>
					<txp:smd_wrap wraptag="li" transform="link|Google+">
						<txp:smd_bio_data field="gplus" />
					</txp:smd_wrap>
				</txp:smd_wrap_all>				
			</figcaption>
		</figure>
    </article>
  </txp:smd_bio_info>
</txp:smd_bio_author>
</txp:if_author>

Note I’ve removed all Txp variables from throughout all the locations that originally came with the code from the TXP Mag build. For example, the part at bottom of the authors block of code posted earlier is now gone. I’m guessing those variables are not really needed now that I’m dropping gbp_permanent_links.

Offline

#306 2016-07-04 08:28:38

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,969
Website

Re: smd_bio : store additional biographical info about your users

Destry wrote #300150:

on the bio list… use the retired people/ section in the path?

Well if the /people section is retired then this rewrite rule:

RewriteRule ^/people/(.*)-(.*)$ /author/$1+$2 [L]

won’t match anything. Nothing rewritten = 404. Perhaps this might bear more fruit:

RewriteRule ^/author/(.*)-(.*)$ /author/$1+$2 [L]

?


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#307 2016-07-04 09:13:08

Destry
Moderator
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,339
Website

Re: smd_bio : store additional biographical info about your users

Still get a 404.

As a side on that rewrite, what if someone in the wild clicked an old profile link that was bookmarked once upon a time, or saved in a different website (…/people/stef-dawson); how does the revised ReWrite rule address that possibility?

Offline

#308 2016-07-04 09:20:52

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,969
Website

Re: smd_bio : store additional biographical info about your users

Destry wrote #300163:

Still get a 404.

Nuts. Something’s going on that I don’t understand then. Seems like it should work in theory.

what if someone in the wild clicked an old profile link

Ah, then you should probably keep the old rule in there as well to cover that eventuality. If only it bloody worked at all! Hmmm.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#309 2016-07-04 09:23:28

Destry
Moderator
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,339
Website

Re: smd_bio : store additional biographical info about your users

Bloke, I know it’s not a good time, but maybe it saves support time in this case, instead of this lengthy back-and-forth… But one thing we could do here, since you do have an account in the CSF site, is add you to the CSF GitHub team, which has my latest dev files (rah flat and all) and give you a copy of the latest DB, then you could poke at it on your own machine and dime-time.

Offline

#310 2016-07-04 09:41:21

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,969
Website

Re: smd_bio : store additional biographical info about your users

@Destry: I’m testing some simple hard-coded redirect rules on my local setup and hitting a brick wall.

I wondered if maybe the [L] flag (last rule) was killing it, but setting it to [R] (redirect) or empty made no difference, nor did moving the rule up and down in the .htaccess file. It’s 404 city. More research required.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

Board footer

Powered by FluxBB