WordPress Subscribe2 plugin escapes characters in blog name when sending email - php

I'm using Subscribe2 plugin in my new upcoming WordPress blog (http://www.adlerr.com). My blog's title is "Roee Adler's Blog". When sending an email, Subscribe2 escapes the apostrophe in my blog's title, and the e-mail subject is received as follows:
[Roee Adler's Blog] Please confirm your request
The e-mail body is:
Roee Adler's Blog has received a request to
subscribe for this email address. To complete your
request please click on the link below:
...
I would naturally like to have the "normal" un-escaped version of my blog name in the title and body.
I asked this question on doctype.com with no success (here's the question), however from the answers I understood this probably requires changes to the PHP code of the plugin, so I would rather ask it here.
Following the answers I received on doctype, I did alter the following section of code:
function substitute($string = '') {
if ('' == $string) {
return;
}
$string = htmlspecialchars_decode(str_replace("BLOGNAME", get_option('blogname'), $string));
$string = str_replace("BLOGLINK", get_bloginfo('url'), $string);
$string = htmlspecialchars_decode(str_replace("TITLE", stripslashes($this->post_title), $string));
$string = str_replace("PERMALINK", $this->permalink, $string);
In the code above, I added a htmlspecialchars_decode wrapper for the generation of both BLOGNAME and TITLE, however the e-mail subject and body still contains '.
What can I do to resolve this?
Thanks

As per the documentation on htmlspecialchars_decode, you need to pass ENT_QUOTES as the $quote_style argument for it to convert ' to '. Try setting ENT_QUOTES:
function substitute($string = '') {
if ('' == $string) {
return;
}
$string = htmlspecialchars_decode(str_replace("BLOGNAME", get_option('blogname'), $string), ENT_QUOTES);
$string = str_replace("BLOGLINK", get_bloginfo('url'), $string);
$string = htmlspecialchars_decode(str_replace("TITLE", stripslashes($this->post_title), $string), ENT_QUOTES);
$string = str_replace("PERMALINK", $this->permalink, $string);

WordPress replaces an apostrophe in the blog title with ' before it stores it in the database. If you want to override this, edit the functions.php file and insert the following statement:
update_option("blogname", "My Blog's Title With Apostrophe");
That will force the title to be exactly what you enter. Changes to the blog title you make in the Settings menu will have no effect.

Related

basic php 'if then' URL link in wordpress

I'm trying to write code that will display a URL link if there one present from a form sumbmission;
If > [a link exists]
then [display the text 'more info' with the href link wrapped around it]
I've confused myself mixing wordpress and php, and can't quite get it. Any help would be great.
This question isn't very specific, but the pseudo-code I can offer is this:
<?php if (isset($_GET['url'])): ?>
Read more
<?php endif; ?>
Are you looking to do something like this to the comments displayed on a post?
Comment: "I like https://www.google.com/" becomes "I like more info".
If that's the case, perhaps adding a filter to functions.php to search for and replace URL might do the trick:
// define the get_comment_text callback
function filter_get_comment_text( $comment_comment_content, $comment, $args ) {
// Regular expression to find URL
$pattern = '/(https?):\/\/(www\.)?[a-z0-9\.:].*?(?=\s)/i';
// Replace url with linked "more info"
$replacement = 'more info';
// Find matches & replace
$newcomment = preg_replace($pattern, $replacement, $comment_comment_content);
// Return the comment
return $newcomment;
};
// add the filter
add_filter( 'get_comment_text', 'filter_get_comment_text', 10, 3 );

Find URL in string, replace it and alter href

I've currently got a few DB entries which look like this:
1. This is some text http://www.sitehere.com more text
2. Text https://www.anothersite.com text text text
3. http://sitehere.com http://sitehereagain.com
4. Just text here blabla
I am trying to filter those entries while printing them and add infront of all the urls http://anothersite.com/?. Also put the new url destination as link but keep the original url as text:
text text http://sitehere.com text
Until now I've managed to add the http://anothersite.com/? part with the following code:
$result = preg_replace('/\bhttp:\/\/\b/i', 'http://anothersite.com/?http://', $input);
$result = preg_replace('/\bhttps:\/\/\b/i', 'http://anothersite.com/?https://', $input);
But the ahref is not the way I want it. Instead it is:
text text http://anothersite.com/?http://sitehere.com text
PS: I am not looking for a javascript solution :) Thank you!
This following code should work. There are a few large changes I made. The first one is I am using preg_replace_callback instead of preg_replace so I am able to properly encode the URL and have more control over the output. The other change is I'm matching the whole domain so the callback function can insert the URL between the <a> tags and also can add it to the hyperlink.
<?php
$strings = array(
'This is some text http://www.sitehere.com more text',
'Text https://www.anothersite.com text text text',
'http://sitehere.com http://sitehereagain.com',
'Just text here blabla'
);
foreach($strings as $string) {
echo preg_replace_callback("/\b(http(s)?:\/\/[^\s]+)\b/i","updateURL",$string);
echo "\n\n";
}
function updateURL($matches) {
$url = "http://anothersite.com/?url=";
return ''.$matches[1].'';
}
?>

correct regex synthax in custom bbcode apllication

I wish to integrated the prism synthax highlighter into my custom built php/mysql CMS; however i am having some issues with regex synthax.
This is what i wish to accomplish:
Allow users to post
text alone,
or code and text but never code alone.
Code may be preceded by text or text may be included after the code.
My PHP Code is below:
function bbcode2html($var)
{
// [code]
$var = preg_replace('/\[code](.+?)\[\/code]/si',
'<section class="language-markup">
<pre><code>$1</code></pre>
</section>', $var);
return $var;
}
$var = '[code]<!DOCTYPE html>[/code] THis is text';
// verify content input
if(!preg_match("/(w+?)|\[code](.+?)\[\/code]/si", $var))
{
echo 'The code tags can not be empty!';
}
elseif(!preg_match("/(w+?)|\[code](.+?)\[\/code](w+)/si", $var))
{
echo 'Your post contains only code, please add some text';
}else{
echo $var = bbcode2html(htmlentities($var));}
With the present code above, this is what i have observed the following:
When text alone is posted, i get this feedback 'The code tags can not be empty!'
When text and code are posted, i get this feed back 'Your post contains only code, please add some text'
I therefore need clues as to the right regex synthax that will enable me achieve these two objectives:
Allow users to post text alone, or code and text but never code alone.
Code may be preceded by text or text may be included after the code.
Thanks.
What about doing two checks:
Verify the string contains one [[:alnum:]], after stripping all [code]...[/code] and trimming.
Check for empty code tags
See example on eval.in
$var = '[code]<!DOCTYPE html>[/code] THis is text';
// code alone or nothing
if(!preg_match('~[[:alnum:]]~', trim(preg_replace('~\[code\].*?\[/code\]~', "", $var))))
{
echo 'Please add some text...';
} else {
// empty code tags
if(preg_match('~\[code\]\s*\[/code\]~', $var))
{
echo 'The code tags can not be empty!';
// fine
} else {
echo "wohoOoo it works!";
}
}

PHP preg_replace: Need to modify hyperlink text if hyperlink contains 'youtube.com'

I'm almost there!
Here is the string I am trying to adjust, and my preg_replace attempt.
$description_string = '<p>Here is the test link: “Man or Muppet” with other text afterwards.</p>';
$description = preg_replace( '/(<a[^>]+youtube[^>]*>)+[^"]*(<\/a>)+/', '$0Watch This Video$2', $description );
The result I'm getting is incorrect:
Here is the test link: “Man or Muppet”Watch This Video with other text afterwards.
Any help would be greatly appreciated! THanks!
Well, not sure if you are trying to get the actual title in there. But here is what I came up with:
<?php
$description_string = '<p>Here is the test link: \'Man or Muppet\' with other text afterwards.</p>';
$description = preg_replace( '/(<a[^>]+youtube[^>]*>)+[^"]*(<\/a>)+/', '$1Watch This Video$2', $description_string );
echo $description;
?>
Result:
<p>Here is the test link: Watch This Video with other text afterwards.</p>
Your biggest issue was with the quotes (") being in the title. It is cutting off the anchor tags. While using $0 is also incorrect. You'll need to use $1.
This may not be exactly what you need, but its a quick monkey patch for you.

Input of email and url to be clickable

I have a form that I process in PHP. Users sometimes put their email address in the form or URLs. These usually come out as text after I strip the input of tags.
Recently my users started asking me to make their URLs and emails clickable when they pull up a page that displays their input (now pulled from a db).
Could someone please suggest a common pattern or ways that this is handled? Basically, if someone enters a url in a form, how do I make the url clickable instead of text when viewed?
Thanks,
Alex
You can use a regular expression based function like this
function autolink($message) {
//Convert all urls to links
$message = preg_replace('#([\s|^])(www)#i', '$1http://$2', $message);
$pattern = '#((http|https|ftp|telnet|news|gopher|file|wais):\/\/[^\s]+)#i';
$replacement = '$1';
$message = preg_replace($pattern, $replacement, $message);
/* Convert all E-mail matches to appropriate HTML links */
$pattern = '#([0-9a-z]([-_.]?[0-9a-z])*#[0-9a-z]([-.]?[0-9a-z])*\\.';
$pattern .= '[a-wyz][a-z](fo|g|l|m|mes|o|op|pa|ro|seum|t|u|v|z)?)#i';
$replacement = '\\1';
$message = preg_replace($pattern, $replacement, $message);
return $message;
you have to wrap the url in a anchor tag:
assuming $myLink is the link text coming from your db:
<?php echo $myLink; ?>

Categories