Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2004-08-06 03:16:02

spchampion
Archived Plugin Author
Registered: 2004-06-10
Posts: 62

[plugin] [ORPHAN] spc_section_alias - Section renaming and management plugin.

I’ve written a plugin that allows for better management of sections and section names. As we all know, Textpattern lacks a human readable section naming scheme as well as the ability to associate meta information such as descriptions, link titles, and ids with a section. This plugin rectifies this in a somewhat kludgy but functional fashion.

At heart, my plugin is essentially a hash table written in PHP to handle section names. It does not actually store anything in a database; instead it requires that the section information be loaded on each page refresh (most likely out of a form).

Downloadspc_section_alias.txt

Version – 0.5, posted on October 25, 2004

Changelog:
  • 0.1 – Initial release
  • 0.2 – Minor bug fix
  • 0.3
    • Added article form tags for all of the functions rather than just the link function.
    • Added wraptag and break attributes to the iterate function.
  • 0.4
    • Changed the behavior of spc_section_alias so that if you do not specify a section, it will redefine the values for the current section.
    • Added new value to spc_section_alias called inactive. If inactive is set to “1”, the iterate function will ignore this entry. This does not affect any other functions.
    • Added new special values for spc_section_alias. Each element that spc_section_alias can define now has a corresponding ‘this’ function that redefines the stored value, replacing any occurrence of the phrase .this. with the value already stored. For example, if name is defined as “Section”, then calling spc_section_alias namethis=”-> .this.” will redefine name to be “-> Section”. If no prior value is defined, the ‘this’ functions simply store the specified value.
    • Added a new function called spc_section_alias_copy. This takes an optional section value (it uses the current section if none is specified) and takes a list of source groups and destination groups. The function will take the first section it encounters in the list of source groups and copy its contents into the first destination group it encounters with a matching section name. If it doesn’t find a destination group, it will copy the data into a new group.
    • Changed the behavior of group= in each of the read functions so that it now accepts a comma (“,”) delimited list of groups rather than just one. If more than one section matches in the list of groups, the first match is the one chosen.
    • Added a new field to spc_section_alias called ‘breakid’. At this point, this tag accepts one value that will appear as an id= in the break tag when calling spc_section_alias_iterate with break=‘li’. At the moment, it does not support any other break type. There are no read functions for this field in this version.
  • 0.4.1
    • Allowed spc_section_alias (the actual function) to take comma delimited groups. If no section is found in the list of groups, then spc_section_alias chooses the first group listed.
  • 0.4.2
    • Fixed a problem with group lists in spc_section_alias_link and _article_link.
  • 0.5
    • Added support for accesskey in links.

Homepagehere

Functions:
  • spc_section_alias – Defines the information associated with a section.
    • section – The section to which you are associating new information. If you do not specify a section, this will modify the data associated with the current section.
    • group – This value will allow you to group certain sections together for better handling with the iterate function (see below). If no group is specified, then the group value is set to “default”. This may be a comma delimited list. If no matching section is found in the comma delimited list of groups, then a new entry will be created in the first group listed.
    • name – A human readable name for your section.
    • title – A title value for links.
    • id – An id value for links.
    • accesskey – An accesskey value for links.
    • description – A description of your section.
    • description2 – A second description for your section.
    • breakid – A value that will appear as id= in the break tag when calling spc_section_alias_iterate with break=‘li’. At the moment, it does not support any other break type.
    • inactive – Setting this value to “1” will will make the iterate function ignore this entry. This does not affect any other function.
    • namethis, titlethis, idthis, accesskeythis, descriptionthis, description2this, breakidthis – Use these to redefine existing values. They take any occurrence of “.this.” in the supplied input, and replace it with the already stored value. If there are no existing values to redefine, the ‘this’ functions will store new values.
  • spc_section_alias_copy – Copies the section contents from one group to another.
    • section – A section to copy. If none is specified, the current section is used.
    • srcgroup – A comma delimited list of groups to search for section information. This function takes the information from the first group found.
    • destgroup – A comma delimited list of groups. If the function finds a matching section in this group list, it will copy the section information to this group. If it does not find a matching section, it will create a new group using the first entry from the comma delimited list.
  • spc_section_alias_section – Given a section, this returns the section. This is useful when combined with other plugins that demand a section variable.
    • section – Return information from this particular section. If no section is specified, the current section is used.
    • group – The section group. If no group is specified, the group value is set to “default”. This value will accept a comma delimited list.
  • spc_section_alias_article_section – (Article form tag) Same as above, but this is meant to be used within an article form.
    • group – The section group. If no group is specified, the group value is set to “default”. This value will accept a comma delimited list.
  • spc_section_alias_name – Return the human readable name for a section.
    • section – Return information from this particular section. If no section is specified, the current section is used.
    • group – The section group. If no group is specified, the group value is set to “default”. This value will accept a comma delimited list.
  • spc_section_alias_article_name – (Article form tag) Same as above, but this is meant to be used within an article form.
    • group – The section group. If no group is specified, the group value is set to “default”. This value will accept a comma delimited list.
  • spc_section_alias_title – Return the link title for a section.
    • section – Return information from this particular section. If no section is specified, the current section is used.
    • group – The section group. If no group is specified, the group value is set to “default”. This value will accept a comma delimited list.
  • spc_section_alias_article_title – (Article form tag) Same as above, but this is meant to be used within an article form.
    • group – The section group. If no group is specified, the group value is set to “default”. This value will accept a comma delimited list.
  • spc_section_alias_id – Return the link id for a section.
    • section – Return information from this particular section. If no section is specified, the current section is used.
    • group – The section group. If no group is specified, the group value is set to “default”. This value will accept a comma delimited list.
  • spc_section_alias_article_id – (Article form tag) Same as above, but this is meant to be used within an article form.
    • group – The section group.This value will accept a comma delimited list. If no group is specified, the group value is set to “default”.
  • spc_section_alias_description – Return the description for a section.
    • section – Return information from this particular section. If no section is specified, the current section is used.
    • group – The section group. If no group is specified, the group value is set to “default”. This value will accept a comma delimited list.
  • spc_section_alias_article_description – (Article form tag) Same as above, but this is meant to be used within an article form.
    • group – The section group. If no group is specified, the group value is set to “default”. This value will accept a comma delimited list.
  • spc_section_alias_description2 – Return the second description for a section.
    • section – Return information from this particular section. If no section is specified, the current section is used.
    • group – The section group. If no group is specified, the group value is set to “default”. This value will accept a comma delimited list.
  • spc_section_alias_article_description2 – (Article form tag) Same as above, but this is meant to be used within an article form.
    • group – The section group. If no group is specified, the group value is set to “default”. This value will accept a comma delimited list.
  • spc_section_alias_link – Return a working link for a particular section that includes title, id, and human readable name.
    • section – Return information from this particular section. If no section is specified, the current section is used.
    • group – The section group. If no group is specified, the group value is set to “default”. This value will accept a comma delimited list.
  • spc_section_alias_article_link – (Article form tag) Same as above, but this is meant to be used within an article form.
    • group – The section group. If no group is specified, the group value is set to “default”. This value will accept a comma delimited list.
  • spc_section_alias_iterate – This tag takes a form and a group, and then iterates over all of the sections listed within that group using the form as input. The form tags are the same tags as listed above. This is useful as a means of outputting a list of sections, section links, etc.
    • form – The form over which to iterate.
    • group – The section group. If no group is specified, the group value is set to “default”. This value will accept a comma delimited list.
    • wraptag – A wraptag to put around the output.
    • break – A break tag to put around the elements.

