Textpattern Forum

You are not logged in. Register | Login | Help

#1 2012-06-17 02:18:07

argi
Plugin Author
Registered: 2012-06-17
Posts: 8
Website

arg_empty_canvas - Empty canvas

When starting to create a new Textpattern site, it is kind of tedious to remove the pages, forms, etc. from the default installation, if you don’t want to built upon the default theme. This arg_empty_canvas plugin will do this in one step and then install the ZURB Foundation framework instead. Finally, the arg_empty_canvas plugin deletes itself.

Version 0.2 of the plugin

How to use:

  1. Start with a fresh installation of the 4.x Textpattern branch. It may also work with Textpattern 4.4.1.
  2. Make the files and images directories writable.
  3. Install the arg_empty_canvas plugin.
  4. Make sure that you really want to turn this Textpattern site into an empty canvas.
  5. Activate the plugin.
  6. Navigate to a tab other than the plugin tab.
  7. Start composing.

It even works on the site that you have spent all your time on :), so be aware, you have been warned.

Versions:

0.1.0 Initial release.
0.1.1 Trying to consider Gocom’s remarks.
0.1.2 Values for predefined forms inserted.
0.2 ZURB Foundation 2.2 framework inserted

Last edited by argi (2012-07-01 21:03:03)

Offline

#2 2012-06-17 04:04:45

maruchan
Member
From: Ukiah, California
Registered: 2010-06-12
Posts: 562
Website

Re: arg_empty_canvas - Empty canvas

Cool. Is it similar to sed_cleaner at all?

Offline

#3 2012-06-17 05:40:52

Gocom
Developer
Registered: 2006-07-14
Posts: 4,476
Website

Re: arg_empty_canvas - Empty canvas

Cool. Nice to see new plugins. Unfortunately not all new things are all shiny. There are number of issues;

  • Doesn’t support prefixed tables. When Textpattern’s tables are set to use prefixes, the plugin errors out. Please see safe_pfx() function. If you want to do a specific task covered in the database library, I would use that specific function. If you want to delete rows, I would highly recommend using safe_delete() (which handles prefixes too).
  • The plugin’s code has needless function empty_canvas_now() which can also cause collisions. When you do define anything in global scope (functions, constants, variables or classes), they do need to be prefixed with your plugin author prefix to avoid said collisions. Please see Plugin Development Guidelines.
  • It removes essential items as hard-coded forms. Number of forms in addition of default are mandatory (hard-coded in source and expected to exist).
  • Tries to remove a plugin named “wld_empty_canvas”. This probably should be “arg_empty_canvas”.
  • When it comes to completely emptying tables, truncate statement maybe be more appropriate than delete.
  • Doesn’t reset site’s lastmod time which may cause pages come from client cache.
  • On existing sites, if default section is set to use any other page template (or style) than default, the public-side of the site stops working until default section’s preferences are updated.
  • The plugin’s type is set as 1, while the code is only ran at the admin-side. The plugin’s type could be changed to 3, admin-only.

argi wrote:

5. Navigate to a tab other than the plugin tab.

These steps could be slimmed down to activation or installation. The cleaning could be done automatically on activation (or installation even) by using plugin life-cycle callbacks.

maruchan wrote:

Cool. Is it similar to sed_cleaner at all?

Essentially yes. Both clean sites to blank state.

Last edited by Gocom (2012-06-17 05:54:16)


Rah-plugins | What? I’m a little confused… again :-) <txp:is_god />

Offline

#4 2012-06-17 13:15:47

argi
Plugin Author
Registered: 2012-06-17
Posts: 8
Website

Re: arg_empty_canvas - Empty canvas

Thanks, Gocom, for the very helpful advices. I’ve tried to consider all of them, but as you have noticed, I am new to PHP.

Actually, the version 0.1 was too radical, wiping out hard-coded forms. Version 0.1.2 keeps these forms, and presets them with some minimal code. Didn’t quite understand how to preset the default section, so the user has to create a new section, but probably the user would do so anyway.

Last edited by argi (2012-06-17 14:02:07)

Offline

#5 2012-06-17 21:32:07

Gocom
Developer
Registered: 2006-07-14
Posts: 4,476
Website

Re: arg_empty_canvas - Empty canvas

argi wrote:

Thanks, Gocom, for the very helpful advices. I’ve tried to consider all of them, but as you have noticed, I am new to PHP.

No problem. Taking look at your new additions and changes;

header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");

Is that for the caching remarks I made? Um, well that sends a HTTP header to the client, but it doesn’t reset Textpattern’s lastmod time which I was pointing at. Please see update_lastmod() function. I.e. replace that header thing with it.

safe_query("TRUNCATE ".PFX."textpattern");

Please see safe_pfx() function. Note that the prefix is user-definable.

The prefix and MySQL table names can contain special syntax characters as periods (.), slashes (\, /) or whitespace. If one of those valid bytes is present in the user-defined prefix, those queries will break or, in case of a dot, will delete content from entirely different database (if by change matching database exists).

To avoid that, use safe_pfx() which will take that into account. If you still insist using the constants, please wrap the table names in backticks (`). E.g. above would become;

safe_query('TRUNCATE '.safe_pfx('textpattern'));

safe_query("DELETE FROM ".PFX."txp_plugin WHERE name like 'arg_empty_canvas'"); […] safe_query("UPDATE ".PFX."txp_section SET page='default',css='default',is_default='1'");

Please, please, consider using the functions Textpattern includes instead of using safe_query where possible. For instance all the update and delete statements can be replaced with lines as following;

safe_delete(
	'txp_plugin',
	"name='arg_empty_canvas'"
);

safe_update(
	'txp_section',
	"page='default', css='default'",
	"name='default'"
);

Rah-plugins | What? I’m a little confused… again :-) <txp:is_god />

Offline

#6 2012-07-01 17:16:45

argi
Plugin Author
Registered: 2012-06-17
Posts: 8
Website

Re: arg_empty_canvas - Empty canvas

Thank you Yukka, I tried to follow all your advices and I have learned a lot about Textpattern.

It seemed to me that a bare metal setup is not such a good idea. This is why version 0.2 now comes with the ZURB Foundation 2.2 framework and installs it unmodified. Also, it turned out that the default Textpattern installation does not support Javascript out of the box. There is neither a javascript database table nor a js directory. Therefore, the arg_empty_canvas has to install the spf_js plugin for using the Foundation 2.2 javascripts.

If you want to replace the Foundation 2.2 framework with something else, it should be easy enough to use this plugin also. Just modify it to pull some other setup files.

Last edited by argi (2012-07-01 21:07:24)

Offline

Board footer

Powered by FluxBB