Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
'Articles' on the Fly - User Directory
- I have a section called directory
- I have many authors
I have a linking author list which uses the following URL structure per each:
site.com/directory/user1
site.com/directory/user2
site.com/directory/user3
site.com/directory/user4
site.com/directory/infinity
Now, I am trying to avoid creating and assigning an article for each author.
Can I take the username in the URL and put it to use?
txtstrap (Textpattern + Twitter Bootstrap + etc…)
Offline
Re: 'Articles' on the Fly - User Directory
What if you make links read site.com/directory/?author=user1
and so on?
Then you could use adi_gps to read out the author url variable which automatically places it in a txp variable. From then on you can use txp:variable
/ txp:if_variable
for your page template/forms.
TXP Builders – finely-crafted code, design and txp
Offline
Re: 'Articles' on the Fly - User Directory
What if you make links read site.com/directory/?author=user1 and so on?
Yes indeed. I’ve just discovered that.
Then you could use adi_gps to read out the author url variable which automatically places it in a txp variable. From then on you can use txp:variable / txp:if_variable for your page template/forms.
I’m using this so far:
<txp:php>
$val = $_GET['author'];
echo "$val";
</txp:php>
I’m placing that where needed in a form that contains my author profile data. I will compare the adi_gps methods. It seems that that plugin addresses this sort of question exactly.
Thank you for pointing that out.
txtstrap (Textpattern + Twitter Bootstrap + etc…)
Offline
Re: 'Articles' on the Fly - User Directory
I’m now getting what I need with profiles showing under the urls:
site.com/directory/?variable=username
Anyone have mod_rewrite bit for .htaccess to remove ?variable=
from this url?
txtstrap (Textpattern + Twitter Bootstrap + etc…)
Offline
Re: 'Articles' on the Fly - User Directory
not tested but try something like this:
RewriteRule ^(directory)/([^/]+)$ index.php?s=$1&variable=$2 [L]
TXP Builders – finely-crafted code, design and txp
Offline
Re: 'Articles' on the Fly - User Directory
jakob wrote:
not tested but try something like this:
RewriteRule ^(directory)/([^/]+)$ index.php?s=$1&variable=$2 [L]
Ah yes. Close. I guess the variable would be missing from the URL then. :)
That is if I go to site.com/directory/username
then none of my profile fields can use the author variable and thus appear empty. The URL does work though in the sense that it shows the directory page.
I reckon I could keep the RewriteRule and try and pull the username from this URL instead: site.com/directory/username
Now to consider how to do that…
Last edited by whaleen (2009-09-16 22:26:26)
txtstrap (Textpattern + Twitter Bootstrap + etc…)
Offline
Re: 'Articles' on the Fly - User Directory
site.com/directory/?variable=username
Anyone have mod_rewrite bit for .htaccess to remove
?variable=
from this url?
I reckon I could keep the RewriteRule and try and pull the username from this URL instead:
site.com/directory/username
Wasn’t that what you were trying to achieve?
The rewrite rule should make the username
your variable so if you do $_GET['variable']
or use adi_gps, it should return username
.
TXP Builders – finely-crafted code, design and txp
Offline
Re: 'Articles' on the Fly - User Directory
I have this for fetching the variable from the URL (variable being author
, username
, or whatever
as long as it’s in the particular location the RewriteRule modifies in the URL string):
Real Name: <txp:smd_bio_info author="<txp:adi_gps name="author" />" items="RealName" label="" />
I have your RewriteRul you suggested in the .htaccess:
RewriteRule ^(directory)/([^/]+)$ index.php?s=$1&author=$2 [L]
Sorry I’m getting alittle confused. Refilling coffee now.
Last edited by whaleen (2009-09-17 21:15:26)
txtstrap (Textpattern + Twitter Bootstrap + etc…)
Offline
Re: 'Articles' on the Fly - User Directory
whaleen wrote:
<txp:smd_bio_info author="<txp:adi_gps name="author" />" items="RealName" label="" />
Should be, if smd_bio doesn’t re-re-parse it’s own values:
<txp:smd_bio_info author='<txp:adi_gps name="author" />' items="RealName" label="" />
Also, I supose that the rewrite works, as it, well, should. But as different Apache/Rewrite-lib builds do handle Rewrite rules differently, till to the point where the bastard doesn’t take any less or more booz than TXP’s own rules sets till the pass-coma-death point.
Tho, you might try the thing that is almost same, expect flag, section and mysterious allow all star.
RewriteRule ^directory/(.*)$ ?s=directory&author=$1 [NC]
The rule might want to be before TXP’s rulesets, right after the line where you turn the RewriteEngine on.
Last edited by Gocom (2009-09-17 00:39:35)
Offline
Re: 'Articles' on the Fly - User Directory
<txp:smd_bio_info author='<txp:adi_gps name="author" />' items="RealName" label="" />
and
RewriteRule ^directory/(.*)$ ?s=directory&author=$1 [NC]
are the magical nuggets!
Thanks!
txtstrap (Textpattern + Twitter Bootstrap + etc…)
Offline
Re: 'Articles' on the Fly - User Directory
So at the end of the day…
Make the links to author profiles
<ul>
<txp:smd_bio_info author="SMD_PRIVS:6" items="name" wraptag="li">
<a href="<txp:site_url />directory/<txp:smd_bio_info author="{smd_bio_info_item}" items="name" label="" />" title="probably yet another tag within tag within a tag within a tag"><txp:smd_bio_info author="{smd_bio_info_item}" items="RealName" label="" /></a>
</txp:smd_bio_info>
</ul>
Author profile display
Real Name: <txp:smd_bio_info author="<txp:adi_gps name="author" />" items="RealName" label="" /><br />
Username: <txp:smd_bio_info author="<txp:adi_gps name="author" />" items="name" label="" /><br />
User ID: <txp:smd_bio_info author="<txp:adi_gps name="author" />" items="user_id" label="" /><br />
etc...
- htaccess*
Addition of this line: RewriteRule ^directory/(.*)$ ?s=directory&author=$1 [NC]
#DirectoryIndex index.php index.html
#Options +FollowSymLinks
#Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^directory/(.*)$ ?s=directory&author=$1 [NC]
#RewriteBase /relative/web/path/
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
This all works beautifully! We’ll see how it holds up as the profile and other related markup gets more involved.
Would this be, in other’s opinions, a straightforward way of doing this whole thing?
I’ve not used variable from the URL before and feel hesitant to rely on something I’m not familiar with. In my travels around googling related approaches I have however found it to be a common type of procedure.
Last edited by whaleen (2009-09-17 01:13:23)
txtstrap (Textpattern + Twitter Bootstrap + etc…)
Offline
Re: 'Articles' on the Fly - User Directory
whaleen wrote:
I’ve not used variable from the URL before and feel hesitant to rely on something I’m not familiar with. In my travels around googling related approaches I have however found it to be a common type of procedure.
From security perspective, as long as you keep sure that the values are escaped, you’re fine. Using GETs to fetch data is the standard way. To improve it a little, you could add there a feature that kills the page (Read: shows a 404 msg) if there isn’t author with requests.
For example something like:
<txp:variable name="AreYouThere" value='<txp:smd_bio_info author='<txp:adi_gps name="author" />' items="user_id" label="" />' />
<txp:if_variable name="AreYouThere" value="">
<!--
Where are you, my Alice? Where did you go... *SadFace*.
Oh well, let's kill the relationshippage of ours:
-->
<txp:txp_die status="404" msg="I've never been here." />
</txp:if_variable>
whaleen wrote:
Would this be, in other’s opinions, a straightforward way of doing this whole thing?
If it doesn’t need manual touch, then definitely yes.
Offline