Ok, let me take a moment to describe how to use this plugin. To start with, make a list of all your sections. On my site (http://www.stantonchampion.com), I have several sections that I use, including “articles” and “sitenews”. I want to have a human readable name for each of these along with a description and some other cool stuff. I start by creating a form (I call it section_prefix) that looks like this:
<code>
<txp:spc_section_alias section=“articles” title=“General Stuff” name=“Articles”
description=“Home of general stuff I write, reviews, news, rants, and raves. If
I wrote about something, it’s probably hiding in here.” />
<txp:spc_section_alias section=“sitenews” title=“Stuff about this site” name=“Site News”
description=“Articles about changes to the site go here. Read all there is to know about
how this place has changed over time.” />
</code>

At the top of each page where I reference anything related to sections (pretty much all of them), I add:
<code><txp:output_form form=“section_prefix” /></code>

Now I modify my articles form to say that a given post is in a section: <code><txp:spc_section_alias_article_link /></code>

I want my articles page to say “Articles” at the top and I want my sitenews page to say “Site News” at the top. I modify my page template and add: <code><txp:spc_section_alias_name /></code>

I also want a description for each of these sections. I can add a description with: <code><txp:spc_section_alias_description /></code>

Next, I want an unorganized list of all my sections. To do this, I create a form called section_list that says:
<code>
<txp:spc_section_alias_link />
</code>

To activate this, I call:
<code>
<txp:spc_section_alias_iterate form=“section_list” wraptag=“ul” break=“li” />
</code>

Lastly, I want a detailed section/description/category/date archive thing, like my page here. This page is a combination of my plugin along with akw_month_list and asy_category_list. I’ll need the iterate function above (without the wraptag and break values), but I’ll change my form to:

<code>
<p><strong><txp:spc_section_alias_link /></strong><br />
<txp:spc_section_alias_description />
<br />
By Date: <txp:akw_month_list break=”, “ section=”<txp:spc_section_alias_section />” /><br />
By Category: <txp:asy_category_list break=”, “ section=”<txp:spc_section_alias_section />” />
</p>
</code>

Finally, I added the optional “group” field that lets you group different types of sections. If your site is big enough that you have more than one type of section list, then use the group value to keep them straight. If you don’t specify a group, then it uses the group “default”.

Poke around on my site. Any place where I reference a section, including the navbar at the top, uses this plugin now.

Quick note #1 – You can link back to the Home section by adding a link to section=“default”.

Quick note #2 – Starting with version 0.4, you can redefine section alias entries on a per section basis. Use the copy, alias, and iterate functions together to do things like add bold tags around the section you’re presently viewing. For example, let’s say you’ve got a bunch of sections, you’re iterating them, and you want bold tags to appear around the section you are presently viewing (let’s say it’s named articles). Let’s also say that articles is in group ‘2’, but it could also be in ‘1’ or ‘3’. Do the following:

Copy the current values for articles somewhere else (note that this only copies the current section):
<code>
<txp:spc_section_alias_copy srcgroup=“1,2,3” destgroup=“temp” />
</code>

Change the existing value using the new ‘this’ values (see above):
<code>
<txp:spc_section_alias namethis=”<b>.this.</b>” group=“1,2,3” />
</code>

Do your iterate:
<code>
<txp:spc_section_alias_iterate wraptag=“ul” break=“li” group=“1,2,3” />
</code>

Then, change the value back to the way it was:
<code>
<txp:spc_section_alias_copy srcgroup=“temp” destgroup=“1,2,3” />
</code>

Last edited by spchampion (2005-08-27 17:09:05)

Offline

#2 2004-08-06 03:26:39

zem
Developer Emeritus
From: Melbourne, Australia
Registered: 2004-04-08
Posts: 2,579

Re: [plugin] [ORPHAN] spc_section_alias - Section renaming and management plugin.

Lovely. And excellent timing, too – I was about to sit down and write something to do the same job.

A plea to the gods of textpattern: any chance we could have section and category titles stored in the database in a forthcoming version?


Alex

Offline

#3 2004-08-23 20:56:09

nednieuws
Member
From: The Home of Heineken
Registered: 2004-08-21
Posts: 14

Re: [plugin] [ORPHAN] spc_section_alias - Section renaming and management plugin.

In form section_alias I have:

<code><txp:spc_section_alias section=“about” name=“About” title=“About La Haya” description=“Lorem ipsum.”
/>
<txp:spc_section_alias section=“casestudies” name=“Case Studies” title=“Case Studies” description=“Lorem ipsum.”
/></code>

In form excerpt I have:
<code><txp:output_form form=“section_alias” />
<h2><span><txp:spc_section_alias_name /></span></h2>
<h3><txp:permlink><txp:title /></txp:permlink></h3>
<p><txp:excerpt /></p></code>

In page default I have:
<code><txp:article_custom limit=“1” section=“website” excerpted=“y” listform=“excerpt”
/></code>

The output of <code><txp:spc_section_alias_name /></code> is empty, so I end up with headings like:
<code><h2><span></span></h2></code>

What am I doing wrong? The plug-in is enabled and it tells me it’s version 0.2.

Last edited by nednieuws (2004-08-23 20:57:41)


Regards, Charles.

Offline

#4 2004-08-23 22:20:07

spchampion
Archived Plugin Author
Registered: 2004-06-10
Posts: 62

Re: [plugin] [ORPHAN] spc_section_alias - Section renaming and management plugin.

I think the problem is that I only created one article form tag for this plugin. Just for the heck of it, try doing spc_section_alias_article_link instead.

Let me know if that works. If so, I’ll add some more article form tags.

Offline

#5 2004-08-24 00:17:18

nednieuws
Member
From: The Home of Heineken
Registered: 2004-08-21
Posts: 14

Re: [plugin] [ORPHAN] spc_section_alias - Section renaming and management plugin.

That works. But I’d really like to only have the title, description (not tried) and so on available as well (as per your docs).

Nice to see that I’m not the only one missing that functionality, though, and even better, people coming up with solutions :).


