1 of 2
1
Plugin: Extract URL Plus 2
Posted: 29 October 2007 11:26 AM   [ Ignore ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1097
Joined  03-22-2006

An almost complete rewrite of the older Extract URL Plus plugin.

This plugin is designed to take a URL (alone, or mixed in with other text, such as the automatic link the upload form might create) and dissect it into it’s seperate components.

For an example URL (this contains all components!):

http://user:pass@www.example.com:8080/articles/index.php?id=10&q=Hello+World#example_anchor

These components are named, as variables:

full_url ( [the given url] )
scheme (http)
user (user)
pass (pass)
host (www.example.com)
port (8080)
public_path (/articles)
file_path (/articles/index.php)
server_path (/var/www/html/articles/index.php)
file_name (index.php)
extension (php)
description (PHP File)
file_size (1.14KB)
query_string (id=10&q=Hello+World)
fragment (example_anchor)

The usage is pretty much identical as to the older version, so either:

Example A:

(remove space between % and variable name!)

{exp:zm_extract_url_plus show="% file_name (% file_size)"}
    
... Some text ...
    
{url_custom_field}
    
... Some more text ...
{/exp:zm_extract_url_plus)

Example B:

{exp:zm_extract_url_plus url="{url_custom_field}"}
{file_name}
({file_size})
{/exp:zm_extract_url_plus}

Both examples returning:

index.php (1.14KB)

There is an additional parameter in this version:

url_only=”” - Defaults to “no”, meaning the plugin will revert to using a regular expression to find the URL in text. This of course is more CPU intensive than if you are supplying JUST a URL, where you could set this paramater to “yes”.

Enjoy!

File Attachments
pi.zm_extract_url_plus.201.zip  (File Size: 5KB - Downloads: 598)
 Signature 

(a.k.a the_butcher)

Profile
 
 
Posted: 29 October 2007 11:52 AM   [ Ignore ]   [ # 1 ]  
Lab Assistant
RankRank
Total Posts:  276
Joined  07-04-2007

What was the reason for the rewrite?  Just to allow more url components?

I will give this a go, let you know how i get on.

Thanks

Profile
 
 
Posted: 29 October 2007 12:21 PM   [ Ignore ]   [ # 2 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1735
Joined  03-26-2006

It was throwing “No URL Found” errors when used with Huot’s File module, at least for me. Thanks for the rewrite!

 Signature 

ryan masuga
—————
Masuga Design | Member, EE Pro Network
My EE Add-Ons | {devot:ee}
Twitter: masuga | masugadesign | devot_ee

Profile
 
 
Posted: 29 October 2007 01:21 PM   [ Ignore ]   [ # 3 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1097
Joined  03-22-2006

@Joobs:

There were many reasons for the rewrite. One was to bring it inline with the developer guidlines, though I’ve yet to submit it for addition to the official repository. The others:

- Allow for a regex OR non-regex parsing of the URL.
- Add caching to improve performance on multiple calls for the same URL.
- Clean up and improve the reliability of the regex.
- Improve the naming of variables.
- Improve the file descriptions to allow for a generic response.
- Add more matched variables (such as user/pass/query_string/fragment). Note that if a URL had any of these components, the old plugin would likey return “No URL Found”—(Don’t you just hate that error already ;])
- Filesize should work without having to muck around with the plugin code.
- You can now use all the variables within conditionals (if used like example B)
- Replaces lone & with & amp; (minus the space) for the full_url variable
- Various security features

The list goes on smile

@Ryan:
Has 2 alleviated the gruesome No URL Found error? smile

 Signature 

(a.k.a the_butcher)

Profile
 
 
Posted: 29 October 2007 01:26 PM   [ Ignore ]   [ # 4 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1735
Joined  03-26-2006

Um, I actually found another way around my problem (big bad deadlines…) but I’ll make sure to try this out when I get a chance.

 Signature 

ryan masuga
—————
Masuga Design | Member, EE Pro Network
My EE Add-Ons | {devot:ee}
Twitter: masuga | masugadesign | devot_ee

Profile
 
 
Posted: 30 October 2007 06:26 AM   [ Ignore ]   [ # 5 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  6579
Joined  04-15-2006

Hiya mdesign,

Just wondering what you did to get around the problem you were having. I’m at the moment using an SAEF with the File extension and am having problems using the original Extract URL and this one due to the files having spaces in their names. Just wondering how you managed to get the name with this happening?

Best wishes,

Mark

 Signature 

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

Profile
 
 
Posted: 08 November 2007 07:47 AM   [ Ignore ]   [ # 6 ]  
Grad Student
Rank
Total Posts:  77
Joined  05-11-2007

I’m getting alternating “Notice: Undefined offset: 7” and “Notice: Undefined offset: 8” errors when I try to use this with phpthumb. I can get the older extract_url plugin to work, but it only extracts the full url, and I need to be able to extract just the file name or the file path.

{exp:weblog:entries weblog="{my_weblog}"}
<div class="thumbnail"><a href="{path=products/products/{entry_id}}"><img src="http://www.mysite.com/images/thumbs/phpThumb/phpThumb.php?src= {exp:zm_extract_url_plus show="&#xfi;le_path"}{photo}{/exp:zm_extract_url_plus}&amp;w=100" border="0" alt="{title}" /> </a>

<p><a href="{path=products/products/{entry_id}}">{title}</a></p>
</
div>

{/exp:weblog:entries}

{photo} is a custom field I’m using for links to the product photos

Profile
 
 
Posted: 08 November 2007 12:00 PM   [ Ignore ]   [ # 7 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1097
Joined  03-22-2006

Fixed, and updated download.

 Signature 

(a.k.a the_butcher)

Profile
 
 
Posted: 08 November 2007 10:09 PM   [ Ignore ]   [ # 8 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  871
Joined  04-14-2007

Hey Dan, I’m hoping your update will address this situation.

I’m trying to implement phpThumb and your plugin (tested unsuccessfully with prior version) to handle image sizing in conjunction with the wiki module.

The wiki file upload process seems to encode image uploads and then uses that code to reference the image rather then the “file_name” and “extension” 

//Example
http://wwww.domain.com/index.php/wiki/1a865c7b038fc4f2425e228d38c2cfa9/


Would the use of “% file_name” alone:

{exp:zm_extract_url_plus show="% file_name"}

be sufficient to pull the long string representing the file?

OR

would I need to use the “query_string” to pull that code?

Thanks

 Signature 

Michael Rubens | hothousegraphix
Making the simple complicated is commonplace; making the complicated simple, awesomely simple, that’s creativity. - Charles Mingus

Profile
 
 
Posted: 13 December 2007 09:32 AM   [ Ignore ]   [ # 9 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  717
Joined  07-02-2007

Shame that you dropped some variables that where handy :’(

% subdomain - (e.g., “www”)
% domain - (e.g., “example”)
% tld - (e.g., “com”)

Lets say http://www.yahoo.com/news/bla

I only want ‘yahoo.com’
Now i have to use the old plugin smile

 Signature 

Truly ExpressionEngine


Fielder Module ( Mass Custom Fields )
Super Cache (Cache heavy tag output)
reCAPTCHA Extension
Rewrite Module


See all my EE Addons (8)

Profile
 
 
Posted: 04 February 2008 04:23 AM   [ Ignore ]   [ # 10 ]  
Summer Student
Avatar
Total Posts:  6
Joined  01-07-2007

Hello, and thank you for this time-saving plugin. The filesize_precision parameter does not work for me; the output is set to the default 2, regardless of what value I ascribe. Here’s the code sample (I’d also been using the exp:extract_url plugin):

{exp:zm_extract_url_plus show="(% description, % file_size)" filesize_precision="1"}{custom_field}{/exp:zm_extract_url_plus}

(I inserted a space above between the percent symbol and the variables “description” and “file_size” so that the text would not be reformatted by the Forum type engine.)

Everything works but the filesize_precision parameter—not a deal-breaker but it would be nice to format the file size number more appropriately.

(Note: I realize I can rewrite the output using only the exp:zm_extract_url_plus plugin without the previous exp:extract_url plugin, using the alternative syntax given in the plugin documentation, but I want to take care of one stage at a time.)

Thanks in advance for your help.

Profile
 
 
Posted: 04 February 2008 07:46 AM   [ Ignore ]   [ # 11 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1097
Joined  03-22-2006

Hmm, looking at the code I see no obvious failure point. What happens if you try 0 and larger number, say 5?

 Signature 

(a.k.a the_butcher)

Profile
 
 
Posted: 04 February 2008 07:55 AM   [ Ignore ]   [ # 12 ]  
Summer Student
Avatar
Total Posts:  6
Joined  01-07-2007

I did try setting the parameter to “0” but the output remained at the default two (2) decimal places. Also, I had placed more of the actual code in, but because it was an anchor tag, it got stripped. What is posted above conveys the gist of it. Finally, I have checked the surrounding syntax meticulously and validated the entire page via two services just to be sure there were no markup errors.

I will try increasing the parameter value to see if it affects the output, then post my results. Thanks for the suggestion.

EDIT
I changed the parameter value to 4 and the output was the same, 2 decimal places. I also looked in the plugin source code to make sure that the parameter referenced was indeed filesize_precision and not, say, file_size_precision (since there is a variable called % file_size [no space in between % symbol and variable name]).

Thanks again in advance for any help or insight.

EDIT
After the “fix” below, I attempted filesize_precision=“0” and was returned the default 2 decimal places, so it appears that the minimum is filesize_precision=“1”.

Profile
 
 
Posted: 04 February 2008 08:43 AM   [ Ignore ]   [ # 13 ]  
Summer Student
Avatar
Total Posts:  6
Joined  01-07-2007

OK, I found the solution. For anyone interested, the analysis follows:

1. The custom_field in the weblog is a link (meaning, an anchor tag). To get at the URL value, I used the exp:extract_url plugin. The idea was to process this extracted URL using the 2nd plugin.

2. Obviously, I didn’t use the alternative syntax, because a prior “raw” URL value was not available. And using exp:extract_url within the 2nd plugin’s url parameter, as expected, generated errors. (You never know—it’s like a Hail Mary in football ... just throw it out and hope it works ...)

3. Using the plugin’s show parameter to output the entire anchor link was not possible because I require a conditional to apply a CSS class (class=“pdf”). The anchor tag, therefore, had to be broken up.

4. I used exp:extract_url to get the raw URL. I could have also just used full_url from exp:zm_extract_url_plus, but that involved more typing and more room for typos. wink

5. I used *two* instances of the exp:zm_extract_url_plus tag, one to get the file extension and one to get the file description and file size.

6. It turned out that, for whatever reason, I had to specify filesize_precision=“1” for both instances of exp:zm_extract_url_plus, even though I didn’t need it for the first instance. If I did this, the setting was respected in the 2nd instance of the plugin.

Sorry to be longwinded—only in the hopes of this helping someone else. Here’s the complete structure of the code (with a space inserted between % and the variable to skirt the Forum’s type engine):

<anchor {if "{exp:zm_extract_url_plus show='% extension' filesize_precision='1'}{custom_field}{/exp:zm_extract_url_plus}" == "pdf"}class="pdf" {/if}href="{exp:extract_url}{custom_field}{/exp:extract_url}" (insert JS code to open link in new window)>Link text</anchor> {exp:zm_extract_url_plus show="(% description, % file_size)" filesize_precision="1"}{custom_field}{/exp:zm_extract_url_plus}

Profile
 
 
Posted: 22 February 2008 09:34 AM   [ Ignore ]   [ # 14 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  300
Joined  07-31-2007

I must be particularly thick but I can’t get this plugin to work :’(

{exp:weblog:entries weblog="documentation" orderby="date"}
    
<h4>{title}</h4>
    <
p>
        
{exp:zm_extract_url_plus show="%filename.%extension (%filesize)"}
        
<a href="http://my_dev_sites:8888/client/job/uploads/docs/Some_Manual.pdf">My file</a>
        
{/exp:zm_extract_url_plus}                    
    
</p>                    
    
{description}
{
/exp:weblog:entries}

And that’s what the output of zm_extract_url_plus give me:

<p>
    %
filename.pdf (%filesize)                    
</
p>

The most perplexing part is that some of it works since the extension is parsed correctly… Any ideas of what I might be doing wrong?

Thanks!

 Signature 

——————————————————-
ExpressionEngine 1.6.2 - Build:  20080206

Profile
 
 
Posted: 22 February 2008 03:09 PM   [ Ignore ]   [ # 15 ]  
Summer Student
Avatar
Total Posts:  6
Joined  01-07-2007

The example given in the documentation doesn’t match the choice of variables delineated beneath it (may be an editing oversight?).

The variable you should use, according to the documentation, is “% file_name” not “% filename” AND “% file_size” not “% filesize” (*without* the space between the % symbol and the variable name—which has to be inserted to skirt the Forum typography engine).

Hope this helps.

minimal design - 22 February 2008 09:34 AM

I must be particularly thick but I can’t get this plugin to work :’(

{exp:weblog:entries weblog="documentation" orderby="date"}
    
<h4>{title}</h4>
    <
p>
        
{exp:zm_extract_url_plus show="%filename.%extension (%filesize)"}
        
<a href="http://my_dev_sites:8888/client/job/uploads/docs/Some_Manual.pdf">My file</a>
        
{/exp:zm_extract_url_plus}                    
    
</p>                    
    
{description}
{
/exp:weblog:entries}

And that’s what the output of zm_extract_url_plus give me:

<p>
    %
filename.pdf (%filesize)                    
</
p>

The most perplexing part is that some of it works since the extension is parsed correctly… Any ideas of what I might be doing wrong?

Thanks!

Profile
 
 
Posted: 22 February 2008 03:36 PM   [ Ignore ]   [ # 16 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  300
Joined  07-31-2007

Thanks for the heads up. I used the example in the plugin usage page in the CP. Looks like dev doesn’t like documentation wink

Well, anyway, some work like file_name, but file_path or file_size don’t, which are ones I need… at this point it’s faster for me to go w/ PHP…

Thanks again!

 Signature 

——————————————————-
ExpressionEngine 1.6.2 - Build:  20080206

Profile
 
 
Posted: 26 February 2008 06:04 AM   [ Ignore ]   [ # 17 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1097
Joined  03-22-2006

Correct. The variable names in the examples (plugin usage pages) are wrong. And as for proper documentation? Oh it exists, just waiting for the damned designer to make up his mind smile

 Signature 

(a.k.a the_butcher)

Profile
 
 
Posted: 08 May 2008 02:51 PM   [ Ignore ]   [ # 18 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  286
Joined  02-02-2007

It would be nice if it were possible to wrap with the tags of this plugin such global variables as {site_url} and {homepage}, and global template variables.

Now wrapping {site_url} or {homepage} or global template variables with Extract URL Plus 2 tags do not change their output. It seems that this is an issue of template parsing order, isn’t it?

 Signature 

Full list of plugins here

Child Categories
Browser Sniff
Category Id
Entries List

Profile
 
 
   
1 of 2
1
 
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: 65024 Total Logged-in Users: 40
Total Topics: 82111 Total Anonymous Users: 23
Total Replies: 441281 Total Guests: 184
Total Posts: 523392    
Members ( View Memberlist )