Login or create new account.

By registering on joomprod.com, you will have immediate access to all our free products and to the public side of our support forum.

Enjoy our subscriptions.

Each of our subscriptions allow you to enjoy the private side of the support forum and all the update of our products for a period ranging from 3 months to 1 year.

Payment And immediate download.

After subscribing to one of our subscription, the products are immediately downloadable.

Login

Or Register
Accueil / forum / Support / AdsManager Support / Detect hyperlinks in description fields

Support Availability Because we must sleep sometimes

Working days: Monday to Friday.
Reply time: Depending on the complexity of your support issue it's usually between a few hours to 48 hours.

Support is only guaranteed to paid subscribers

AdsManager - End of life

It is with great regrets that we have chosen to end the developpement of Adsmanager and its other associated components.

AdsManager is born 10 years ago and, as of today, the number of new subscriptions and downloads have fallen and we cannot maintain the component anymore.

All active subscribers will be able to continue enjoying support until the end of their subscription.

The components will be free and no support will be provided anymore for the other users.

×

Notice

The forum is in read only mode.

Detect hyperlinks in description fields

More
11 years 6 months ago #1685 by kristel
Hi,
When user post an ad, all "Description" fields (textearea) are recorded as plain text.
When the user writes a URL in the description field, I need the frontend to display hyperlinks.

So, I updated the following file to globally detect URLs in this type of field:
components/com_adsmanager/helpers/field.php

I would like to contribute to this module and provide my code in order to get it in the next release ;-) and make it useful for the community.

How should I proceed?

Thanks.
The following user(s) said Thank You: adarr
More
11 years 6 months ago #1702 by loic
Replied by loic on topic Detect hyperlinks in description fields
Hello,

You can write the modified lines directly in the forum by using the code tag.

If your modification is too big, you can send us an email with the file attached.
The following user(s) said Thank You: adarr
More
11 years 6 months ago - 11 years 6 months ago #1718 by kristel
Replied by kristel on topic Detect hyperlinks in description fields
Ok sure,

So to display hyperlinks automatically in your ads, simply locate the file:
components/com_adsmanager/helpers/field.php

and add the following methods where ever you want in the class JHTMLAdsmanagerField:

Note: I simplified my method absolute_url() to keep it simple, but at least this gives you some guide lines.
function array_field($ar, $field) {
  $a = array();
  foreach($ar as $r) array_push($a, $r[$field]);
  return $a;
}
function absolute_url($uri, $external=false, $param=false) {
  if(!preg_match("#^https?://#i", $uri)) {
    $uri = "http://$uri";
  }
  return  $uri;
}
 
function htmlize_links($s) {
  preg_match_all("#(?!<=\S)(https?://)?(www\.)?[a-z0-9\.\-]+\.(com|org|edu|net|us|gov|uk|name|info|gl)(/\S*)?#i", $s, $matches, PREG_SET_ORDER);
  if($matches) {
    $links = $this->array_field($matches, 0);
    foreach($links as $i => $link) $links[$i] = preg_replace('/[\)\]]+$/', '', $link);
    $links = array_unique($links);
    foreach($links as $l) {
      $url      = $this->absolute_url($l);
      $link     = "<a href='$url' target='_blank'>$l</a>";
      $regexp   = "|(?!<=\S)".preg_quote($l, '|')."(?=[\s\)])|";
      $s        = preg_replace($regexp, $link, $s);
    }
  }
  return $s;
}

and in the method showFieldValue(), search for
case 'textarea':
                    $return .= str_replace(array("\r\n", "\n", "\r"), "<br />", $value);
                    break;

and replace it by
case 'textarea':
                    $return .= str_replace(array("\r\n", "\n", "\r"), "<br />", $this->htmlize_links($value));
                    break;
[

Hope this can help someone and this would be fantastic if you can package it with a switch in the backend UI :-)

Thanks

JT
Last edit: 11 years 6 months ago by kristel. Reason: removed a debug line
The following user(s) said Thank You: wafa, adarr
More
11 years 6 months ago #1735 by loic
Replied by loic on topic Detect hyperlinks in description fields
Hello,

Thank you for the improvement.

Maybe you will find it in the next versions ;) .
The following user(s) said Thank You: adarr
More
10 years 11 months ago #5128 by nemgtr_webmanager
Replied by nemgtr_webmanager on topic Detect hyperlinks in description fields
This update to the functionality would be so helpful for the "non programmers" out there who need this feature. Please consider it for the next release.
The following user(s) said Thank You: adarr
Time to create page: 0.125 seconds
Powered by Kunena Forum