Regards, Charles.

Offline

#6 2004-08-24 01:03:55

spchampion
Archived Plugin Author
Registered: 2004-06-10
Posts: 62

Re: [plugin] [ORPHAN] spc_section_alias - Section renaming and management plugin.

Excellent. I’ll whip up some more functions and upload a new version shortly. Just a side note, there are two types of functions in this plugin. Most of the functions are meant to be embedded in page templates and used to provide a means of modifying a page’s layout.
On the other hand, Textpattern has a little different means of dealing with functions that are used in article forms (and only article forms—not any other types of forms). These need to look for slightly different information in order to operate, thus requiring slightly different functions.

I’ll write the new functions the same way I’ve written the link function where there are two versions: spc_section_alias_link (the page template version) and spc_section_alias_article_link (the article form version).

I’ll post again once I’m done.

Last edited by spchampion (2004-08-24 01:19:27)

Offline

#7 2004-08-24 06:59:45

spchampion
Archived Plugin Author
Registered: 2004-06-10
Posts: 62

Re: [plugin] [ORPHAN] spc_section_alias - Section renaming and management plugin.

I’ve posted an updated version. This one has article form tags for all of the major output functions that are indicated by the word “article” in the function name. Make sure you use the article functions in article forms and the rest of the functions in page templates.

Also, I’ve added wraptag and break capability to the iterate function. It all seems to work for me, but I would certainly appreciate knowing if anyone finds anything wrong. Let me know if it all works!

Offline

#8 2004-08-24 14:02:06

nednieuws
Member
From: The Home of Heineken
Registered: 2004-08-21
Posts: 14

Re: [plugin] [ORPHAN] spc_section_alias - Section renaming and management plugin.

spchampion: Perfect.


Regards, Charles.

Offline

#9 2004-09-29 16:41:08

Andrew
Plugin Author
Registered: 2004-02-23
Posts: 730

Re: [plugin] [ORPHAN] spc_section_alias - Section renaming and management plugin.

If I’m grouping my sections, but still want to be able to output all sections in one list (without having to output several tags – each w/ a different group id) … how to do that? As of now,

<pre><txp:spc_section_alias_iterate form=“section_list” wraptag=“ul” break=“li” /> </pre>

Will output only items that are not grouped. But if grouped, I’d have to use two separate <code><ul>‘s</code>. There needs to be a way to be able to request multiple groups, like:

<pre><txp:spc_section_alias_iterate form=“section_list” wraptag=“ul” break=“li” group=“1,2,3” /></pre>

Offline

#10 2004-09-29 17:53:41

spchampion
Archived Plugin Author
Registered: 2004-06-10
Posts: 62

Re: [plugin] [ORPHAN] spc_section_alias - Section renaming and management plugin.

Ooooh…good idea. I’ll see what I can do.

Offline

#11 2004-09-29 18:00:30

spchampion
Archived Plugin Author
Registered: 2004-06-10
Posts: 62

Re: [plugin] [ORPHAN] spc_section_alias - Section renaming and management plugin.

compooter,

Do keep in mind that you can fake the behavior you want by doing:

<code>
<ul>
<txp:spc_section_alias_iterate form=“section_list” break=“li” group=“1” />
<txp:spc_section_alias_iterate form=“section_list” break=“li” group=“2” />
<txp:spc_section_alias_iterate form=“section_list” break=“li” group=“3” />
</ul>
</code>

Last edited by spchampion (2005-08-25 14:41:29)

Offline

#12 2004-09-29 18:17:24

Andrew
Plugin Author
Registered: 2004-02-23
Posts: 730

Re: [plugin] [ORPHAN] spc_section_alias - Section renaming and management plugin.

Aha – hadn’t thought of that. Thx.

Offline

Board footer

Powered by FluxBB