Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

LinkPreview plugin

(Page 1 of 2)
> >
Quote Reply
LinkPreview plugin
BTW- this is off topic but... have you found an easy way to preview links before they get submitted. I am guessing that with your work on the blogging plugin you have encountered this problem and found a way around it. Unsure

Last edited by:

yogi: Jul 16, 2005, 10:28 PM
Quote Reply
Re: [jgkiefer] Reviving Blogging plugin In reply to
I'll look into it. That's probably going to require a hook, which I'm not really familar with doing. A quick and dirty solution would be to embed the code directly in search.cgi. something like:

Code:
use strict;
use lib 'C:/Program Files/Apache Group/Apache2/cgi-bin/glinks/admin';
use Links qw/$PLG $IN/;
use Links::User::Search;

local $SIG{__DIE__} = \&Links::fatal;

Links::init('C:/Program Files/Apache Group/Apache2/cgi-bin/glinks/admin');
Links::init_user();

if ($IN->param("preview")) {
print $IN->header();
print Links::user_page ("add_preview", $IN);
}
else {
if ($PLG->dispatch('check_request', \&Links::check_request)) {
$PLG->dispatch('handle_search', \&Links::User::Search::handle);
}
}

Create a new template called 'add_preview.html'. Then add an extra submit button to add.html:
Code:
<input type="submit" name="preview=1" value="Preview">

Philip
------------------
Limecat is not pleased.
Quote Reply
Re: [fuzzy logic] Reviving Blogging plugin In reply to
The only problem with this is it will get over-ridden with auto-update. Maybe there is a a global for this?
Quote Reply
Re: [jgkiefer] Reviving Blogging plugin In reply to
I've attached a plugin that seems to do the job.

Note to moderator: please detach this discussion into it's own thread.

Philip
------------------
Limecat is not pleased.
Quote Reply
Preview plugin In reply to
Thanks Philip -
I have successfully installed the plugin but do not know how to implement it?
Quote Reply
Re: [jgkiefer] Preview plugin In reply to
After you install the plugin, you need to do a little template work since I did not include it with the plugin.

You need to add the following line to add.html:
Code:
<input type="SUBMIT" name="add=1&preview=1" value="Preview Link">

Then basicly make a copy of add_success.html and name it add_preview.html. add the form include if you want, so that users don't have to hit their history button to make changes.

That should be all you need to do.

Philip
------------------
Limecat is not pleased.
Quote Reply
Re: [fuzzy logic] Preview plugin In reply to
Thank you it works really well. I almost forgot about the modify page. Can this be used for that also?
Quote Reply
Re: [fuzzy logic] Preview plugin In reply to
In Reply To:
make a copy of add_success.html and name it add_preview.html. add the form include.
I added the form to the add preview page. The drop down categories are not being passed to this page creating the error "you did not choose a category" which takes you back to the add page. Unless you select add link instead of preview link the user becomes stuck in a page loop.
Quote Reply
Re: [jgkiefer] Preview plugin In reply to
Okay. To get around this, a PRE and POST hook are going to be needed instead of just a PRE, in order to have access those template tags. I'll post an updated version this evening.

Philip
------------------
Limecat is not pleased.
Quote Reply
Re: [jgkiefer] Preview plugin In reply to
Attached is an updated plugin. It now will add the drop down list to the form on the preview page. Just to note: 'Category_Name' is the selected categorys' full name, whereas 'Category' is the select list. Unfortunately, if you want any error checking done on the preview page, you need to add it in yourself because the whole routine must be bypassed to keep the link from actually being added. there are probably some missing tags as a result.

And yes, you can basicly do the same for the modify routines by using the 'modify_link' hook instead of 'add_link'.

Philip
------------------
Limecat is not pleased.
Quote Reply
Re: [fuzzy logic] Preview plugin In reply to
I am confused about how to modify the category code from the include form to work with the preview plugin?
Code:

