PDA

View Full Version : Addon Fast edit button


eon
12-15-2005, 03:08 PM
In this (http://forum.pixelpost.org/showthread.php?t=2815) tread ttlive asked for an "edit this image"-link.

An "edit this" option directly from the Post would be wounderful.

In case I am loged-in in the Admin section and I surfe through my PP blog, than an "edit this" option would be amazing. The Login is saved anyway somewhere, because I don't have to use the PW if I reenter the Adminsection again on the e.g. next day.

In case if there are a lot of images are saved in the database, it is a long way to scroll via "Images/Older Images..." to edit an picture (Title, Category or description / text) that was published a long time ago.

I don't know whether this post ist correct in "Hacks and Modifications" or should have been published in Addon. If it should have been published in Addon, than I am sorry.

Is there a change to get an option like this, sometimes?

I have the same problem and I made a little addon for this called "Fastedit".
http://www.northing.nl/programs/fastedit.tar.gz
(I don't have zip, but you can open tar.gz with 7-zip (http://www.7-zip.org/))

<FAST_EDIT> is the tag to use in your template.

The cookie of pixelpost_admin is stored in /admin.
I can't reach this cookie out of index.php (any suggestions?)
So I moved the cookie to the root ("/").

Edit /admin/index.php
- row 126
if (setcookie("pixelpost_admin",$cfgrow_password,time() +60*60*60*60, "/"))
- row 135
setcookie("pixelpost_admin","nope",time() -60, "/");

This is the code of the addon:
if(!isset($_COOKIE['pixelpost_admin']) && $cfgrow['password'] != $_COOKIE['pixelpost_admin']) {
$tpl = str_replace("<FAST_EDIT>","",$tpl); //delete <FAST_EDIT> when there is no valid cookie
}else{
$fastedit = "<a href=\"/admin/index.php?view=images&id=$image_id\">Admin</a>";
$tpl = str_replace("<FAST_EDIT>",$fastedit,$tpl); //show link
}


Have much fun with the Addon!

Joe[y]
12-15-2005, 05:04 PM
what if pixelpost really is in the root - ie, what to put instead of /pixelpost/ ?

eon
12-15-2005, 05:41 PM
I use my server to test different PHP opensource Contentmanagement-systems. Every system use his own index.php ;).

When your pixelpost is on root it must be "/" instand of "/pixelpost/".

I will rebuild the addon for the normal user. Done

posefius
12-17-2005, 02:27 PM
This is an addon i always wanted, great!

Please can you explain me step by step what i need to do to use this addon. I put it in the addon directory and placed the tag <FAST_EDIT> in the image template but nothing happens. Do I also need to modify the index.php?

Please explain step-by-step, i'm not a PHP code writer.

eon
12-17-2005, 03:43 PM
This is an addon i always wanted, great!

Please can you explain me step by step what i need to do to use this addon. I put it in the addon directory and placed the tag <FAST_EDIT> in the image template but nothing happens. Do I also need to modify the index.php?

Please explain step-by-step, i'm not a PHP code writer.

You placed the tag <FAST_EDIT> in the image template. That's oke!
There is something more that you have to do.

Find in "/admin/index.php" this code. It starts at row 123.
if($_GET['x'] == "login") {
$cfgrow_password = $cfgrow['password'];
if(($cfgrow['admin'] == $_POST['user']) AND ($cfgrow_password == md5($_POST['password']))) {
// login is valid, set cookie
if (setcookie("pixelpost_admin",$cfgrow_password,time() +60*60*60*60))
header("Location:index.php");
unset($login);
} else { $loginmessage = "Username or Password Incorrect.<br />
<a href='#' onclick=\"flip('askforpass'); return false;\">Forgot password?</a><p />
"; }
} // if (login = yes) end

if($_GET['x'] == "logout") {
setcookie("pixelpost_admin","nope",time() -60);
header("Location:index.php");
}

This script controls the cookie that's tells the system if you logged in as an admin. Login and Logout. The cookie of login will be placed in the directory "/admin/". How that works I don't know. Take it as a fact.
BUT the addon is searching for a cookie in the directory "/", the root. So we have a problem. I thried to let the addon search in "/admin/" but that didn't work out.
My solution is this. Move the cookie to "/". That's what you have to do to use the addon.

Replace this script:
if (setcookie("pixelpost_admin",$cfgrow_password,time() +60*60*60*60))
for this:
if (setcookie("pixelpost_admin",$cfgrow_password,time() +60*60*60*60,"/"))

What does it mean?
Set a cookie with the name "pixelpost_admin" and it contains the password of the admin ($cfgrow_password). The cookie will be expired at "time" + 15 days (60sec * 60 * 60 * 60) and will be stored in "/".

And replace this script:
setcookie("pixelpost_admin","nope",time() -60);
for this:
setcookie("pixelpost_admin","nope",time() -60,"/");

What does it mean?
Set a cookie with the name "pixelpost_admin" and it contains the word "nope". The cookie will be expired at "time" - 60sec and wil be stored in "/". The cookie will be deleted because the time is in the history.


That's all folks! I have explained this little modification in the addon itself. But maybe I made the explination too short ;). Let me know if it's working or not.

tinyblob
12-17-2005, 04:11 PM
be aware that this addon is going to have to be re-written when 1.5 comes out ;)

eon
12-17-2005, 06:51 PM
Keeps me off the street :D

eon
12-18-2005, 07:23 PM
The addon Fastedit version 1 contains a bug.
This code:
if(!isset($_COOKIE['pixelpost_admin']) && $cfgrow['password'] != $_COOKIE['pixelpost_admin']) {
$tpl = str_replace("<FAST_EDIT>","",$tpl); //delete <FAST_EDIT> when there is no valid cookie
}else{
$fastedit = "<a href=\"/pixelpost/admin/index.php?view=images&id=$image_id\">Admin</a>";
$tpl = str_replace("<FAST_EDIT>",$fastedit,$tpl); //show link
}

?>
Must be this code:
if(!isset($_COOKIE['pixelpost_admin']) || $cfgrow['password'] != $_COOKIE['pixelpost_admin']) {
$tpl = str_replace("<FAST_EDIT>","",$tpl); //delete <FAST_EDIT> when there is no valid cookie
}else{
$fastedit = "<a href=\"/pixelpost/admin/index.php?view=images&id=$image_id\">Admin</a>";
$tpl = str_replace("<FAST_EDIT>",$fastedit,$tpl); //show link
}

?>
So "&&" must be "||".

Please replace the code or download the new version here (http://www.northing.nl/programs/fastedit.tar.gz) or here (http://www.pixelpost.org/v1/index.php?x=downloads&details=130).

There is also an Fastedit version for Pixelpost 1.5! You can download it here (http://www.northing.nl/programs/fastedit_1.5.tar.gz) or here (http://www.pixelpost.org/v1/index.php?x=downloads&details=133).

unseen
12-18-2005, 07:44 PM
awesome addon, eon. thanks!!

eon
12-18-2005, 08:10 PM
awesome addon, eon. thanks!!

No Problem, thank you!