2 of 4
2
NEW - Redirect Plugin…
Posted: 28 March 2008 03:26 PM   [ Ignore ]   [ # 19 ]  
Summer Student
Total Posts:  16
Joined  04-15-2006

Mark:

I’m attempting to build a simple search that would accomplish the following:

Keyword is not found - send to “keyword not found” page.

Keyword is found - redirect browser to the value stored in the “keyword_url” field.

I can get the search to return the “keyword_url” value with no problems… all by itself by using this code:

{exp:search:search_results}{keyword_url}{/exp:search:search_results}

And, I can get your plugin to work just fine placing a simple URL into it -

{exp:redirect_to location="www.yahoo.com"}

However, if I attempt to combine the two by placing the keyword_url inside the plugin I get an invalid URL:

{exp:redirect_to location="{exp:search:search_results}{keyword_url}{/exp:search:search_results}"}

The Invalid URL is:

http://www.panhandleparade.com/index.php/keywords/results/f4c187fcd506cbc4692df65e5bbe434a/{exp:search:search_results}{keyword_url}{/exp:search:search_results}

I’m guessing the EE code to extract the “keyword_url” value is not working inside the plugin code…

The simple search page is here:  http://www.panhandleparade.com/index.php/keywords/simple_search/

The single good keyword in the system at this time is “bagpipes” and the keyword_url is http://www.bagpipes.com

(I’m not into bagpipes, it’s just what I chose to test with)

Any thoughts?

 Signature 

Gene Hilsheimer
wmbb.com
Panama City, FL

Profile
 
 
Posted: 29 March 2008 03:21 PM   [ Ignore ]   [ # 20 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  6552
Joined  04-15-2006

Hiya,

Sorry I am probably being dense here but where exactly is this {keyword_url} you are talking about coming from. I don’t see it listed in the documentation for search results?

Best wishes,

Mark

 Signature 

Full List Of Plugins Here!! (16)
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

Profile
 
 
Posted: 31 March 2008 05:09 AM   [ Ignore ]   [ # 21 ]  
Summer Student
Total Posts:  16
Joined  04-15-2006

Sorry Mark… the “keyword_url” is just the name of the field I made for the weblog I made whose name is “keywords”. 

Basically - I have a weblog named “keywords”.

In that weblog, I have two fields, the default (title) field and a field I generated for this weblog called “keyword_url”.

I can get a Simple Search form to search for a keyword - looking in the title fields of the keyword weblog. 

If the Simple Search does not the find word that was searched for, it will send me to the “Not Found” page…. but if it does find the keyword I submitted in the title field of any of the entries in my keyword weblog, it will display the information in the “keyword_url” field of that “found” entry in the results page.

I can get the simple search to “find” my bagpipes entry… and I can get it to then display the information in the “keyword_url” field… but what I’d like it to do is - instead of display the url in the keyword_url field - I’d like it to redirect the browser to that URL.

gh

 Signature 

Gene Hilsheimer
wmbb.com
Panama City, FL

Profile
 
 
Posted: 31 March 2008 05:23 AM   [ Ignore ]   [ # 22 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  6552
Joined  04-15-2006

Hiya,

Ah I see what you are trying to do now! Is this for some sort of link directory or something?

I don’t think that the plugin I have made is going to work for this. I did try using it within {if} statements myself the once but it just went with whatever was in the first {if} statement regardless of the outcome. I don’t really have enough knowledge of the system to put together a plugin of that nature I’m afraid and what I have put together is quite simple in that respect.

Do you have to have the person automatically re-directed to the page stored in {keyword_url}? I only ask as I know that a lot of people on the net don’t like to be automatically taken away from a site without being told about it first, but I guess that’s another thing to look at.

Sorry I can’t be of more help but I don’t think that in this instance the plugin is going to do what you need it to. I would love to be proven wrong by one of the learned people in here who know much more about the plugin development side of things than me though so please please please developers bring on the ideas grin

Once again sorry I couldn’t be of more help on this for you.

Hope you get something sorted out though for this.

Best wishes,

Mark

 Signature 

Full List Of Plugins Here!! (16)
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

Profile
 
 
Posted: 31 March 2008 02:47 PM   [ Ignore ]   [ # 23 ]  
Summer Student
Total Posts:  16
Joined  04-15-2006

No sweat, Mark… I sure do appreciate your look-see on this one.

I am looking for a direct “redirect” on our keyword search.  I work for a TV station and they are big into keywords.

We’ve been sold and I’m building out a prototype site that we can move to for all our stuff… and the keyword is one thing in the mix that I’ve gotta figure out.

If I can’t figure it out - a direct redirect - I’ll figure out the next best thing.

Again… thanks for your efforts here.

gh

 Signature 

Gene Hilsheimer
wmbb.com
Panama City, FL

Profile
 
 
Posted: 31 March 2008 02:52 PM   [ Ignore ]   [ # 24 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  6552
Joined  04-15-2006

Hiya,

Sorry that I couldn’t be of more help on this one. Perhaps you could ask one of the EE development team in here to take a look at my plugin? Well actually don’t bother as they could probably write one up in about half a second but you have my permission to gladly get in touch with them and ask questions about how to extend this plugin to do what you need. I’m sure they could be of help on this one but it is just a little too deep into code for me I’m afraid.

Do keep me in on the loop if you do come up with anything on this plugin as would love to see anything that gets modified.

Hope you get it all sorted soon.

Best wishes,

Mark

 Signature 

Full List Of Plugins Here!! (16)
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

Profile
 
 
Posted: 31 March 2008 03:28 PM   [ Ignore ]   [ # 25 ]  
Summer Student
Total Posts:  16
Joined  04-15-2006

I ended up setting up a simple script that finally worked:

<sKript>
windoZe.location="{exp:search:search_results}{keyword_url}{/exp:search:search_results}";
</
sKript>

Now, if you put “bagpipes” in the Simple Search - you will be redirected to bagpipes.com right away…  This should hold the big guys off for a while…

 Signature 

Gene Hilsheimer
wmbb.com
Panama City, FL

Profile
 
 
Posted: 31 March 2008 03:53 PM   [ Ignore ]   [ # 26 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  6552
Joined  04-15-2006

Excellent news!

Glad you got it all sorted.

Best wishes,

Mark

 Signature 

Full List Of Plugins Here!! (16)
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

Profile
 
 
Posted: 15 May 2008 04:06 AM   [ Ignore ]   [ # 27 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  881
Joined  02-15-2008

I’m trying this:

{exp:weblog:entries weblog="casestudy" disable="member_data|trackbacks" limit="8" orderby="title" sort="asc" paginate="bottom"}
    {if total_results
== 1}
        {exp
:redirect_to location="http://example.com/casestudy/{categories show_group="4"}{category_url_title}{/categories}/{url_title}/"}
    {
/if}
{
/exp:weblog:entries}

And Firefox is telling me:

Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

Any idea what could be happening here?

//EDIT - hold fire, just spotted the quotes around 4…

 Signature 

Andy Harris | Pepper Digital | Malvern, UK | Twitter | New to ExpressionEngine? Start here!
Remember - If at first you don’t succeed, you’re not Chuck Norris

Profile
 
 
Posted: 15 May 2008 04:23 AM   [ Ignore ]   [ # 28 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  881
Joined  02-15-2008

No, I just can’t get this to work at all…don’t suppose anyone has any suggestions, I basically need to redirect (including a category name) if there’s only one result present.

 Signature 

Andy Harris | Pepper Digital | Malvern, UK | Twitter | New to ExpressionEngine? Start here!
Remember - If at first you don’t succeed, you’re not Chuck Norris

Profile
 
 
Posted: 15 May 2008 09:29 AM   [ Ignore ]   [ # 29 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  228
Joined  11-16-2004

Andy - This might help you. We were having trouble with the redirect plugin also so we ended up using some javascript. This paticular bit of code checks to see if a logged in person is of a certian member group, and then checks to see if the {segment_3} variable is equal to a custom_profile field called {pebble_group}.

Anyway, is seems pretty fullproof even though it is deeply nested, which is I think why the Redirect Pluggin is not working.

{if member_group != "1"}

  {exp
:member:custom_profile_data}

     {if {pebble_group}
!="{segment_3}"}
     
     [removed]
.href="http://www.domain.org/pebblegroup/";
     
{/if}

  {
/exp:member:custom_profile_data}

{
/if}

 Signature 

T. Payton
OneCreative | Albuquerque, NM

Profile
 
 
Posted: 20 May 2008 02:38 AM   [ Ignore ]   [ # 30 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  881
Joined  02-15-2008

Thanks for that. I had to go with javascript also as I couldn’t get a PHP redirect to work due to not being able to put it in the header. I find it amazing that something as simple as this isn’t straightforward in PHP!

 Signature 

Andy Harris | Pepper Digital | Malvern, UK | Twitter | New to ExpressionEngine? Start here!
Remember - If at first you don’t succeed, you’re not Chuck Norris

Profile
 
 
Posted: 20 May 2008 02:44 AM   [ Ignore ]   [ # 31 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  285
Joined  02-02-2007

Hi Mark,

In ExpressionEngine it is usual to provide only url segments as tag parameter, as here

{path=site/contacts}

In contrast, using Redirect To plugin full url must be provided as “location” parameter.

It seems to me that it would be handy to allow both full url (for redirection to pages located in external sites) and url segments (for redirection to pages located within site).

I think it would be nice if this functionality would be incorporated into new version of Redirect To plugin.

To achieve this is really easy. The PHP function which is wrapped in Redirect To plugin should check if full url is provided and if it is, redirect to location, if not, create url from segments and then redirect.

Here you can see how modified function might look like

function Redirect_to() {
       
        
global $TMPL, $FNS;
        
        
// Fetch our parameters from the plugin tag
        
$location = str_replace("&#47;", "/" ,$TMPL->fetch_param('location'));
    
//check if full url is provided as location parameter
        
if (strpos($location, 'http') === 0 OR strpos($location, 'http') > 0)
        
{
        
//if full url is provided, redirect
      
$FNS->redirect($location);
    
}
    
else
    
{
    
//if only segments of url are provided, create full url and redirect
      
$location = $FNS->create_url($location);
      
$FNS->redirect($location);
    
}
    }

 Signature 

Full list of plugins here

Child Categories
Browser Sniff
Category Id
Entries List

Profile
 
 
Posted: 20 May 2008 03:11 AM   [ Ignore ]   [ # 32 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  6552
Joined  04-15-2006
Laisvunas - 20 May 2008 02:44 AM

Hi Mark,

In ExpressionEngine it is usual to provide only url segments as tag parameter, as here

{path=site/contacts}

In contrast, using Redirect To plugin full url must be provided as “location” parameter.

It seems to me that it would be handy to allow both full url (for redirection to pages located in external sites) and url segments (for redirection to pages located within site).

I think it would be nice if this functionality would be incorporated into new version of Redirect To plugin.

To achieve this is really easy. The PHP function which is wrapped in Redirect To plugin should check if full url is provided and if it is, redirect to location, if not, create url from segments and then redirect.

Here you can see how modified function might look like

function Redirect_to() {
       
        
global $TMPL, $FNS;
        
        
// Fetch our parameters from the plugin tag
        
$location = str_replace("&#47;", "/" ,$TMPL->fetch_param('location'));
    
//check if full url is provided as location parameter
        
if (strpos($location, 'http') === 0 OR strpos($location, 'http') > 0)
        
{
        
//if full url is provided, redirect
      
$FNS->redirect($location);
    
}
    
else
    
{
    
//if only segments of url are provided, create full url and redirect
      
$location = $FNS->create_url($location);
      
$FNS->redirect($location);
    
}
    }


There’s always someone who wants to spoil my fun wink

Only kidding. I totally hear what you are saying there and I should have done that at the beginning but wasn’t really too sure of how to use all the functions available to me at the time and still messing around with them nowadays!!

Will give the code you have provided a real good looking over and add it in as soon as I can. Thanks for the help on that one.

Best wishes,

Mark

 Signature 

Full List Of Plugins Here!! (16)
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

Profile
 
 
Posted: 20 May 2008 03:29 AM   [ Ignore ]   [ # 33 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  6552
Joined  04-15-2006

Just to let everyone know that the plugin has now been updated to V1.1 thanks to the excellent pointer by Laisvunas above. Thanks for that mate! wink grin wink

I have placed credit in the plugin to yourself too. If you want a web-address or anything else in there instead then just let me know and I will add that in as soon as possible.

New plugin version can be found in the first post on the first page of this forum thread.

Best wishes,

Mark

 Signature 

Full List Of Plugins Here!! (16)
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

Profile
 
 
Posted: 21 May 2008 06:59 AM   [ Ignore ]   [ # 34 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  285
Joined  02-02-2007

Hi Mark,

I see a problem with Redirect To plugin v.1.1:

There are situations when you can test condition, but cannot perform or cannot perform correctly PHP redirection on condition tested.

One example is advanced conditionals as here:

{if segment_3 == "some_string" }
Some code
{if
:else}
{exp
:redirect_to location="my_template_group/my_template"}
{
/if}

This code will redirect regardless condition is true or not.

Another example is conditionals within ExpressionEngine tags as here:

{exp:weblog:entries weblog="my_weblog" category="5"}
{if total_results
== 1}
{exp
:redirect_to location="my_template_group/my_template"}
{
/if}
{
/exp:weblog:entries}

or as here:

{exp:weblog:entries weblog="my_weblog" url_title="my_title"}
{if certain_field
== ""}
{exp
:redirect_to location="my_template_group/my_template"}
{
/if}
{
/exp:weblog:entries}

These two pieces of code will produce PHP error.

In this thread some people reported that because of the problems with PHP redirects they were forced to switch to Javascript redirects. It seems to me that it is best to use PHP redirects wherever possible and only if it is not possible to use javascript redirects.

With minimal changes Redirect To plugin can perform both PHP and javascript redirects. To enable javascript redirects a new parameter - “method” should be added. Then if “method” parameter is set to “script”, a javascript redirect will be performed, if “method” parameter is not set, then PHP redirect will be performed.

Having possibility to perform both PHP and javascript redirects you can easily everywhere perform redirects using Redirect To plugin: in cases PHP redirect does not work or you are not sure will it work or not, then you can simply set “method” parameter to “script” and you are done.

Here you can see how modified Redirect_to function might look like

function Redirect_to() {
           
        
global $TMPL, $FNS;
        
        
// Fetch our parameters from the plugin tag
        
$location = str_replace("&#47;", "/" ,$TMPL->fetch_param('location'));
        
$method = $TMPL->fetch_param('method');
            
// Perform a check to see if a full url is not given in the location parameter
            
if (strpos($location, 'http') !== 0 AND !(strpos($location, 'http') > 0))
            
{
                
// If we only find segments then use the create_url function to
                // create our URL needed for correct re-direction
                
$location = $FNS->create_url($location);
            
}
            
// Perform a check to see if method parameter supplied
            
if ($method === FALSE)
            
{
              
// If we do not find method parameter then perform PHP redirect
              
$FNS->redirect($location);
            
}
            
else
            
{
               
// If we find method parameter then create redirection javascript and output it
               
$output = '<script type="text/javascript">location.href="'.$location.'"</script>';
               
$this->return_data = $output;
            
}
         }

So, with modified Redirect_to function to perform PHP redirect we would need this code:

{exp:redirect_to location="my_template_group/my_template"}

and to perform javascript redirect we would need this code:

{exp:redirect_to location="my_template_group/my_template" method="script"}

 Signature 

Full list of plugins here

Child Categories
Browser Sniff
Category Id
Entries List

Profile
 
 
Posted: 22 May 2008 02:48 AM   [ Ignore ]   [ # 35 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  285
Joined  02-02-2007

Hi Mark,

There is yet another problem with redirects: in some situations you not only cannot perform redirect, but you even cannot test if condition on which you would like to perform redirect was met or not.

For example it seems that it is not possible to perform redirect in cases when {exp:query} tag does not output anything. That is, the code

{exp:query sql="SELECT title FROM exp_weblog_titles WHERE weblog_id = '5' AND url_title ='My title'"}
{if total_results
== 0}
{exp
:redirect_to location="my_template_group/my_template" method="script"}
{
/if}
{
/exp:query}

will not work.

Neither will the code as this (see thread)

{exp:subsegment segment="3" separator="-" index="0" parse="inward"}
{exp
:weblog:entries weblog="my_weblog" url_title="{subsegment}"}
{if no_results}
{redirect
="my_template_group/my_template" method="script"}
{
/if}
{
/exp:weblog:entries}
{
/exp:subsegment}

In both examples it is impossible to perform redirect in case the tag outputs nothing since it is impossible to test if the tag has outputted nothing.

I suppose that it may exist also such situation when the tag has some output, but it is not possible before redirecting to test if it has output or if it has expected output.

I gave some thought on this problem and here is a solution:

In order to test if some complicated condition on which redirect should be performed was met, we need to wrap the code expressing that condition with {exp:redirect_to} and {/exp:redirect_to} tag pair and to check if the tagdata of this tag pair is equal or not equal to some expected string or not.

Here is the code using which you would be able test if {exp:qeery} tag has no output and redirect if it has no output:

{exp:redirect_to location="my_template_group/my_template" method="script"}
{exp
:query sql="SELECT title FROM exp_weblog_titles WHERE weblog_id = '5' AND url_title ='My title'"}
{title}
{
/exp:query}
{
/exp:redirect_to}

If parameter “tagdata” would be added then there would be possible to test not only if there is output and redirect if there is no output, but also to test if there is certain string outputted and redirect if string entered as “tagdata” parameter is equal to string outputted.

Here is the code using which you would be able test if {exp:qeery} tag has outputted a string “1” and redirect if it has outputted this string (checking if string “1” was outputted we are really checking if certain entry exists):

{exp:redirect_to location="my_template_group/my_template" tagdata="1" method="script"}
{exp
:query sql="SELECT title FROM exp_weblog_titles WHERE weblog_id = '5' AND url_title ='My title'"}
{total_results}
{
/exp:query}
{
/exp:redirect_to}

To enable this functionality is quite easy. The function I have published in my previous post should be changed as follows:

function Redirect_to()
{
           
        
global $TMPL, $FNS;
        
        
// Fetch the tagdata
        
$tagdata = $TMPL->tagdata;
        
        
// Fetch our parameters from the plugin tag
        
$location = str_replace("&#47;", "/" ,$TMPL->fetch_param('location'));
        
$method = $TMPL->fetch_param('method');
        
$condition = $TMPL->fetch_param('tagdata');
        
        
// Perform a check to see if a full url is not given in the location parameter
            
if (strpos($location, 'http') !== 0 AND !(strpos($location, 'http') > 0))
            
{
                 
// If we only find segments then use the create_url function to
                 // create our URL needed for correct re-direction
                 
$location = $FNS->create_url($location);
            
}
            
            
// Clean tagdata from new line, carriage return and tab symbols
            
$tagdata = trim($tagdata);
            
$tagdata = str_replace('\n','', $tagdata);
            
$tagdata = str_replace('\r','', $tagdata);
            
$tagdata = str_replace('\t','', $tagdata);
            
$tagdata = str_replace('\x0B','', $tagdata);
   
            
// Perform a check if tagdata conforms to condition, or, in case condition not supplied,
            // if tagdata is equal to empty string or space symbol
            
if ($condition === $tagdata OR (($condition === FALSE) AND (($tagdata === '') OR ($tagdata === ' '))))
            
{
               
// Perform a check to see if method parameter supplied
                
if ($method === FALSE)
                
{
                   
// If we do not find method parameter then perform PHP redirect
                   
$FNS->redirect($location);
                
}
                
else
                
{
                    
// If we find method parameter then create redirection javascript and output it
                    
$output = '<script type="text/javascript">location.href="'.$location.'"</script>';
                    
$this->return_data = $output;
                
}
             }
  }

 Signature 

Full list of plugins here

Child Categories
Browser Sniff
Category Id
Entries List

Profile
 
 
Posted: 22 May 2008 03:31 AM   [ Ignore ]   [ # 36 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  881
Joined  02-15-2008

You’re right, javascript redirects suck and I’m not going to use them. I **really** need to get a redirect working in PHP, within conditionals. The code I have currently works, but redirects regardless of the surrounding if statements (both EE and PHP):

{if total_results == 1}<?php
    
if("{total_results}"==1){ ?>
        {exp
:redirect_to location="/casestudy/{categories show_group="4"}{category_url_title}{/categories}/{url_title}"}
    <?php
    }
    ?>
{
/if}

Any help would really be appreciated on this one.

 Signature 

Andy Harris | Pepper Digital | Malvern, UK | Twitter | New to ExpressionEngine? Start here!
Remember - If at first you don’t succeed, you’re not Chuck Norris

Profile
 
 
   
2 of 4
2
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 64932 Total Logged-in Users: 52
Total Topics: 81897 Total Anonymous Users: 32
Total Replies: 440250 Total Guests: 258
Total Posts: 522147    
Members ( View Memberlist )
Newest Members:  PetrovichusharurblaisdellLevagstudioigotthelemonmileswkakiharaAurelsbhairab
Active Members:    {e}HouseDevAJPatlkarenAvrilBas1cBeertasticbeneberkeleybobhbrendanhBurly ChassisCarlocommunicatedesignCrucialD-Rock