Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2010-07-09 10:26:41

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,422
Website GitHub

smd_write_cats: create categories on the fly from the Write tab

In response to a request from wornout this tiny plugin simply allows you to type categories directly in a new box on the Write tab (beneath the existing category selects) to have them created and assigned to your article automatically when you save it.

Nothing more, nothing less.

Download it and report the usual goodness / badness / indifferenceness here.

Revision history
————————

All available versions and changes are listed here. Each entry indexes the relevant post(s) in the thread to learn about the features.

  • 06 Jul 10 | 0.10 | Initial release
  • 11 Jul 10 | 0.20 | Added parent-child assignment ; fixed ‘article’ type selection (thanks monkeyninja / Uli) ; made tests case insensitive to prevent duplicate cats being created ; prevented ‘root’ being added to category1/2 ; added edit class to input box and made sure only people who have category privs can create them (thanks Uli)

Last edited by Bloke (2010-07-11 13:04:45)


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

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#2 2010-07-09 12:41:17

monkeyninja
Plugin Author
From: Sheffield, UK
Registered: 2008-10-14
Posts: 239
Website

Re: smd_write_cats: create categories on the fly from the Write tab

I’ve been considering writing a plugin like this for a while now. Seems like I won’t have to. Thanks Stef.

Offline

#3 2010-07-09 12:51:11

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,422
Website GitHub

Re: smd_write_cats: create categories on the fly from the Write tab

monkeyninja wrote:

I’ve been considering writing a plugin like this for a while now. Seems like I won’t have to. Thanks Stef.

No worries. I wrote + documented it in under an hour so if you can think of any improvements or places it’ll fall over, please holler. I think I tested it with what I consider to be a fairly full set of inputs, but I may have missed something in my haste.

I did wonder if it could be enhanced so you could specify Muppets-->Kermit, Area-->Entertainment and it’d insert Kermit and Entertainment under the given parent nodes. Not sure how many people would use it.

If there’s a clamouring for this kind of thing (or someone comes up with a better syntax) I can add it fairly easily. I’ve done this in my dev copy of smd_tags so it’d be a fairly simple copy, paste ‘n’ tweak job.


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

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#4 2010-07-09 13:03:28

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,316

Re: smd_write_cats: create categories on the fly from the Write tab

, , as usual, some extra goodness Thanks, Stef!


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#5 2010-07-09 17:40:29

monkeyninja
Plugin Author
From: Sheffield, UK
Registered: 2008-10-14
Posts: 239
Website

Re: smd_write_cats: create categories on the fly from the Write tab

Bloke wrote:

I did wonder if it could be enhanced so you could specify Muppets-->Kermit, Area-->Entertainment and it’d insert Kermit and Entertainment under the given parent nodes. Not sure how many people would use it.

Perhaps a Muppets>Kermit format would be simpler and clearer? Certainly could see a use for it if people like using hierarchical category structures.

Offline

#6 2010-07-09 19:10:02

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,422
Website GitHub

Re: smd_write_cats: create categories on the fly from the Write tab

monkeyninja wrote:

Perhaps a Muppets>Kermit format would be simpler and clearer?

Yeah that’d be nice. I was just trying to choose a character sequence that wouldn’t be likely to appear in someone’s Category titles though. The single greater-than seems, to me, a little risky. I could always make it a preference I suppose.

EDIT: Uli has pointed out that the categories are created even if the person doesn’t have category creation privs. Naughty me. I’ll fix that asap.

Last edited by Bloke (2010-07-09 19:10:47)


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

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#7 2010-07-09 19:35:29

monkeyninja
Plugin Author
From: Sheffield, UK
Registered: 2008-10-14
Posts: 239
Website

Re: smd_write_cats: create categories on the fly from the Write tab

Bloke wrote:

Yeah that’d be nice. I was just trying to choose a character sequence that wouldn’t be likely to appear in someone’s Category titles though. The single greater-than seems, to me, a little risky. I could always make it a preference I suppose.

A preference would be great.

I’ve just given the plugin a try and come across something a little odd. It works great unless I try and add the category “Textpattern”! Tried a number of other category names and it created them, or added them, perfectly. Looking at your code I can’t see any obvious reason why I should not be able to add this category. Otherwise it’s looking good.

Offline

#8 2010-07-09 19:47:32

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,422
Website GitHub

Re: smd_write_cats: create categories on the fly from the Write tab

monkeyninja wrote:

A preference would be great.

Working on it. Might have to be a hidden pref ‘cos I can’t be arsed making an entire screen for this one little thing (btw, things are afoot to help plugin authors in this regard but I’ll reveal more as TXP 5 takes shape — it’s not a 4.3.0 thing).

I’ve just given the plugin a try and come across something a little odd. It works great unless I try and add the category “Textpattern”!

Totally bizarre. I’ll check that one out, thanks for the report.