<div class="row<%unless category_loop_selected%> required<%endunless%> clear">
<label for="CatLinks.CategoryID" class="name">Category:<%unless category_loop_selected%> <span>*</span><%endunless%></label>
<div class="value<%if category_loop_selected%> wrappedtext<%endif%>">
<%if category_loop_selected%>
<%if category_loop.length > 1%>
<ul><%loop category_loop%><li><%Full_Name%><input type="hidden" name="CatLinks.CategoryID" value="<%escape_html ID%>" /></li><%endloop%></ul>
<%else%>
<%loop category_loop%><%Full_Name%><input type="hidden" name="CatLinks.CategoryID" value="<%escape_html ID%>" /><%endloop%>
<%endif%>
<%else%>
<select id="CatLinks.CategoryID" name="CatLinks.CategoryID">
<%loop category_loop%>
<option value="<%escape_html ID%>"<%if selected%> selected="selected"<%endif%>><%'&nbsp;&nbsp;' x $CatDepth%><%Name%></option>
<%endloop%>
</select>
<%endif%>
</div>
</div>
Quote Reply
Re: [jgkiefer] Preview plugin In reply to
Ah... you seem to be using 3.x. I've been writing this code with 2.2.1. The select list is generated internally. The tag 'Category' contains the entire select list code.

Philip
------------------
Limecat is not pleased.
Quote Reply
Re: [jgkiefer] Preview plugin In reply to
Yes I am using v3.0.4

I figured it out.

I pasted the include form on to the add_preview.html page and replaced the following category code:
Code:
<div class="row<%unless category_loop_selected%> required<%endunless%> clear">
<label for="CatLinks.CategoryID" class="name">Category:<%unless category_loop_selected%> <span>*</span><%endunless%></label>
<div class="value<%if category_loop_selected%> wrappedtext<%endif%>">
<%if category_loop_selected%>
<%if category_loop.length > 1%>
<ul><%loop category_loop%><li><%Full_Name%><input type="hidden" name="CatLinks.CategoryID" value="<%escape_html ID%>" /></li><%endloop%></ul>
<%else%>
<%loop category_loop%><%Full_Name%><input type="hidden" name="CatLinks.CategoryID" value="<%escape_html ID%>" /><%endloop%>
<%endif%>
<%else%>
<select id="CatLinks.CategoryID" name="CatLinks.CategoryID">
<%loop category_loop%>
<option value="<%escape_html ID%>"<%if selected%> selected="selected"<%endif%>><%'&nbsp;&nbsp;' x $CatDepth%><%Name%></option>
<%endloop%>
</select>
<%endif%>
</div>
</div>

It gets replaced with:

Code:
<div class="row required clear">
<label class="name">Category: <span>*</span></label>
<div class="value wrappedtext">
<%~if Category_loop.length > 1%>
<ul><%loop Category_loop%><li><%loop_value%></li><%endloop%></ul>
<%~else%>
<%Category%>
<%~endif%>
</div>
</div>


Thank you very much Philip. This has been a plugin that has been needed for a very long time. You did it very easily and elegantly. Wink
Quote Reply
Re: [fuzzy logic] Preview plugin In reply to
I can't seem to get it to work with modify link at all.
Quote Reply
Re: [jgkiefer] Preview plugin In reply to
I'll look into it and see if I can expand the plugin to work with the user registration and link modification routines. I'm off from work Monday and Tuesday so I'll have time to piddle around.

If you want to give it another try, here's some general instructions:

1) uninstall the plugin
2) go to the plugin wizard, and select "LinkPreview" to edit.
3) Click past the first couple of pages until you get 'hooks' section
3) select 'modify_link', click 'use'. select 'PRE' from the other pull-down list.
4) change the bottom field to read 'Plugins::LinkPreview::pre_modify_link'.
5) click 'add hook'
6) repeat, except select 'POST', and subroutine name 'Plugins::LinkPreview::post_modify_link'
7) click through a few more screens, until you get to an option to overwrite/keep existing LinkPreview.pm. choose NOT to overwrite.
8) click through to the end of the wizard.
9) go to the plugin manager and click the edit link for LinkPreview.pm
10) create subroutines 'pre_modify_link' and 'post_modify_link' based on the existing subs.

You may need to manually grab the links data.

Philip
------------------
Limecat is not pleased.
Quote Reply
Re: [fuzzy logic] Preview plugin In reply to
Thanks, but I am already lost. Crazy I can wait till you can get around to it... think I would be better to have an expert do it.
Quote Reply
Re: [jgkiefer] Preview plugin In reply to
hehe... an expert I am not (yet). but I will say this: It is much easier for a complete novice to add functionality to Links SQL than it ever was in Links 2.0. In Links 2.0 you really needed to be a seasoned Perl programer to safely hack any snippet of code since there was no hook system (to overide functions) or plugin system (to automate installation of addons) or globals editor (to add smaller scale functions for templates).

