Start
Help
Forum
Addons
Projects
Welcome,
Guest
. Please
login
or
register
.
August 20, 2008, 05:24:16 PM
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Search:
Advanced search
Website Baker 2.7.0 (stable) released!
For more information look
here
.
The announcement board can be found
here
.
60556
Posts in
9791
Topics by
5824
Members
Latest Member:
blubb
Website Baker Community Forum
English
Modules
Code Snippets
Handy "edit this page" link when your logged in!
Pages:
[
1
]
2
Author
Topic: Handy "edit this page" link when your logged in! (Read 9106 times)
englishdingbat
Pending Apprentice Baker
Offline
Posts: 42
Handy "edit this page" link when your logged in!
«
on:
January 25, 2006, 10:54:45 PM »
I wanted a way to quickly edit the page when I was on it, so i just added this simple bit of code in to my template. Place where ever it is convenient for you, but it only shows when you are logged in. You must have login enabled in prefs, but someone might be able to hack the code further???
Code:
<?php
if(
FRONTEND_LOGIN
==
'enabled'
AND
is_numeric
(
$wb
->
get_session
(
'USER_ID'
))) {
?>
<a href="
<?php
echo
ADMIN_URL
;
?>
/index.php">
<?php
echo
$TEXT
[
'ADMINISTRATION'
];
?>
</a><br />
<a href="http://[you-website.domain]/admin/pages/modify.php?page_id=
<?php
echo
$page_id
;
?>
">Edit Page</a>
<?php
}
?>
simple i know, but useful.
Pete
«
Last Edit: January 26, 2006, 05:58:45 PM by englishdingbat
»
Logged
pcwacht
Guest
Re: Handy "edit this page" link when your logged in!
«
Reply #1 on:
January 25, 2006, 11:10:52 PM »
Very good idea, 1 improvement though, the second url, doens't make use of the ADMIN_URL yet, change to:
Code:
<?php
if(
FRONTEND_LOGIN
==
'enabled'
AND
is_numeric
(
$wb
->
get_session
(
'USER_ID'
))) {
?>
<a href="
<?php
echo
ADMIN_URL
;
?>
/index.php">
<?php
echo
$TEXT
[
'ADMINISTRATION'
];
?>
</a><br />
<a href="
<?php
echo
ADMIN_URL
;
?>
/pages/modify.php?page_id=
<?php
echo
$page_id
;
?>
">Edit Page</a>
<?php
}
?>
I suggestion, maybe a check to see if the logged in user is admin or has the rights to edit the page??
John
Logged
baZzz
Pending Apprentice Baker
Offline
Posts: 49
Re: Handy "edit this page" link when your logged in!
«
Reply #2 on:
January 26, 2006, 07:01:07 PM »
Very handy indeed, good job!
A little improvement, in case you have a multilingual website, you might want to do this:
Code:
<?php
if(
FRONTEND_LOGIN
==
'enabled'
AND
is_numeric
(
$wb
->
get_session
(
'USER_ID'
)))
{
?>
<a href="
<?php
echo
ADMIN_URL
;
?>
/index.php">
<?php
echo
$TEXT
[
'ADMINISTRATION'
];
?>
</a><br />
<a href="
<?php
echo
ADMIN_URL
;
?>
/pages/modify.php?page_id=
<?php
echo
$page_id
;
?>
">
<?php
echo
$HEADING
[
'MODIFY_PAGE'
];
?>
</a>
<?php
}
?>
Logged
-= assumption is the mother of all f*ck ups / to assume makes an ass out of u and me =-
felix_se_cat
Pending Apprentice Baker
Offline
Posts: 45
Re: Handy "edit this page" link when your logged in!
«
Reply #3 on:
January 26, 2006, 07:01:36 PM »
check to see if logged in user is an admin could be done with:
if ($wb->get_session('GROUP_ID')==1)
(i did so and it works fine for me)
Logged
Vincent
Semi-Master Baker
Offline
Posts: 202
Re: Handy "edit this page" link when your logged in!
«
Reply #4 on:
September 04, 2006, 02:52:10 PM »
Very handy indeed!
I slightly refined it (open new window). Thanks.
Vincent
Code:
<?php
if(
FRONTEND_LOGIN
==
'enabled'
AND
is_numeric
(
$wb
->
get_session
(
'USER_ID'
)))
if (
$wb
->
get_session
(
'GROUP_ID'
)==
1
)
{
?>
<a href="
<?php
echo
ADMIN_URL
;
?>
/index.php"target="_blank">
<?php
echo
$TEXT
[
'ADMINISTRATION'
];
?>
</a><br />
<a href="
<?php
echo
ADMIN_URL
;
?>
/pages/modify.php?page_id=
<?php
echo
$page_id
;
?>
"target="_blank">
<?php
echo
$HEADING
[
'MODIFY_PAGE'
];
?>
</a>
«
Last Edit: February 09, 2007, 06:07:07 PM by vincent
»
Logged
marathoner
Master Baker
Offline
Posts: 383
Re: Handy "edit this page" link when your logged in!
«
Reply #5 on:
October 31, 2006, 11:23:51 PM »
This works great for me and saves time when tweaking pages.
However, I'm having a problem. This snippet works fine for every page except my 'home' page which happens to be $page_id=1. Has anyone else had a problem using this snippet with $page_id=1? If so, is there a solution?
Logged
dellington
Apprentice Baker
Offline
Posts: 63
Re: Handy "edit this page" link when your logged in!
«
Reply #6 on:
November 05, 2006, 06:47:32 PM »
I love this! This will be really great for some of the folks I build websites for. Thanks!!
Logged
DGEC
Master Baker
Offline
Posts: 382
Re: Handy "edit this page" link when your logged in!
«
Reply #7 on:
February 06, 2007, 10:40:43 PM »
I was trying to figure out why my implementation of this didn't work until I realized that I was on Home as well. I guess we'll just have to hardcode IF id="" then ID=1 or whatever your home page code is (mine is 3, must have deleted it twice I guess)
Vincent - good idea, but your code got cut off at the end.
So here's my combined solution!
Code:
<?php
if (
FRONTEND_LOGIN
==
'enabled'
AND
is_numeric
(
$wb
->
get_session
(
'USER_ID'
)))
if (
$wb
->
get_session
(
'GROUP_ID'
)==
1
)
{
?>
<a href="
<?php
echo
ADMIN_URL
;
?>
/index.php">
<?php
echo
$TEXT
[
'ADMINISTRATION'
];
?>
</a><br />
<a href="
<?php
echo
ADMIN_URL
;
?>
/pages/modify.php?page_id=
<?php
if (
$page_id
)
echo
$page_id
;
else
echo
"3"
;
?>
" target="_blank">
<?php
echo
$HEADING
[
'MODIFY_PAGE'
];
?>
</a>
<?php
}
?>
Logged
icouto
Junior Baker
Offline
Posts: 119
Re: Handy "edit this page" link when your logged in!
«
Reply #8 on:
March 18, 2007, 03:29:00 AM »
Wow! This hint is SOOO useful!
Is there a way to automatically find out what the id of the home page is without having to hard-code it? I ask because I can imagine some of my clients deleting the home page, making another one, and causing the link to fail.
Logged
DGEC
Master Baker
Offline
Posts: 382
Re: Handy "edit this page" link when your logged in!
«
Reply #9 on:
March 19, 2007, 08:26:10 PM »
You mean... like I did?
That's a good point. You might have to just tell them not to do that, I couldn't figure out another way to do it without mucking into the core further and I didn't have time to do that.
It would be best to integrate this function into the system, and have it as an option on Settings, like Log In and Search.
Actually another thing I've been wanting to try doing is a "view page as guest/member/non-admin" function. I remember seeing that on another CMS and thinking how useful that would be. They implemented it as a fixed administrator menu option. That method sounds like a lot of work for WB.
One quick mod might be to change the Edit Page link to a drop-down listbox with Edit as the first option, and "View as Guest,..." and then display the rest of the types in the Group database. The view link could pass a parameter and a refresh would then automatically bring back the edit/view menu, hopefully. Similar to the template preview function - it can work for one page view, but harder to make it sticky. If it was an available value like the test if you're signed in or not, then you could turn it on and off.
Logged
gavjof
Apprentice Baker
Offline
Posts: 89
Grammaton Cleric 1st Class
Re: Handy "edit this page" link when your logged in!
«
Reply #10 on:
April 20, 2007, 03:26:37 PM »
Thank for this 'handy' piece of code.
I'd used something similar in the past for jumping to the ADMIN_URL but the "edit this page" feature is really nice
Logged
vivitron
Pending Apprentice Baker
Offline
Posts: 5
Re: Handy "edit this page" link when your logged in!
«
Reply #11 on:
April 29, 2007, 06:19:12 AM »
Greetings,
I was using this and made a small modification that makes the link always for the default page when the id changes.
Code:
<?php
if (
FRONTEND_LOGIN
==
'enabled'
AND
is_numeric
(
$wb
->
get_session
(
'USER_ID'
)))
if (
$wb
->
get_session
(
'GROUP_ID'
)==
1
)
{
?>
<a href="
<?php
echo
ADMIN_URL
;
?>
/index.php">
<?php
echo
$TEXT
[
'ADMINISTRATION'
];
?>
</a><br />
<a href="
<?php
echo
ADMIN_URL
;
?>
/pages/modify.php?page_id=
<?php
if (
$page_id
)
echo
$page_id
;
else
echo
$wb
->
default_page_id
; ;
?>
" target="_blank">
<?php
echo
$HEADING
[
'MODIFY_PAGE'
];
?>
</a>
<?php
}
?>
Notice the use of $wb->default_page_id.
Hope this helps!
Sincerely,
Dustin Lambert
Logged
DGEC
Master Baker
Offline
Posts: 382
Re: Handy "edit this page" link when your logged in!
«
Reply #12 on:
April 30, 2007, 05:12:16 PM »
So that's how it's done.
Thanks for that info - good job, Dustin!
Logged
icouto
Junior Baker
Offline
Posts: 119
Re: Handy "edit this page" link when your logged in!
«
Reply #13 on:
May 01, 2007, 12:11:02 PM »
Dustin, that is great!
I might include that in the upcoming Template Primer - a guide for WB Template Designers.
Logged
Mesum
Pending Apprentice Baker
Offline
Posts: 19
I want to make history.
Re: Handy "edit this page" link when your logged in!
«
Reply #14 on:
May 13, 2007, 06:23:23 AM »
When I add this code to theme, it won't show... Where else can I add it?
Logged
Bible On Web - Read, Listen and Study Holy Bible Online
icouto
Junior Baker
Offline
Posts: 119
Re: Handy "edit this page" link when your logged in!
«
Reply #15 on:
May 13, 2007, 09:43:38 AM »
@Mesum: hmmm, hard to know what could be the cause. Here are a few suggestions for you to check and try out:
1) make sure that you are adding the code to the template's 'index.php' file of the template you are currently using in your site.
2) make sure that you are adding the code to a section/element in the BODY of the template, and that it is visible - and not somewhere that is a hidden part of the template's layout.
3) make sure you have 'Login enabled' in your Admin->Settings, and that you login!
Logged
Mesum
Pending Apprentice Baker
Offline
Posts: 19
I want to make history.
Re: Handy "edit this page" link when your logged in!
«
Reply #16 on:
May 13, 2007, 07:44:29 PM »
AHA! I didn't have 3 on
Thanks icouto.
Logged
Bible On Web - Read, Listen and Study Holy Bible Online
Panther
Senior Baker
Offline
Posts: 168
Re: Handy "edit this page" link when your logged in!
«
Reply #17 on:
June 14, 2007, 08:11:25 PM »
Right now, this only works if someone is an admin...
how could this be tweeked to check the admin_groups value in the pages table to see if a user has been enabled as an editor?
I have people who are editors of specific pages. I could hard code this something like...
if ($wb->get_session('GROUP_ID')==1) | ($wb->get_session('GROUP_ID')==3) {
But that only works if the group of editors is editors for every page...
ideally, doing a check of the DB would be slick so it checks and only shows up an edit option if you are authorized to edit that particular page.
Side note to this, I modified it a bit to show the "edit page" icon from the admin panel in the upper right corner of my content area when logged in..
Code:
<div id="content">
<?php
if (
FRONTEND_LOGIN
==
'enabled'
AND
is_numeric
(
$wb
->
get_session
(
'USER_ID'
)))
if (
$wb
->
get_session
(
'GROUP_ID'
)==
1
) {
?>
<a href="
<?php
echo
ADMIN_URL
;
?>
/pages/modify.php?page_id=
<?php
if (
$page_id
)
echo
$page_id
;
else
echo
$wb
->
default_page_id
; ;
?>
" target="_blank"><img align="right" src="
<?php
echo
ADMIN_URL ?>
/images/modify_16.png" alt="
<?php
echo
$HEADING
[
'MODIFY_PAGE'
];
?>
" /></a>
<?php
}
?>
<h2>
<?php
echo
MENU_TITLE
;
?>
</h2>
<?php page_content
();
?>
I placed it just inside my content div container, before any other headers or content.
Logged
Panther
Senior Baker
Offline
Posts: 168
Re: Handy "edit this page" link when your logged in!
«
Reply #18 on:
June 14, 2007, 08:43:14 PM »
ok, this works... mostly (I looked in the admin/pages/settings.php file to find where it checks permissions)
Code:
<?php
if (
FRONTEND_LOGIN
==
'enabled'
AND
is_numeric
(
$wb
->
get_session
(
'USER_ID'
)))
// Get permissons
$database
= new
database
();
$results
=
$database
->
query
(
"SELECT * FROM "
.
TABLE_PREFIX
.
"pages WHERE page_id = '$page_id'"
);
$results_array
=
$results
->
fetchRow
();
$old_admin_groups
=
explode
(
','
,
$results_array
[
'admin_groups'
]);
$old_admin_users
=
explode
(
','
,
$results_array
[
'admin_users'
]);
$this_user
=
$wb
->
get_session
(
'GROUP_ID'
);
if (
is_numeric
(
array_search
(
$this_user
,
$old_admin_groups
)) ) {
?>
<a href="
<?php
echo
ADMIN_URL
;
?>
/pages/modify.php?page_id=
<?php
if (
$page_id
)
echo
$page_id
;
else
echo
$wb
->
default_page_id
; ;
?>
" target="_blank"><img align="right" src="
<?php
echo
ADMIN_URL ?>
/images/modify_16.png" alt="
<?php
echo
$HEADING
[
'MODIFY_PAGE'
];
?>
" /></a>
<?php
}
?>
But, the icon shows up on any page that doesn't have a specific $page_id, like the default page... even when I'm logged out.. and I'm not sure why.
Logged
pcwacht
Guest
Re: Handy "edit this page" link when your logged in!
«
Reply #19 on:
June 14, 2007, 09:14:19 PM »
Check the use of { and } for the nested if's
I don't see a { at the first if and think you need an extra ending } at the last php bit.
Good luck
John
Logged
Pages:
[
1
]
2
Jump to:
Please select a destination:
-----------------------------
General
-----------------------------
=> Announcements
===> Security Announcements
=> Guest Area and Off-Topic
=> Website Showcase
-----------------------------
English
-----------------------------
=> Help/Support
===> Help/Support of WB2.7.x core
=> Website Baker Development
===> Website Baker 3
=> Documentation
=> Templates
=> Modules
===> Code Snippets
=> Languages
=> Archive
-----------------------------
Deutsch (German)
-----------------------------
=> Ankündigungen
=> Hilfe/Support
===> Templates, Module & Co.
===> Hilfe/Support von WB2.7.x core
=> Diskussion über WB
=> Off-Topic
=> Archiv
-----------------------------
Nederlands (Dutch)
-----------------------------
=> Aankondigingen
=> Help / Support
===> WB Core
===> Templates, Modules & Languages
=> WB Discussie
=> Niet-Terzake (Off Topic)
-----------------------------
French
-----------------------------
=> Help/Support
-----------------------------
Italian
-----------------------------
=> Help/Support
Loading...