I’ve just found another subtle bug that might affect you if you make multi-word categories; it won’t correctly check if the category exists. I’m fixing that now as part of the Parent->Child thing.


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

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#9 2010-07-09 19:50:05

monkeyninja
Plugin Author
From: Sheffield, UK
Registered: 2008-10-14
Posts: 239
Website

Re: smd_write_cats: create categories on the fly from the Write tab

Bloke wrote:

(btw, things are afoot to help plugin authors in this regard but I’ll reveal more as TXP 5 takes shape — it’s not a 4.3.0 thing).

You’ve got me intrigued now. Spoilers?

Offline

#10 2010-07-09 20:04:59

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,316

Re: smd_write_cats: create categories on the fly from the Write tab

monkeyninja wrote:

It works great unless I try and add the category “Textpattern”!

Seems like it has to do with the vanilla link-category “Textpattern”.

Stef, if you work on adding nested categories, separator prefs etc:
I’d prefer to write it Kermit-->Muppets, read: category Kermit goes into category Muppets.

Is it possible to have a separate pref for exchanging the order of mother and child categories fields?


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#11 2010-07-09 20:36:12

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,422
Website GitHub

Re: smd_write_cats: create categories on the fly from the Write tab

uli wrote:

Seems like it has to do with the vanilla link-category “Textpattern”.

/Stef slaps forehead.

I forgot to add the type to the category. What a doughnut! I swear I added that but must have deleted it by mistake as I messaed around with the code.

I’d prefer to write it Kermit-->Muppets, read: category Kermit goes into category Muppets.

Weirdo! :-p

I’ll see what I can do.

Last edited by Bloke (2010-07-09 20:36:55)


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

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#12 2010-07-10 07:44:36

monkeyninja
Plugin Author
From: Sheffield, UK
Registered: 2008-10-14
Posts: 239
Website

Re: smd_write_cats: create categories on the fly from the Write tab

uli wrote:

Stef, if you work on adding nested categories, separator prefs etc:
I’d prefer to write it Kermit-->Muppets, read: category Kermit goes into category Muppets.

Is it possible to have a separate pref for exchanging the order of mother and child categories fields?

Could have it work like Kermit<Muppets for child followed by parent or Muppets>Kermit for parent followed by child. This is kind of what I had in mind with my form of notation. I suspect it complicates things a bit with Stef’s move towards a preference though.

Offline

#13 2010-07-10 07:54:14

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,422
Website GitHub

Re: smd_write_cats: create categories on the fly from the Write tab

monkeyninja wrote:

could have it work like Kermit<Muppets for child followed by parent or Muppets>Kermit

Hadn’t thought of that but Uli seems to want the parent at the ‘point’ end of the greater-then/less-than symbol so neither of the above will satisfy him :-)

I’ve implemented a pref for choosing the parent-child delimiter and also a pref for the order of items (child_first: 1 or 0).

Just running it through some rigorous tests as I don’t want to be responsible for corrupting someone’s category tree. Will try and release it later today / tonight.


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

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#14 2010-07-11 12:58:06

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,422
Website GitHub

Re: smd_write_cats: create categories on the fly from the Write tab

After a slight delay, here’s v0.20. You should upgrade to this version immediately as v0.10 had some quirks that may cause problems in your category table (knew the plugin was too easy last time!)

Now:

  • Added parent->child creation
  • You can specify the parent-child delimiter via a hidden pref
  • You can switch the parent-child link order if you wish via a hidden pref
  • Only users with appropriate catgeory privs can add categories (thanks Uli)
  • Made internal tests case insensitive so you can’t create duplicates
  • Improved efficiency: fewer database calls and it’s still less than 100 lines of code
  • Prevented ‘root’ from being created/displayed
  • Set class of input box to Edit (thanks Uli)
  • Fixed stupid oversight with category types so they only consider articles (thanks monkeyninja/Uli)

Be aware that v0.10 will have erroneously created category names that are of mixed case. v0.20 forces lower case names (titles are unaffected). Now, when you type in ‘MY New CaTEGoRy’ the plugin uses that as your category title but ‘my-new-category’ as its name. I recommend you leave it this way and let the plugin assign lower case names on your behalf. It may be prudent to check your categories, especially those created by v0.10 and make them lower case.

Note that if you really want mixed case names you can use TXP’s interface to re-edit the names but I strongly advise against this: for starters you probably won’t be able to assign cats using this plugin because it won’t ‘find’ them. I consider the fact that categories can be altered to use mixed case a TXP bug, but I don’t know how everyone else feels about this or if there’s a good reason why it’s permitted.

Anyway, see how you get on with this version.


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

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#15 2010-07-18 12:33:28

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,316

Re: smd_write_cats: create categories on the fly from the Write tab

Stef, many thanks for implementing the parent child order thing, and sorry for not responding earlier. I’d hoped to find time for in detail testing, but still couldn’t do so.


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

Board footer

Powered by FluxBB