Recent Topics

1 Oct 23, 2007 08:56    

My b2evolution Version: 1.10.x

I've tried unsuccessfully to find the answer in the forum, so I'm sorry if it's already there somewhere.

I'm using b2evo 1.10.2 and the nautica skin. I don't know if it's the css, but ticks (' & ") are converted to the curly quotation marks (6 & 9) when the blog is displayed. I have an older installation with the same skin, which I use for testing things, and it doesn't convert, but I've tried another skin (miami_blue) in my current installation, and it doesn't do it either. My conclusion is that it's to do with the nautica skin, but I have no idea where to look for that.

I like the fact that it converts, as I prefer the curly quotes, but the problem is that when a quotation mark is followed by another punctuation mark, like a comma or a period (full stop) it doesn't convert - so that particular one will stay as a tick. My awkward workaround has been to put a space between the quotation and the other punctuation, but that looks weird to me and I don't like it ;)

So what I want to know is (yes, there was a point!): does anybody know where this conversion takes place, and can I make it happen all the time?

I'm wondering if there is the possibility that it's to do with the smileys and text conversion in that plugin, but I don't know where to start.

2 Oct 23, 2007 16:15

Well, from all questions I have seen, this is the most funny one.

You were close in your assumption that this is a skin issue and I searched for too long in the wrong direction. The fact is that not all skins use a font that is able to distinguish the opening and the closing quotation marks from the unisex ones.

The transistion is made in the texturizing plugin. Find ../blogs/plugins/_texturize.plugin.php and add to the first line of this example the second:

$curl = preg_replace('/"(\s|\Z)/', '”$1', $curl);
$curl = preg_replace('/"[.|,]?(\s|\Z)/', '”.$1', $curl);


and for the single quotation mark:

$curl = preg_replace("/'([\s.]|\Z)/", '’$1', $curl);
$curl = preg_replace("/'[.|,]?([\s.]|\Z)/", '’$1', $curl);

Note: phpBB ruined this example. Use & # 8221 in the first and & # 8217 in the second php code. See the plugin itself for details. In both cases you add [.|,]? to the existing line.

It probably works also if you replace the lines, but they don't bite.

Good luck

3 Oct 23, 2007 16:57

Thanks Afwas, I really appreciate that - and I'm glad I could give you a laugh :p I don't usually ask "normal" questions because they've often been asked by somebody else already.

Following your instructions, I now have curly quotes, but it actually makes the adjacent punctuation invisible... i.e. in the backoffice my comma etc. is still there but on the page it's gone.

Also, it still doesn't texturise for any other punctuation if it's not a '.' or a ',' Would that mean the [.|,]? would have to become [.|,|?|;]? etc to allow for any other possibility? As you can probably tell, I'm (still) not very php-literate...

The transistion is made in the texturizing plugin. Find ../blogs/plugins/_texturize.plugin.php and add to the first line of this example the second:
PHP:
$curl = preg_replace('/"(\s|\Z)/', '”$1', $curl);
$curl = preg_replace('/"[.|,]?(\s|\Z)/', '”.$1', $curl);

I just added in the [.|,]? to each - I'm guessing the '.' in '”.$1', was part of phpBB's messing with it.

and for the single quotation mark:
PHP:
$curl = preg_replace("/'([\s.]|\Z)/", '’$1', $curl);
$curl = preg_replace("/'[.|,]?([\s.]|\Z)/", '’$1', $curl);

Note: phpBB ruined this example. Use & # 8221 in the first and & # 8217 in the second php code. See the plugin itself for details. In both cases you add [.|,]? to the existing line.

Sorry to keep asking, but I'd like to figure it out. Although now that I know where it comes from, if it's not fixable I can just turn off the plugin...

Thanks again.

4 Oct 23, 2007 17:16

Thanks for the feedback

cockatoo wrote:

I just added in the [.|,]? to each - I'm guessing the '.' in '”.$1', was part of phpBB's messing with it.

Actually it was me messing with it. I had a dot in my post, so it worked (it did the closing quotation mark *and* the dot). But this is no solution for you.

I will come up with a solution shortly.

5 Oct 23, 2007 17:22

This *appears* to work ( screws up the ";" though, but how often will you need that? ;) ) :

<?php
$fred = '"hello world", said "Fred". Unfortunately he had a problem of thinking of a sentence that involved ";" so he "went home";-p';

$peter = preg_replace( array( '~(\w)"~','~"(\w)~' ) , array( '$1[close_quote]', '[open_quote]$1' ), $fred );

echo $peter;
?>

¥

6 Oct 23, 2007 17:23

This is not beautiful, but it works:

$curl = preg_replace('/"\.+(\s|\Z)/', '& #8221;.$1', $curl);
$curl = preg_replace('/"\,+(\s|\Z)/', '& #8221;,$1', $curl);
$curl = preg_replace('/"\?+(\s|\Z)/', '& #8221;?$1', $curl);
$curl = preg_replace('/"\;+(\s|\Z)/', '& #8221;;$1', $curl);


There must be a way to catch them in one expression, but that's beyond my knowledge (I hoped I had them in my first attempt :roll: ).

Good luck

7 Oct 23, 2007 18:00

This seems to be the single line version:

$curl = preg_replace('/"(\s|\Z|.\s|.\Z)/', '”$1', $curl);

Good luck

8 Oct 23, 2007 18:41

Oh. My. Goodness! LOL - I was about to give up...

Thankyou both Afwas and ¥åßßå for your help - the first solutions didn't work for me and I have reloaded and installed that plugin so many times because I messed up the code too much... I'm sorry, ¥åßßå, I have no idea what yours meant and it did weird things to my page (but that could have been to do with my choice of placement in the code).

Actually, decided to go back and check again - the "not beautiful" one:

This is not beautiful, but it works:
PHP:
$curl = preg_replace('/"\.+(\s|\Z)/', '& #8221;.$1', $curl);
$curl = preg_replace('/"\,+(\s|\Z)/', '& #8221;,$1', $curl);
$curl = preg_replace('/"\?+(\s|\Z)/', '& #8221;?$1', $curl);
$curl = preg_replace('/"\;+(\s|\Z)/', '& #8221;;$1', $curl);

*did* work after I realised there were spaces before #8221 in the lines above.

This is perfect, and I'm really going to have to learn some more php so I can figure out what on earth it means (I've figured some of it out - to modify, I wouldn't attempt anything from scratch yet).

This seems to be the single line version:
PHP:
$curl = preg_replace('/"(\s|\Z|.\s|.\Z)/', '”$1', $curl);

It appears that this works for single and double quotation marks, should that be so?

Thanks again, very much appreciated :)

9 Oct 23, 2007 19:03

Update: No, it wasn't so ;)
All was looking great until I reached some text with single quotes at the end of a word followed by a space - they weren't curly, although everything with other punctuation was fine... so... this seems to fix it... I hope that's right, because so far it does the job, and it would be sad for it to mess something else up later...

The first line is Afwas' - the second line is my adaptation of the line that came after it (aforementioned spaces added back in before the # to mess with phpBB's compulsion to change it).


$curl = preg_replace('/"(\s|\Z|.\s|.\Z)/', '& #8221;$1', $curl);
$curl = preg_replace("/'([\s.]|\Z|.[\s.]|.\Z)/", '& #8217;$1', $curl);

Anyway, it seems to be good now, thanks again.

10 Oct 23, 2007 19:24

If there were any riddles to solve like the extra space (to avoid the phpBB problem) and the similar line you needed to change for the single quotes, you found them.
Note that this line:

$curl = preg_replace("/'([\s.]|\Z|.[\s.]|.\Z)/", '& #8217;$1', $curl);


is not going to work if you don't put the dots in the right place. :>

Well done. Happy blogging.

11 Oct 24, 2007 00:37

For those with some interest in regular expressions I will analyze this line:

$curl = preg_replace('/"(\s|\Z|.\s|.\Z)/', '& #8221;$1', $curl);


The ' is just the start of a string
the / is the start of a regular expression
the " is the object we are searching for, literally a double quotation mark
the ( denotes the start of the pattern
the | means "or"
the \s stands for whitespace
the \Z matches a line break or end of string
the . is any single character.
So the expression reads: find " before (a space or end of string or one character + space or one character + end of string).

12 Oct 24, 2007 02:51

Note that this line:


$curl = preg_replace("/'([\s.]|\Z|.[\s.]|.\Z)/", '& #8217;$1', $curl);

is not going to work if you don't put the dots in the right place.

Do you mean I *didn't* put them in the right place? Or that I *did*? It still works, so I'm going to leave things as they are unless it goes wrong ;)

Thanks for the help and encouragement.

13 Oct 24, 2007 03:07

For those with some interest in regular expressions I will analyze this line:


$curl = preg_replace('/"(\s|\Z|.\s|.\Z)/', '& #8221;$1', $curl);


etc...

Thanks for this explanation - that definitely makes sense of the parts I hadn't understood yet. For this task I've still been at the point of copying and modifying existing patterns, not really understanding what I was doing. I know that's part of learning it, but I appreciate your taking the time to explain more detail.

One more thing, and I know I should just look up php now, but it still relates to this. In the other line, from earlier in the thread (not what I ultimately used, but as an example:

and for the single quotation mark:


$curl = preg_replace("/'([\s.]|\Z)/", '’$1', $curl);
$curl = preg_replace("/'[.|,]?([\s.]|\Z)/", '’$1', $curl);

the first string is opened with " instead of ' - is that because the ' is the object we're searching for in this case? Is this the only time we would substitute " ? Sorry, this paragraph starts to look confusing, but it's the shortest way of writing ' and " ;)

And finally, it seems obvious now, but I want to point out that it works for colons and semicolons too, and I'm assuming (until proven wrong) it will be fine for anything I throw at it. ¥åßßå's explanation still fascinates me, but Afwas' solution fits into a smaller space and seems to cover all I need.

Thank you for your time, help and extra explanation.

14 Oct 24, 2007 10:55

cockatoo wrote:

the first string is opened with " instead of ' - is that because the ' is the object we're searching for in this case? Is this the only time we would substitute " ? Sorry, this paragraph starts to look confusing, but it's the shortest way of writing ' and " ;)

In php you can start a string with both 'and " but you must be careful if you are using one or both characters in the string itself as in this example. Php will think it's the end of the string.

'John said: it's late'


will end the string after the t so you do:

"Jonh said:  it's late"

And yes, both the " and ' in the php lines from the texturize plugin are the subject we are looking for. Your code is 'ugly' but it works -check out why. You could have copied more exactly:

$curl = preg_replace("/'(\s|\Z|.\s|.\Z)/", '’$1', $curl);


Or have a look at [url=http://forums.b2evolution.net/viewtopic.php?t=13078&start=0&postdays=0&postorder=asc&highlight=][Almost solved] minor issue in texturize plugin[/url]

Good luck

15 Oct 24, 2007 11:21

cockatoo wrote:

I'm sorry, ¥åßßå, I have no idea what yours meant and it did weird things to my page (but that could have been to do with my choice of placement in the code).

Copy / paste ¥åßßås code into a text editor and save it as fred.php. Upload it to your server and run it in a browser. Afterwards you can play with the code :lol:

Good luck

16 Oct 24, 2007 11:42

Whilst yer playing, here's an alternative ;) ( it still screws up ";" though ;) ) :

<?php
$fred = '"hello world!", said "Fred". Unfortunately he\'d a problem of thinking of a sentence that involved ";" so he "went home";-)';

$peter = preg_replace( array(
	'~((\w)["\'](\W))|((\W)["\'](\w))|((\W)["\'](\W))~', // find any " or ' within sentance
	'~^["\']~', // find any " or ' at start of line
	'~["\']$~' // find any " or ' at end of line
	 ) ,array( '$2$5$8[quote]$3$6$9', '[quote]' ), $fred );

echo $peter;
?>

¥


Form is loading...