How are your regular expressions?

Discuss news styles, css code, and other Coranto customizations in here...the possibilities are endless, so have at it!

Moderator: Spunkmeyer

How are your regular expressions?

Postby Pirate Elf » Tue Jun 24, 2008 9:42 pm

On my site I have a dialup section for my users that are still living in the dark ages and I have a style set up that will strip the flash of any post. However the side effect is it replaces the whole post, do any of you know perl really well to the point that it would only strip the flash (or any other embed for that matter)?

Current Code:

Code: Select all
<PerlCode>
if ($Text  =~ m/embed src/i)
{
</PerlCode>
<br><b>
This post has flash posted within it, but you are viewing the dialup page which will not load these posts to make it faster. If you wish to see the full post <a href="javascript:popUp('../Coranto/viewnews.cgi?id=<Field: newsid>&tmpl=iSay',550,600)">CLICK HERE</a>
<If: Else>


Since I cannot delete posts this will work.

Code: Select all
$Text =~ s/(<embed src.*?embed>)//i


Will strip any embed commands within a post...

No Actually it will strip any embed commands in news.txt

Is there a way to do if else commands with a profile? Like if profile eq 'whatever'. Or a way I can do the search on just one dat file like dialup,txt instead of the entire news.txt
Nichts ist für dich
Nichts war für dich
Nichts bleibt für dich
Für immer
Pirate Elf
 
Posts: 732
Joined: Wed Jan 31, 2007 9:45 pm

Postby SrNupsen » Wed Jun 25, 2008 7:39 am

Depends on how your "dialup section" is set up. What do the posts in this section have in common? A category name? A checkbox ticked off?

Based on this you can do some If/Else magic in your general style, in order to display flash content ONLY if the user isn't dialing to reach you.
-----------------------------------------------------------------------------------------------------
Coranto is free software. I am available for custom work or troubleshooting.

http://www.sundaune.no - transkripsjon, webdesign, nettsider, tekstbyrå
http://www.vagbladet.no - satire, politikk, kultur, sport, nettavis
-----------------------------------------------------------------------------------------------------
SrNupsen
 
Posts: 2229
Joined: Tue Jan 09, 2007 6:46 pm
Location: Nesodden, outside Oslo, Norway

Postby Pirate Elf » Wed Jun 25, 2008 9:05 am

SrNupsen wrote:Depends on how your "dialup section" is set up. What do the posts in this section have in common? A category name? A checkbox ticked off?

Based on this you can do some If/Else magic in your general style, in order to display flash content ONLY if the user isn't dialing to reach you.


Basically it is set to using default category. But it has a seperate profile and style. It reads news.txt and builds a "dumbed" down version.

Right now my only fix is to totally replace the post with a warning that the post contains flash but this is ugly.

For an idea check here http://www.ragewars.net/Coranto/DialUp.shtml

When it's all said and done what I want is the post to post but if the dialup profile builds it would strip and embed commands within dialup.txt (or at least not show it in the built profile) right now my fix totally eats news.txt and it shouldn't since it's using a seperate style and profile...
Nichts ist für dich
Nichts war für dich
Nichts bleibt für dich
Für immer
Pirate Elf
 
Posts: 732
Joined: Wed Jan 31, 2007 9:45 pm

Postby SrNupsen » Wed Jun 25, 2008 10:23 am

I don't get it... if dialup content has a separate style, why don't you just exclude the java and stuff from that style?
-----------------------------------------------------------------------------------------------------
Coranto is free software. I am available for custom work or troubleshooting.

http://www.sundaune.no - transkripsjon, webdesign, nettsider, tekstbyrå
http://www.vagbladet.no - satire, politikk, kultur, sport, nettavis
-----------------------------------------------------------------------------------------------------
SrNupsen
 
Posts: 2229
Joined: Tue Jan 09, 2007 6:46 pm
Location: Nesodden, outside Oslo, Norway

Postby Pirate Elf » Wed Jun 25, 2008 11:06 am

SrNupsen wrote:I don't get it... if dialup content has a separate style, why don't you just exclude the java and stuff from that style?


I tried that but unless there is a way to see if a field contains X without using perl I don't have an option.

Playing with the perl I am not entirely sure how the regular expression is reading, but since it's just gibberish anyway that perl interprets it's hard to lock down what the right code to make it work is.


*While working on something totally unrelated (modifying the calendar to accept javascript) I worked out a possible way to make this work. After a few 0 byte errors due to bad scripting adding this into cruser.pl will do exactly what I want without eating news.txt and will only work on the specific profile. In hindsight in future versions of coranto perhaps make styles only affect/effect (I always get those wrong) their specific .txt files and not the global news.txt.

Code: Select all
sub replace
{
my $replace = $Text;
$replace =~ s/(<embed src.*?embed>)//i;
return "$replace";
}



then it's a simple matter of calling the sub ala <Sub: replace> in the style.

And there was much rejoicing.
Nichts ist für dich
Nichts war für dich
Nichts bleibt für dich
Für immer
Pirate Elf
 
Posts: 732
Joined: Wed Jan 31, 2007 9:45 pm

Postby Musicvid » Wed Jun 25, 2008 3:56 pm

Here's some interesting reading on localizing variables to profiles and styles in the cases of:
-- Using the same variables in multiple styles (which is probably why your first regexp didn't work and your sub did); or,
-- Two or more profiles using the same style.

http://coranto.org/forum/viewtopic.php?t=10022#66490

...in future versions of coranto perhaps make styles only affect their specific .txt files and not the global news.txt.

Running regexp or subs inside a style does not actually affect news.txt because it does not rewrite the file -- it only temporarily filters or alters the output, either globally or locally, depending on how you call it from the script. So it is really a Perl thing, not a Coranto thing.

I don't know how much of this applies to your case, however if you will post your Style code and examples of news containing the embeds you want to exclude, I might be able to look at it next week.
Last edited by Musicvid on Thu Jun 26, 2008 4:43 pm, edited 1 time in total.
Musicvid
 
Posts: 138
Joined: Wed Jan 17, 2007 1:05 am
Location: Western America

Postby SrNupsen » Wed Jun 25, 2008 5:43 pm

Funny how I didn't understand what your problem was until after you had allready fixed it :?
-----------------------------------------------------------------------------------------------------
Coranto is free software. I am available for custom work or troubleshooting.

http://www.sundaune.no - transkripsjon, webdesign, nettsider, tekstbyrå
http://www.vagbladet.no - satire, politikk, kultur, sport, nettavis
-----------------------------------------------------------------------------------------------------
SrNupsen
 
Posts: 2229
Joined: Tue Jan 09, 2007 6:46 pm
Location: Nesodden, outside Oslo, Norway

Postby Pirate Elf » Wed Jun 25, 2008 11:36 pm

SrNupsen wrote:Funny how I didn't understand what your problem was until after you had allready fixed it :?


I'm used to that. The things I make coranto do I am pretty sure it was never dreamed of that you could or should do it.

As to my earlier post this solutions works great. What I was wanting to do is I have a profile and a style setup that are basically dumbed down lo-fi versions of my main page. I still have users that have crappy connections, dial up, or are over seas with less than awesome connections. So I was petitioned to make my page accessible for these people. Flash was a big complaint for a lot of them because stuff like youtube eats a slow connection. The problem is they style itself required the basic field (text) and I didn't want posters posting to A: two profiles, and B: I wanted it to seem fluid. However, doing it that way I was setup with the fact that I needed a way to alter the field text but only for a given profile.

Enter the sub which fixes this problem. It will look for any embed commands and strip them completely out of the text field but ONLY for that particular profile. As you can see from this post the early attempts were not successful due to the nature of Perl and how coranto does certain things. I realized the solution as I was working on my calendar (smcCal) I needed smcCal to look for apostrophes in the subject (i.e. $title) and replace them with \' working on it I delved pretty deep into the nature of perl and expressions working with javascript and developed a solution. The process lead me to believe I could apply the same principle to Coranto without it eating my news.txt

Thus the solution.
Nichts ist für dich
Nichts war für dich
Nichts bleibt für dich
Für immer
Pirate Elf
 
Posts: 732
Joined: Wed Jan 31, 2007 9:45 pm

Postby SrNupsen » Thu Jun 26, 2008 6:31 am

Well done, and a slick solution. Congratulations!
-----------------------------------------------------------------------------------------------------
Coranto is free software. I am available for custom work or troubleshooting.

http://www.sundaune.no - transkripsjon, webdesign, nettsider, tekstbyrå
http://www.vagbladet.no - satire, politikk, kultur, sport, nettavis
-----------------------------------------------------------------------------------------------------
SrNupsen
 
Posts: 2229
Joined: Tue Jan 09, 2007 6:46 pm
Location: Nesodden, outside Oslo, Norway

Postby Musicvid » Thu Jun 26, 2008 3:47 pm

As you can see from this post the early attempts were not successful due to the nature of Perl and how coranto does certain things.

I think it's because you didn't put the "my" lexical operator in your first regexp.
Musicvid
 
Posts: 138
Joined: Wed Jan 17, 2007 1:05 am
Location: Western America


Return to Customization

Who is online

Users browsing this forum: No registered users and 2 guests

cron