Handy "edit this page" link when your logged in!

RolfP

Did you enable front end login?

If so, try to simply add "<?php print "Test"; ?> to prove if there is no error in your template anywhere else.

janjoensen

I have tried what Rolf is writhing in his post 29"; I have also installed his module frontedit.zip. But how and where, shell I but "<?php frontend_edit(); ?>", I have try to edit to template, and puts this string there. I have but this string in to "Resultater - Footer:" and to may font page edit. :?

DGEC

Try the snippet module up in post #29 - he wrote instructions in the other thread.

janjoensen

#35
Plc. HELP I can't not get it to work on may page, and do not find any descriptions how do it.
Sorry I am a beginner! :x :?

I have tried what Rolf is writhing in his post 29"; I have also installed his module frontedit.zip. But how and where, shell I but "<?php frontend_edit(); ?>", I have try to edit to template, and puts this string there. I have but this string in to "Resultater - Footer:" and to may font page edit.

mercator


This is great. At the moment, it "only" checks if the current user is an admin and them allows editing or not. Can't one change the code such as to check if the current user (or group the user is in) is allowed to edit and then show the icon as well?

THANKS
Mercator

nerjuz

#33
I think this will help to make first page editable
if (!isset($page_id)) $page_id = $wb->default_page_id;
<?php  
                
if (FRONTEND_LOGIN == 'enabled' AND is_numeric($wb->get_session('USER_ID')))
                    
// Get permissons
                    
$database = new database();
                    
/* Checking*/ if (!isset($page_id)) $page_id $wb->default_page_id;
                    
$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']; ?>" border="0" /></a><br>
               <?php ?>

DGEC

heilcal,

I'm not sure what you mean.  Are you saying you had trouble getting the default (home) page to display the edit icon?

Your code does have the correct code to find it, $wb->default_page_id;
What does it do differently?

heikal

#31
Hi there, I'm a newcomer in the scene.

I'm very pleased with WB and I have picked up the code snippets about the handy "edit this page" link of which I think it is a great idea.

When using the code in my template, I have had the same problem having the icon being displayed in the "home" condition (page_id = default).
To cope with this I have slightly changed the routine making it check if the group_id is greater than 1,  because the group_id of the top_level page is 1 in my case.
The routine now works perfect and I'm very happy with it. Thanks to all of you.
I hope that this subject was still an issue and that I could eventually help someone.

Good luck and best regards,
heikal


[gelöscht durch Administrator]

RolfP

#30
I found this code snippet pretty need. Took Panthers code and turned it into a snippet modul. Now I am able to use it in a few servers without much additional effort.
For code see
http://forum.websitebaker.org/index.php/topic,8167.0.html

Have fun

Rolf

marccouture

Thanks to all who worked on this, very handy indeed.  I'll echo others by saying it would be great if this were made available eventually as an installable module, but inserting the code into a template isn't too hard... for the time being.  :wink:
Marc C.

pcwacht

When using a code section the code will be run through the php interpreter with the function eval();

This is very differrent from using the same code from a module (snippet)

Look at the hello world snippet I once wrote
just replace the echo 'hello world';  with your code and rename the snippet might do just what you need.


Good luck,
John

Panther

Ok, I'm trying to get it so this can be done as a module, but I can't even get it to work as a function...

I put the following in a CODE section on a page...

function edit_this_page()
{
   if (is_numeric($wb->get_session('USER_ID')))
   {
       // Get permissons
       if ($page_id) { $this_page = $page_id; }
       else { $this_page = $wb->default_page_id; }
       $database = new database();
       $results = $database->query("SELECT * FROM ".TABLE_PREFIX."pages WHERE page_id = '$this_page'");
       $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)) )
       {
           echo '<a href="'.ADMIN_URL.'/pages/modify.php?page_id=';
           if ($page_id) { echo $page_id; }
           else { echo  $wb->default_page_id; }
           echo '" target="_blank"><img align="right" src="'.ADMIN_URL.'/images/modify_16.png" alt="'.$HEADING['MODIFY_PAGE'].' /></a>';
       }
   }     
}

edit_this_page();


and I get...
QuoteFatal error: Call to a member function get_session() on a non-object in /home/.elijah/mnpages/baker.mnpages.com/modules/code/view.php(30) : eval()'d code on line 3

Any suggestions?

Panther

There's a system variable for that.. try this..

<a href="<?php echo LOGIN_URL?>">member login</a>

I use this to display a link in my templates then is taken from the regular login box, it displays a preferences link, logout link and your name when logged in...

<?php
if(FRONTEND_LOGIN AND !$wb->is_authenticated()) {
?>

   <a href="<?php echo LOGIN_URL?>">member login</a>
   <!-- <a href="<?php echo SIGNUP_URL?>">register</a> -->
<?php
} elseif(FRONTEND_LOGIN AND $wb->is_authenticated()) {
?>

   <a href="<?php echo PREFERENCES_URL?>"><?php echo $MENU['PREFERENCES']; ?></a>
   <a href="<?php echo LOGOUT_URL?>"><?php echo $MENU['LOGOUT']; ?></a><br />
   Logged in as: <span class="caps"><?php echo $wb->get_display_name(); ?></span>
<?php ?>

DGEC

That's a good idea, that way you don't have to have a login page tempting people on every page.

Hmm....

I tried to make a "member tools" page that includes a link to the login page (used the id=#) but it gets a 404?  Odd. What's going on here...

pcwacht

If you don't have login enabled,
change this:
if (FRONTEND_LOGIN == 'enabled' AND is_numeric($wb->get_session('USER_ID'))) {
to:
if (is_numeric($wb->get_session('USER_ID'))) {

kickarse

Remember in order for this to work you must have Login enabled.

DGEC

Ha! Looks like we both had the same ideas.  :-)

I ran into issue making a snippet too and stopped work on it.

Guess this will work go enough though - THANKS!

Panther

Quote from: pcwacht 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

That did it.. there were actually a couple spots in the original snippet that did not have {}s

here's what I came up with and it seems to be working fine. This does NOT put the link to the admin home page like the original snippet, it puts an image link, right now on the right side (but that can be changed). I placed mine at the top of my content block, just before the page title so it puts the icon across from the title.

You can just as easily include this at the bottom of your content or elsewhere on your page.

I tried to package this as a snippet-module like the RandomImage one but doing so broke things, it did not like the session calls. I may try to fix that eventually... but for now, this checks the permissions for each page, and if someone is logged in, and has permission to edit that particular page, the link shows up. If they don't.. it doesn't show up.

<?php  
if (
FRONTEND_LOGIN == 'enabled' AND is_numeric($wb->get_session('USER_ID'))) {
// Get permissons
if ($page_id) { $this_page $page_id; }
else { $this_page $wb->default_page_id; }
$database = new database();
$results $database->query("SELECT * FROM ".TABLE_PREFIX."pages WHERE page_id = '$this_page'");
$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 ?>     
<?php ?>

pcwacht

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

Panther

ok, this works... mostly (I looked in the admin/pages/settings.php file to find where it checks permissions)

<?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.

Panther

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..


<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.


Mesum

Bible On Web - Read, Listen and Study Holy Bible Online

icouto

@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!

Mesum

When I add this code to theme, it won't show... Where else can I add it?
Bible On Web - Read, Listen and Study Holy Bible Online

icouto

Dustin, that is great!

I might include that in the upcoming Template Primer - a guide for WB Template Designers.