Keyword

Turning URL comments field into a text field

  • Pedro Lima
  • Pedro Lima's Avatar Topic Author
  • Offline
  • New Member
More
11 years 2 months ago #115980 by Pedro Lima
Hi,

I've just registered to post this here because so many times I search for things online and if only people that find solutions always posted the solution, let's say that the online world would be a better world. :D

I changed the "Comments" of K2 to "Request Quote". Then I changed the option to not auto approve the comments.

Then I wanted to receive a new email whenever someone would post a comment, so I downloaded this: getk2.org/extend/extensions/1242-bnr-comment-notify-for-k2

After that, I tried everything and it was just (almost) perfect... just one thing was not right. Instead of the URL, I wanted to have that field changed to "Phone number".

The problem was, there's a checking procedure on the code which validates if the URL is valid or not! And that's a problem...

So I went digging!

I found that for K2, the solution is this:

1. On your server, by FTP or Local Directory on your cpanel, sphere, etc., go to the root of your site and then follow this path: components/com_k2/models
2. Create a copy of the file "item.php" (name it, e.g. "ORIGINAL_item.php")
3. Download the file to your PC
4. Open the file with a TXT editor, Dreamweaver or other
5. Find this code starting on line 1101:
if ($row->commentURL && preg_match('/^((http|https|ftp):\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6}((:[0-9]{1,5})?\/.*)?$/i', $row->commentURL))
{
        $url = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $row->commentURL);
        $url = str_replace(';//', '://', $url);
        if ($url != '')
        {
                $url = (!strstr($url, '://')) ? 'http://'.$url : $url;
                $url = preg_replace('/&([^#])(?![a-z]{2,8};)/', '&$1', $url);
                $row->commentURL = $url;
        }
}
6. Change it to this:
if ($row->commentURL)
{
        if ($url != '')
        {
                $row->commentURL = $url;
        }
}
7. Find this code starting on line 1227:
if (substr($commentURL, 0, 7) != 'http://')
{
        $row->commentURL = 'http://'.$commentURL;
}
8. Change it to this:
$row->commentURL = $commentURL;

So now I had deleted the validation for the URL and inside admin panel it appears the phone number (or whatever we write on that simple text field).

But wait, there's another problem!

On the email that I receive when a new comment is inserted, the text I insert on URL field doesn't appear inside email.

So then there's these changes to be done:

Same proceedure as for the "item.php", create a copy and the file is located here: ROOT/plugins/system/brn_k2comment_notify

File name is: "brn_k2comment_notify.php"

As I said, same proceedure as for the previous file but in lines 176 for the first change and 245 for the second code change.

And this is it, I have the email warning each time someone fulfil the "Request Quote" and I can even know for which product that person is requesting quote. :)

I hope this can be useful for someone in the future.

Thank you.

Best regards,
Pedro Lima

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum