Introducing Flexifilter

Today, the initial version of Flexifilter for Drupal 6.x was released. "What is this flexifilter?" you might ask. And the answer: Flexifilter is an awesome new module that's going to totally revolutionize the way filters are done in Drupal. It's going to become (almost) as important as CCK and Views for a site builder. Flexifilter was initially created by Corsix as a part of GHOP 2007-08.

What it is

Flexifilter allows you to define custom filters entirely through the user interface. You name a filter, you can create it. A filter to append a "back to top" link if the text is longer than 1000 characters? No problem. A filter to change links in the form of [[link|title]] into links in the form of <a href="link">title<a>? Downright easy. And, if you ever want to change the format from [[link|title]] to {{link:title}}, there will be no delving into php code necessary: just change your settings on the admin page.

Over the next few months, we will see all filter modules gradually either disappear to be replaced by flexifilter or self-modify to work under the flexifilter framework. Why is it better to work under the flexifilter framework? Because then the admin has complete control over WHEN this filter applies, IF it is applied, and HOW this filter applies. Yes, flexifilter has the ability to set up advanced workflows through the user interface: you can have "if" statements and "while" statements; you can have "and" groups, "or" groups, and "not" groups.

How to use it

Using flexifilter is simple, as it is designed to provide an intuitive administration page and work entirely through the user interface. Here's a brief overview of what some of the terminology we use means:

  • A flexifilter is a custom filter created by the admin through the flexifilter module.
  • A component is the basic building block of a flexifilter. Components are the things that do the actual text manipulation.
  • A condition is something that can be evaluated and returns either TRUE or FALSE. Conditions are used, for example, in "if" statements and "while" loops to determine if certain components are run.

If you find flexifilter difficult to use, please submit a support request at the issue queue.

How to code for it

Flexifilter is designed to be easily extendable. Modules can define their own components and conditions through two hooks: hook_flexifilter_components and hook_flexifilter_conditions. Here, you define the callbacks the components and conditions, respectively. Then, all you have to do is write a very simple function, and you're done. For an example of how this is done, either look in flexifilter.components.inc and flexifilter.conditions.inc for the default components and conditions, or look at the Flexifilter Cite module, which serves as an example of a module that works under the flexifilter framework.

So, module writers, start converting your modules to flexifilter! Unless, of course, you'd rather have your users be unable to use your module to it's full potential. And have your module sit in the corner sulking because none of the other modules want to talk to it because your module doesn't play nicely with all the other modules, which have all accepted flexifilter while your module falls behind, clinging to an outdated and dead API. Do you really want that to happen? Of course not! So begin porting your modules to flexifilter now!

The future of flexifilter

What's left to do? A lot. First of all, the administration pages will likely see some redesign in the next few months. Also, an import/export API is being worked on, so modules will soon be able to define default flexifilters (probably in the 6.x-1.1 version). In addition, I think a form validation step may be added soon; this is usefully, say, because while it makes sense for a while statement to abort after "50" loops, it doesn't make sense for a while statement to abort after "abc" loops. This will be an API change for the most part, not a user interface change. Right now, we're making the stupid assumption that the admin will not choose to enter "abc" for the maximum number of loops.

Other ideas for cool or awesome new features? Post a feature request at flexifilter's issue queue.

Note on youth rights because I just can't resist

Ok, so we all pretty much agree that this is an awesome module by now. There's no denying that.

Let's just point out that it was written by Corsix, a 16-year-old, mentored by dmitrig01, a 12-year-old, and now I (15 years old) co-maintain it with Corsix. We provide Drupal with the contributed modules that sustain it's growth, and yet you older members of the Drupal community continue to insist that it's a good thing to deny us the right to vote. Come on, people! Show some sense! If we can do this amazing stuff for Drupal, imagine the amazing stuff we can do for the world.

Comments

Hi, good job! you're so

Hi, good job! you're so young for writing such a module (and also so smart ;) ). congratulation :)

Related work

That reminds me of the Universal Link Filter project which was done as Summer of Code '07 project. It might not be feasible to merge, but maybe you can join forces and/or take some ideas from there, as it would be cool to have One Filter Module To Rule Them All (TM).

Nice direction though, I like it :)

sounds cool. Is it different

sounds cool. Is it different then than custom filter module? - http://drupal.org/project/customfilter

Very different

Flexifilter provides a framework for creating filters, based around generic components and conditions. The flexifilter core knows nothing about any components or conditions, all of the default ones (if & while loops included) are implemented through the hooks, and other modules are free to add their own components and conditions as well.
Customfilter on the other hand can create filters which are defined using regular expressions. It presents a tool for creating filters, whereas flexifilter is a toolbox (with some built-in tools in it).

A couple thoughts

Ok, so we all pretty much agree that this is an awesome module by now. There's no denying that.

Since you are a developer of this module I'd say this line surpasses confidence and is a little cocky. [[cwgordon7's note: Maybe just a little ;) ]]

"The superior man is modest in his speech, but exceeds in his actions."
- Confucius (551 BC - 479 BC)

If you are referring to voting rights in the drupal association, which is what I assume you are talking about though I might be wrong, you might want to consider the law here. Is this a matter of someones choice or legalities in Belgium, where the association legally exists?

...

Based on previous articles, I think he's referring to voting rights in general.

Quote

I really can't resist to sort of take a jab at the translation quality of the quote as well. The quote that the "superior man is modest in his speech, but exceeds in his actions" is from the Analects, XIV.29. The original Chinese is:
君子恥其言而過其行。
There are several ways to interpret this. The dominate interpretation is the one aforementioned, but there are also several others. One is to interpret it as:
"The superior man is ashamed of his speech; he exceeds in his actions."
Here 而 serves to create a parallel structure. "The Superior Man" is being ashamed because of merely talking about doing stuff, or, in other words, speech. Yet another way to interpret it is:
"The superior man is ashamed of his speech exceeding his actions."
Here, 其言而過其行 serves as an entire dependent clause. Note that in both cases "is ashamed of" is pretty much the same as "will be ashamed of" as Chinese has no clear indication of tense in verbs.
That's probably the flaw in translating foreign literature; when there are several interpretations, translators are often forced to pick one. I have no idea how 恥 was interpreted as "modest." Anyhow, the quote that the "superior man is modest in his speech, but exceeds in his actions" turned out to be the most popular translation. EOR. End of Rant.

On a sidenote, I'd like to point out that cwgordon7 is not the main developer of this module, Corsix is. cwgordon7 is the (very endorsing) maintainer, so (personally I think) Corsix would have more rights to brag about this module.

I think cwgordon7 deserves

I think cwgordon7 deserves some bragging rights about this module

Youth rights first, then a technical question

Agreed on youth rights, and I'm old now. I'd already posted a quotation from your previous call for youth rights to my highest profile blog (not saying much).

And while Belgian legal reasons may keep the future off of the Drupal Association formally, your input is certainly welcome on who should serve, and why: http://buytaert.net/applications/applications

You can have my vote this election cycle– I have convinced myself too many times that U.S. elections are far more spectacle than a route to change. So despite having given to Barack Obama a campaign donation in the Democratic primary for his first election to the Senate, now my money and energies will be going toward anything that can build true power for people on an equal basis. (Even if it's not immediately obvious.)

Now the technical question: what is the performance cost of this approach? Filter definitions are now saved in the database and are more complex, so I'm assuming there's some... but node content is filtered once and then cached... so all you have to do is not change your filters too often, and not define non-cacheable filters... well I guess that's the only question then, that cacheable filters are on by default.

Ok, never mind, carry on...

Awesome!

Awesome, I'm being quoted! I had no idea that people actually thought that the stuff I said in my blog was worth quoting! I feel honored. As a side note, I agree that the two-party system of America is not a real democracy. Also, I was more referring to the world than Drupal, but it's still nice to know that our opinions are appreciated in the Drupal world, even if the real world continues (stupidly) to ignore them.

As for the technical question, Corsix can probably answer it better than me, but I believe that the performance is not to harshly affected. There's a single call to the database to determine which flexifilter to use, and then another call to the database to determine the components / conditions of the flexifilter, and then all the function callbacks are stored in memory. It's a very hook_menu-ish hook in that the callbacks, the callback arguments, etc., are what's stored in the database— and hook_menu was designed to be as performance-unintensive as possible. Also, as you say, the filtered versions are cached, so the actual filtering only goes on during submission (when you update or create the node).

Excellent Module! Regarding

Excellent Module!

Regarding the awesome things you could do if you could vote in the real world... I am afraid not much, at least as long as there is an idot that votes the opposite. As Einstein said "Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." ;)

In the past, there were minimum literacy requirements to vote... but even if I am happy that this unfair practice has been cancelled (it was a strategy to leave out all the poors) I wish it could be re-introduced, now that we have compulsory schooling!

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

You must answer the above question correctly to be able to submit a comment. This measure is designed to protect this site against spambots, which seem able to circumvent even the toughest image captchas. Hint: try googling for the question answer if you really don't know it. The theory behind this is that if this website is running its own completely custom captcha, it will not be in anyone's economic advantage to rewrite their spam bot's code to handle this website's questions. Powered by CwgordonCaptcha.