Frontend Editing for MovableType
The concept of “Frontend Editing” has been used in high-end CMS like
RedDot SmartEdit or
Typo3 for quite some time now. Its purpose is to edit content directly on the page or at least initiate the editing dialogue from a link close to the content. This article describes a solution for implementing “Frontend Editing” for MovableType.
Using frontend editing has several advantages. First you don’t have to work your way through the whole MT interface to correct the spelling error you just found somewhere in your archives or to delete the latest troll comments. A link that leads you to the appropriate dialogue could be right next to the content. Check out the screenshot from
Edda’s blog. Quite convenient. Second, these links are extremely useful if the blog will be used by authors you don’t want to confront with underlying concepts or who you don’t want to train in the usage of MT. This is often the case if you use MT to power non-blog websites. I would say that MT is comparably easy to use but that doesn’t save me from having to explain the interface over and over again to my users. With “Frontend Editing” they need much less training on the MT interface and can now intuitively edit their webpage with just one click.
The idea to do this with MT is not new. It is even partly built in already. If you use the search templates that come with MT you might have noticed the <MTEntryEditLink> Search Results Tag which creates a link to edit the entry represented by a search result. Also
Jay Allen mentioned in a comment on
Stopdesign that he is implementing links on his clients’ websites which make it possible to open corresponding edit dialogues directly onsite. I picked up his idea and converted it into a plugin.
Implementation
So, how does it work? The idea is to embed links in our templates that lead directly back to the appropriate edit dialogue. As we’ll see in the following showcase this is pretty easy to do and can even be done manually. As an example we’ll create an entry-sensitive link. The URL for the “Edit” page of an MT entry looks like this:
/mt/mt.cgi?__mode=view&_type=entry&id=630&blog_id=12
Now to add an “Edit Entry” link to each of our entries all we have to do is to replace the entry and blog ID with the appropriate values. This can be achieved by using the <MTEntryID> and <MTBlogID> template tags.
<MTEntries>
<MTEntryTitle>
<MTEntryBody>
<a href="<MTCGIPath>mt.cgi?__mode=view&_type=entry&id=<MTEntryID>&blog_id=<MTBlogID>">
Edit Entry
</a>
</MTEntries>
As you might already have noticed this link will be visible for everybody. This isn’t a critical problem because MT’s authentication mechanism is still protecting our content. If an unauthorised user tries to edit an entry all she’ll see is the login screen. But it is preferable to dynamically show or hide these links and make them only visible for “authenticated” users. This will prompt the usage of a server side scripting language though. Since a lot of people already use PHP to enhance their blogs with additional functionality I decided to use PHP for that purpose. We’ll set a cookie and use PHP to test whether the cookie is set or not.
The following code will only show the content between the two PHP statements if a cookie named admin is set:
<?php if (isset($_COOKIE["admin"])) {?>
<a href="<MTCGIPath>mt.cgi?__mode=view&_type=entry&id=<MTEntryID>&blog_id=<MTBlogID>">
Edit Entry
</a>
<?php } ?>
So in this example only users with the admin cookie will be able to see the “Edit Entry” link. To set and unset the Admin cookie we’ll use the following code:
<?php
# set admin cookie. It will last for 1 year
setcookie("admin", "admin", time()+31536000, "/");
# unset admin cookie
setcookie("admin", "admin", time()-3600, "/");
?>
If you don’t want to introduce your blog to PHP just to hide your AdminLinks you can try to camouflage them. To make the links less obvious you could for example put them on an inconspicuous design element, use just a dot as link caption or create an extra style which is different from your usual link style.
Update: I just found out that almost exactly the same approach was used by Breena in her tip about
Edit Link for Entries with PHP. Go figure…
AdminLinks Plugin
To present you with at least something new I will show you how to use the AdminLinks plugin for MT. It doesn’t do anything fancy you couldn’t do yourself if you followed the above example. But the plugin is easier to use and makes your templates more readable. The plugin provides you with two new template tags.
- <MTAdminLink>: Outputs a context sensitive link for direct manipulation of blog, entries or comments.
- <MTAdminOnly>: Container tag that hides its contents from not authenticated visitors using the method described above.
The usage of <MTAdminOnly> is straight forward. Everything you enclose within this container tag will be protected by the PHP statement posted above. It will only be displayed for users with set admin cookie.
To specify what kind of link <MTAdminLink> should create you have to provide a type attribute. The following values are possible:
- blogmenu: creates link to main page of blog
- newentry: creates link to new entry dialogue of blog
- editentry: creates link to edit entry dialogue of entry
- editcomment: creates link to edit comment dialogue of comment
- deletecomment: creates link to delete dialogue of comment
- rebuild: creates link to rebuild dialogue of blog
Here’s an example:
<MTAdminOnly> <a href="<MTAdminLink type="editentry">">Edit Entry</a> </MTAdminOnly>
In this example <MTAdminLink> creates a link to edit an entry. Since it is enclosed in <MTAdminOnly> tags the link is only visible for people with set admin cookie.
The enclosed
picture shows an example of a site that is using the AdminLinks plugin. The red circled parts of the site are AdminLinks which are not visible to the casual visitor.
I hope people will find this plugin useful. I sure did myself.
Ressources
- Download the
AdminLinks plugin v1.1 for MT.
For installation and usage instructions refer to the included readme file. - Find out more about
Movable Type
Trackbacks
TrackBack is a system for enabling "conversations between weblogs". The links listed below are links to posts in other weblogs that reference this article:
-
a dog named fish:
Dump your Brain!
-
MovableTape:
Frontend editing for MT: AdminLinks
-
ETC. Indulging my inner geek:
Front End Editing for Movable Type
-
Gwen Harlow resources:
Edit this entry with PHP
-
Almaren:
diter la vole vos pages avec Movable Type
-
distant, early morning: static:
Colophon
-
Sideblog:
http://www.mariwood.com/sideblog/previously/002720.html
-
LissaKay, Too:
Edit Entries and more!
-
EOUIA:
MT & ̾߱
-
MT Plugin Directory:
AdminLinks
-
pixelgraphix:
MTAdminLink fr Movable Type
-
Web Sites You Should Know:
AdminLinks Plugin
-
pUrEza :: For the inflexible life:
MT Plugin Ʈ ƴٴմϴ.
-
Regressing at its finest...:
http://regressing.net/archives/2004/Feb/12/.html
-
JayAllen - The Daily Journey:
Frontend Editing for MT
-
Funtime Franky :
MT Plugin Update
-
Remaindered links weblog:
http://www.sixdifferentways.com/remainder/006091.php
-
ollicle:
Hide frontend editing links with CSS
-
..geek..:
c.c.changes
-
lonita.links:
Frontend Editing for MovableType
-
Devlog:
Frontend editing and hiding Movable Type entries
-
SHINYA'S SCRIBBLES:
Fronted Editing for MT
-
[[ VG BOOKMARKS :: Links to Scripts, Tutorials and Stuff for MT ]] [[VG.net ]]:
Frontend Editing
-
Netdoc blog:
Frontend Editing
-
anil dash's daily links:
edit links on your MT posts
-
Tao of Dowingba:
Making life easy via PHP
-
Linkaggio: storie, attualita', tecnologia e tempo libero...:
Frontend Editing in MovableType
-
Linkaggio: storie, attualita', tecnologia e tempo libero...:
Frontend Editing in MovableType
-
Suckahs Daily Bookmarks:
Frontend Editing for MovableType
-
links:
http://www.lehopictures.com/links/archives/002342.php
-
anything but ordinary:
AdminLinks Plugin For MT
-
Convergence of Thought:
Links to Check Out
-
Barlavento:
Editando posts diretamente do weblog
-
PC Blog @ Noel Cafe:
Edit{^
-
PC Blog @ Noel Cafe:
Edit{^
-
nonAesthetic:
links for 2004-11-12
-
nonAesthetic:
links for 2004-11-12
-
caramel*vanilla:
adminlinksプラグインを導入
-
G̍˔\͂Ȃ:
̊Ǘj[Ă݂B
-
A tempo - Une:
Front-end editing
-
Orlando Vacation:
Orlando Vacation
-
Lasik:
Lasik
-
baccarat call:
baccarat call
-
Windmills Road:
Windmills Road
To manually trackback this article use the following URL:
http://www.brain-dump.com/trackback/1
Post A Comment
Please try and keep your comments on-topic, informative and polite. Flaming and trolling is discouraged and may be deleted. In fact, we reserve the right to edit or delete any post for any reason.
Comments
I just wanted to publicly announce that I really like this plugin. It saves me tons of clicks every time I want to delete yet another troll comment from my site...
Wanted to say thanks for this script, but to add that there is a problem with implementing it with some hosts, it appears! I could *not* get the on/off scripts to work anywhere in my account except the root folder. No matter what the permissions were for folder or files, I would get either file not founds or permissions denied errors. A tip from a http://www.Forum4Bloggers.com user fixed it though, although i don't know why. My host account, by default, has indexing turned off. When I enabled indexing (std. text) for the folder where I stored the two .php files, then they worked just fine. Weird, but true!
Thank you for your comment, Gary. I read the thread on http://forum4bloggers.com/viewtopic.php?t=125.
Well, this looks strange indeed. I have a slight suspicion why this doesn't work. I will look into it tonight.
You can try to replace the header redirection in the log(on|off) files to a static URL. Maybe getting your root directory dynamically somehow collides with the directory listing.
Great. Also thought about the possibility of adding a simple print echo (?) statement to each to show something like "AdminLinks are turned on." or equal. As is, nothing is returned, leaving the user to wonder if it worked! I put a dummy index page in the folder with the two scripts so I see that when the script completes, but would be nice to have the more positive feedback that it's now "on" or "off." This is probably really simple for codeheads, but alas, that's not me...
"You can try to replace the header redirection in the log(on|off) files to a static URL."
Just wanted to post that this tricked worked, and although I wasn't sure which static URL to use, I used the url to where these two script files are. Scripts ran fine without errors (and this was a new directory where I hadn't turned indexing on).
I investigated the problem Gary reported. The dynamic redirection in the logon/logoff scripts was causing problems in directories without a welcome file (e.g. index.html). I now replaced the redirection with a static message.
Great! I did put a dummy index.html page in the directories, though, and it still did not work. For me the static url and/or the index on/off fixed it.
On another note, if you're keeping a list of cool toys to add to this, how about a way to link to edit the template that created the page? I'm helping someone over at the MT support forum on this issue and think it would fit well with this plugin.
Gary,
I already thought about the template links. I even tried to implement it but I think it can't be done without hacking the MT sources. And that's something I don't want to have as a requirement for this simple plugin.
What you can do is to create the template links yourself. It should be quite easy if you follow the examples given in this article.
Thanks, Michael. I have worked the edit template links successfully inside the MTAdminOnly tags, and it works well. Was a bit tricky getting the link for my floating side bar as well as the contents template, but managed that as well. Could also have done a sql query to pick up the template_id, but couldn't figure out it would know what template it was. Anyway, manual worked fine. I posted a screen cap of what I ended up with at the thread link you noted above. Slick stuff!
I have it working except for one little thing: it is neglecting to put the slash in between the directory path and the mt.cgi script (which makes it a little less useful). You can surf over and see since I removed the code that hides the edit links. Is there something I am missing somewhere?
Michael,
I already got a complaint about that last week. Make sure the CGIPath variable in your mt.cfg file has a trailing slash.
See:
http://www.movabletype.org/docs/mtinstall.html#installation%20directories
Ahh, just the thing I was looking for. Thanks for creating this beauty. :) Got two questions tho. Would there be a way to just use the entry form in MT's main Edit or New Entry screens, that is without the main MT skin (buttons, searchbox and username) to edit an entry or post a new one? Any suggestions? Second: would it be possible to login as a special guest user, with special guest access (as defined in the main MT author/privileges settings).
Ton,
1. This isn't possible without hacking the MT templates but it's possible.
2. Sure, no problem. Just set up a special user and log in.
I can imagine what you want to do. Maybe setting up your own post entry form and using the XML-RPC API could do the trick without serious hacks. Jay Allen did something like that. See the links in the third paragraph of this article.
This is a great addition (I dropped it into my personal site immediately). I was wondering about a possible extension/feature request.
I have a client that schedules training courses. They desire a calendar of all of the courses scheduled in the upcoming year. I have used Brad Choate's Supplemental Calendar Tags (http://www.bradchoate.com/weblog/2003/01/27/calx) to generate the current month + the next 11 months. That part works great.
When I saw this plugin, I instantly thought of making the dates in the publicly viewable calendar clickable 'Add Course' links for that date. Can this be used to pass the date to MT in one operation?
Wouldn't it be easier to use the MT session instead of a seperate cookie? Or am I overlooking something?
I've noted a few issues using MTAdminLink. I love it to death though.
1) When I use this to delete a comment, I get a hash error on rebuilding. I can replicate this every time - let me know if you need the error.
2) When I use this to edit a comment and then save the post, i get an error 500.
I only think these are related to the plugin because they don't do that when I go through the normal steps of using the MT interface.
Maybe it's just me, though. =)
Thanks for making it available! It has saved me a TON of time.
Hey Lisa,
I already stumbled across that Hash error before. To be honest I don't know what MT complains about. I guess it's a bug in MT. The comment gets deleted fine, right?
I think the same error message appears if you delete a comment from within MT but you just can't see it because the window is closed immediately.
On my blog I constructed the delete comment link like this:
<a href="" onclick="javascript:window.open('<MTAdminLink type="deletecomment">', 'confirm_delete', 'width=370,height=150');">Delete</a>
This will open a popup (just like in MT) and redirect you to the edit entry dialog => no visible Hash error... ;)
I can't reproduce your second problem. Are you sure this is related to MTAdminLinks?
Rock on,
Michael
Geoff,
now that you mention it I can't remember why I chose to go with a custom cookie. I think it would in deed be possible to check for MT's cookie.
I can vaguely remember that there were problems when checking for MT cookies when you log in with different users or you host multiple blogs on one domain.
It should be easy enough to modify the plugin to check for another cookie. See "sub adminOnly" in AdminLinks.pl.
The second problem appears to have disappeared, it may have been an issue with my change in hosts...
I'll change it to that popup, that is *brilliant* thank you for posting it. =)
I'd love to see this use MT's cookies, tht would make it a lot more useful when on the road. But I'm not nearly clever enough to make the change so if anyone does and you release it with the plugin, I'll grab it then. It's a minor thing anyway, for me. =)
I installed the AdminLinks plugin, and added the MTAdminOnly tags around an "Edit Entry" link, just as the example shows. However, not realizing I needed to add the logon/logoff pages, I went ahead and rebuilt.. and yet it still shows the Edit Entry link on each entry, despite the fact that I haven't logged in. Others see it too.
Any ideas what I'm doing wrong, or how I can troubleshoot? I know nothing about PHP.
Jay, I checked out your blog and saw what the problem is. For the AdminOnly container to work your pages have to be parsed as PHP. Check out the source code. You will find PHP source code.
If your host supports PHP it might be enough to tell MT to use .php as ending instead of .html. You can change this setting in the weblog configuration screen.
Another option would be to disguise the admin links as a dot or a small icon or something.
Bingo! Thanks for answering so quickly - and for posting it to my blog as well. It makes sense, of course; how would Apache know to parse PHP if I don't give it the .php extension (or serve all HTML as PHP)? For now, I did the former.. problem solved.
I've been using a similar (non-plugin based) trick to give myself 'edit' links for quite some time now, first on my MovableType weblog, now on TypePad. With a little creative stylesheet work, the links aren't even visible to the great majority of visitors.
My writeup from Jan. 2003: http://www.michaelhanscom.com/eclecticism/2003/01/mt_easy_comment.html
We've really appreciated how Basecamp (a web-based project management system that we use - from the folks at 37signals) has "front-end" (or what we like to call "inline") editing of posts/messages and comments. Surely better than having to go to the "admin" section somewhere else. Makes everything speedier, more usable, and certainly more convenient.
Whoops... Used HTML for that Basecamp link and it died.
Should be: http://www.basecampHQ.com
Just a simple question - does this work with MT3.0D? It looks like a very handy feature but I just need to know if it works with the latest edition of Moveable Type.
Nope it doesn't, just tried it out and the link doesn't show, the cookie is there though !
The MTAdminOnly link shows up on my pages, but when I delete a comment I get:
MT::App::CMS=HASH(0x835d868) Use of uninitialized value in concatenation (.) or string at lib/MT/App/CMS.pm line 1263.
when I edit a comment I get:
MT::App::CMS=HASH(0x835d790) Use of uninitialized value in join or string at (eval 14) line 2.
What can I be doing wrong?
Nevermind, I used your popup solution #17, that did work
Thanks anyhow!
Lawrence
The Blog Father: I believe it does work on MT3, except the cookie is called 'mt_user' instead of 'admin'.
Wow. This is what I have been looking for for some time. I have a problem though. I have tried both solutions (manual and the plugin) with the same result. The first time that I use it it works fine but after that it sends me directly to the MT login screen. The blog that I use this on is a personal blog in a password protected folder. Would this somehow cause a problem with accessing whatever it needs to directly edit the entry?
Downloaded the AdminLinks plugin. One *small* problem: the php scripts have a malformed ending title tag. It says instead of . Otherwise, a great plugin. Thanks!
i can see all the links but the problem is when i click on them, it takes me to the login screen. only when i have previuosly logged in does it bring me straight to the targeted url. what should i do?
Hi, is that plugin MT3 friendly regarding to the cookie ?
Report :
- It's not clear in the readme that the php files must be browsed before.
">Nouvelle Entre
- This shows 2 similar links, how comes ?
<MTEntries last="0">
<a href="<MTAdminLink type="newentry">">Nouvelle Entre</a>
</MTEntries>
the code almost works in typepad. It looks like they changed something that messes it up.
It makes sense, of course; how would Apache know to parse PHP if I don't give it the .php extension (or serve all HTML as PHP)? You can use .htaccess file directives to parse without a .php extension like http://www.seekingo.com. Cheers!
To get apache to parse both .php and .html files inthe target dir put this in the dir's .htaccess (assuming overides are allowed):
AddType application/x-httpd-php .php .html
With the latest releases of MT (I'm using 3.14), there's a new feature that allows for dynamic PHP publishing. On static pages, the AdminLinks plugin is working as great as ever (I started using it with MT 2.x), but on dynamically created pages, I get this error and nothing else:
Smarty error: [in mt:34 line 33]: syntax error: unrecognized tag 'MTAdminLink' (Smarty_Compiler.class.php, line 556)
I'd like to continue using the plugin, it's been really useful, but I wanted to start using dynamic publishing too. They just don't seem to work together very well at the moment, or maybe it's just me. ;)
If a user somehow gets on the set cookies-page he still can see the adminlinks. Why isn't it possible to use the MT-security itself for this?
When I go to the MT-login page I'm logged in automatically. So a cookie is set? Why can't that cookie be reused? It it possible to set your cookie right after (the first)login in MT only so I know for sure that that cookie is set for an author?
NICE SITE... LOOK THIS...
Same issue as Comment #39. ???
If i change AdminScript name in mt.cfg, this plugin doesn't work any more because AdminScript name is directly written as mt.cgi in AdminLinks.pl.
I tried to use MTAdminOnly tag inside a dynamic archive and I got this error message:
Smarty error: [in mt:234 line 46]: syntax error: unrecognized tag 'MTAdminOnly' (Smarty_Compiler.class.php, line 580)
How can I modify the plugin in order to make it compatible with smarty tags?