Browse Source

- Fix others warnings

- Don't display a link if the contact URL is not valide
pull/16/head
Jaussoin Timothée 12 years ago
parent
commit
60411a3684
  1. 18
      app/widgets/ContactCard/ContactCard.php
  2. 6
      app/widgets/ContactSummary/ContactSummary.php
  3. 4
      app/widgets/WidgetCommon/WidgetCommon.php
  4. 53
      system/Utils.php

18
app/widgets/ContactCard/ContactCard.php

@ -84,11 +84,19 @@ class ContactCard extends WidgetCommon
<label for="url">'.t('Email').'</label>
<a target="_blank" href="mailto:'.$contact->email.'">'.$contact->email.'</a>
</div>';
if($this->testIsSet($contact->url))
$html .= '<div class="element simple">
<label for="url">'.t('Website').'</label>
<a target="_blank" href="'.$contact->url.'">'.$contact->url.'</a>
</div>';
if($this->testIsSet($contact->url)) {
if(filter_var($contact->url, FILTER_VALIDATE_URL)) {
$html .= '<div class="element simple">
<label for="url">'.t('Website').'</label>
<a target="_blank" href="'.$contact->url.'">'.$contact->url.'</a>
</div>';
} else {
$html .= '<div class="element simple">
<label for="url">'.t('Website').'</label>
'.$contact->url.'
</div>';
}
}
if($this->testIsSet($contact->desc) && prepareString($contact->desc) != '')
$html .= '<div class="element large simple">

6
app/widgets/ContactSummary/ContactSummary.php

@ -52,7 +52,9 @@ class ContactSummary extends WidgetCommon
$presencetxt = getPresencesTxt();
// Contact general infos
$html .= '
if(isset($contact->presence))
$html .= '
<h1 class="'.$presencetxt[$contact->presence].'">'.$contact->getTrueName().'</h1>';
if($this->testIsSet($contact->name))
@ -63,7 +65,7 @@ class ContactSummary extends WidgetCommon
if($this->testIsSet($contact->url))
$html .= '<br /><a target="_blank" href="'.$contact->url.'">'.$contact->url.'</a>';
if($this->testIsSet($contact->status)) {
if(isset($contact->status)) {
$html .= '
<div class="textbubble">
'.prepareString($contact->status).'

4
app/widgets/WidgetCommon/WidgetCommon.php

@ -92,13 +92,15 @@ class WidgetCommon extends WidgetBase {
if($post->tags)
$tags = $this->printTags($post->tags);
if($enc)
if(isset($enc))
$enc = '
<div class="enclosure">'.
$enc.
'
<div class="clear"></div>
</div>';
else
$enc = '';
$content = prepareString(html_entity_decode($post->content));

53
system/Utils.php

@ -85,9 +85,11 @@ function prepareString($string) {
$string = str_replace('<a ', '<a target="_blank" ', $string);
$string = str_replace('<iframe', '', $string);
//$string = preg_replace('/<iframe.*?\/iframe>/i','', $string);
$string = preg_replace(
/*
* OLD VERSION preg_replace with EVAL ( :o ! )
*
$string = preg_replace(
array(
'/(^|\s|>)(www.[^<> \n\r]+)/iex',
'/(^|\s|>)([_A-Za-z0-9-]+(\\.[A-Za-z]{2,3})?\\.[A-Za-z]{2,4}\\/[^<> \n\r]+)/iex',
@ -101,8 +103,52 @@ function prepareString($string) {
''
),
' '.$string
);
);*/
//replace begin by www
$string = preg_replace_callback(
'/(^|\s|>)(www.[^<> \n\r]+)/ix', function ($match) {
//print '<br />preg[1]';\system\Debug::dump($match);
if (strlen($match[2])>0) {
return stripslashes($match[1].'<a href=\"http://'.$match[2].'\" target=\"_blank\">'.$match[2].'</a>');
} else {
return $match[2];
}
}, ' ' . $string
);
//replace begin by http - https (before www)
$string = preg_replace_callback(
'/(?(?=<a[^>]*>.+<\/a>)(?:<a[^>]*>.+<\/a>)|([^="\'])((?:https?):\/\/([^<> \n\r]+)))/ix', function ($match) {
//print '<br />preg[2]';\system\Debug::dump($match);
if (isset($match[2]) && strlen($match[2])>0) {
return stripslashes($match[1].'<a href=\"'.$match[2].'\" target=\"_blank\">'.$match[3].'</a>');
} else {
return $match[0];
}
}, ' ' . $string
);
//what the fuck it is ???!!!
/*$string = preg_replace_callback(
'/(^|\s|>)([_A-Za-z0-9-]+(\\.[A-Za-z]{2,3})?\\.[A-Za-z]{2,4}\\/[^<> \n\r]+)/ix', function ($match) {
//print '<br />preg[3]';\system\Debug::dump($match);
if (isset($match[2]) && strlen($match[2])>0) {
return stripslashes($match[1].'<a href=\"http://'.$match[2].'\" target=\"_blank\">'.$match[2].'</a>');
} else {
return $match[2];
}
}, ' ' . $string
);*/
//remove all scripts
$string = preg_replace_callback(
'#<[^>]*script[^>]*>#is', function ($match) {
return '';
}, ' ' . $string
);
// We add some smileys...
$conf = new Conf();
$theme = $conf->getServerConfElement('theme');
@ -114,7 +160,6 @@ function prepareString($string) {
$string = preg_replace('/(^|[ ])('.$key.')/', $replace, $string);
}
//return '';
return trim($string);
}

Loading…
Cancel
Save