Philip
------------------
Limecat is not pleased.
Quote Reply
Re: [fuzzy logic] Preview plugin In reply to
Anyone that takes the time to help others and the community is tops in my book. Also with all the effort you are putting into this plugin, the blogg plugin, I would say that you are well on your way to the expert level. Wink
Quote Reply
Re: [jgkiefer] Preview plugin In reply to
Dude, just realized something. No plugin is needed to actually do this. A global, however, is all you need to actually pull up the category name.

Just make sure the "preview" submit button does NOT include "add". ie:
Code:
<input type="submit" name="preview=1" value="Preview">

As long as "add=" isn't true, the script will just load the form again, but it will include any submited values.

Then you can create a global to get the category name:

Category_Full_Name
Code:
sub {
my $vars = shift;
my $cat = $DB->table("Category")->select("Full_Name", { ID => $vars->{'CatLinks.CategoryID'} })->fetchrow();
return $cat;
}

use it in your template like:

Code:
<%if preview%>
Please confirm the information below:<br>
<table border=0 cellpadding=3 cellspacing=0>
<tr><td>Title:</td><td><%Title%></td></tr>
<tr><td>URL:</td><td><%URL%></td></tr>
<tr><td>Category:</td><td><%Category_Full_Name%></td></tr>
<tr><td>Description:</td><td><%Description%></td></tr>
<tr><td>Contact Name:</td><td><%Contact_Name%></td></tr>
<tr><td>Contact Email:</td><td><%Contact_Email%></td></tr>
</table>
<%endif%>
<form action="<%db_cgi_url%>/add.cgi" enctype="multipart/form-data" method="POST">
<table border="0" cellspacing="0" cellpadding="0">
<%include include_form.html%>
<tr>
<td>&nbsp;</td>
<td>
<input type="SUBMIT" name="add" value="Add Link">
<input type="submit" name="preview=1" value="Preview Link">
</td>
</tr>
</table>
</form>

Philip
------------------
Limecat is not pleased.
Quote Reply
Re: [fuzzy logic] Preview plugin In reply to
I will give it a try. Since I am using v3 there is no HTML in the template but that shouldn't make a difference with the code. I will tweak it and post the results.
Thanks! Shocked
Quote Reply
Re: [fuzzy logic] Preview plugin In reply to
I'm afraid I don't follow you. Using the <input type="submit" name="preview=1" value="Preview Link"> on the modify.html page doesn't do anything. It still sends the data to the modify_success.html page without using modify_preview.html. Maybe I am doing something wrong? Could you walk me through the steps used to use the preview link plugin for the link modify pages? Unsure

Quote Reply
Re: [jgkiefer] Preview plugin In reply to
Hm... while the method I described earlier works for add.cgi, it won't work for exactly the same for modify.cgi. Regardless of whether or not the form is submitted for processing, it will replace any form input with the original values. Since you are using 3.x, You can get around that by using the hash style tags to get the value from the GT::CGI object.

For example, instead of "URL", use "IN.URL"

alternatively (or for people using 2.x) you can use a global:

form_input
Code:
sub {
my $field = shift;
return $IN->param($field);
}

which you can call as "form_input('URL')"

You also need to remove the line:

<input type="hidden" name="modify" value="1">

and change the submit button from "modify_submit" to "modify=1".

That SHOULD take care of everything except for the category field, which has me stumped. I may have to try doing the plugin again if I can't figure it out. I'm pulling my hair out on that one.

Philip
------------------
Limecat is not pleased.
Quote Reply
Re: [fuzzy logic] Preview plugin In reply to
This seems to address the form issue (although I haven't as yet tried it) But how would I call the modify.html to display the preview in modify_preview.html since the plugin calls link_preview.html. I will try to address the category display issue once the page calls and page displays are working smoothly. This is coming together slowly but surely.
Quote Reply
Re: [jgkiefer] Preview plugin In reply to
I believe I have figured out how to get this to work 100% without the use of the plugin I posted. It involves using a few globals and an array of set tags, and changing the include_form.html template a bit. Right now, I've got to get me some sleep -- need to be at work in the morning.

When I get back from work at 5 pm I'll test out my theory for the category menu and post the results.

(the preview system otherwise works fine. you just aren't understanding what needs to be done. I will post full instructions and example templates later.)

Philip
------------------
Limecat is not pleased.
Quote Reply
Re: [fuzzy logic] Preview plugin In reply to
In Reply To:
(the preview system otherwise works fine. you just aren't understanding what needs to be done. I will post full instructions and example templates later.) [/quote]
Great! - You are probably right...
I got the add link preview working perfectly.
It's the modify link preview that has my knickers in a twist. I just can't seem to get it right. Pirate
> >