Julio Montoya 10 years ago
parent aba8fea952
commit 2cad61f986
  1. 9
      main/inc/ajax/social.ajax.php
  2. 67
      main/inc/lib/social.lib.php

@ -213,6 +213,15 @@ switch ($action) {
echo $html;
}
break;
// Read the Url using OpenGraph and returns the hyperlinks content
case 'readUrlWithOpenGraph':
$url = isset($_POST['social_wall_new_msg_main']) ? $_POST['social_wall_new_msg_main'] : '';
$html = '';
if (SocialManager::verifyUrl($url) == true){
$html = Security::remove_XSS(SocialManager::readContentWithOpenGraph($url));
}
echo $html;
break;
default:
echo '';
}

@ -1250,7 +1250,6 @@ class SocialManager extends UserManager
//Just in case we replace the and \n and \n\r while saving in the DB
$messageContent = str_replace(array("\n", "\n\r"), '<br />', $messageContent);
$cleanMessageContent = Database::escape_string($messageContent);
$attributes = array(
'user_sender_id' => $userId,
@ -1258,7 +1257,7 @@ class SocialManager extends UserManager
'msg_status' => $messageStatus,
'send_date' => api_get_utc_datetime(),
'title' => '',
'content' => $cleanMessageContent,
'content' => $messageContent,
'parent_id' => $messageId
);
@ -1549,7 +1548,7 @@ class SocialManager extends UserManager
$html .= '<div class="img-post">';
$html .= $wallImage;
$html .= '</div>';
$html .= '<p>'. Security::remove_XSS(self::readContentWithOpenGraph($message['content'])).'</p>';
$html .= '<p>'. Security::remove_XSS($message['content']).'</p>';
$html .= '</div>';
$html .= '</div>'; // end mediaPost
@ -1566,19 +1565,14 @@ class SocialManager extends UserManager
// search link in first line
$regExUrl = "/(http|https)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
$newText = '';
$count = 0;
if(preg_match($regExUrl, $text, $url)) {
if (preg_match($regExUrl, $text, $url)) {
// make the urls hyper links
$newText .= preg_replace($regExUrl, "<a target=\"_blank\" href=" . $url[0] . ">".$url[0]."</a> ", $text);
if ($count == 0) {
// Comment this line to disable OpenGraph
//$newText .= self::getHtmlByLink($url[0]);
}
$count++;
// Comment this line to disable OpenGraph
$newText .= self::getHtmlByLink($url[0]);
} else {
$newText .= $text;
}
return $newText;
}
@ -1590,16 +1584,51 @@ class SocialManager extends UserManager
public static function getHtmlByLink($link)
{
$graph = OpenGraph::fetch($link);
$url = $graph->url;
$image = $graph->image;
$domain = empty($url) ? parse_url($link) : parse_url($url);
$domain = $domain['scheme'].'://'.$domain['host'];
// Trick to verify if the Image Url Exist because of some bad metatag dev
if (self::verifyUrl($image) == false){
if (!($image[0] == '/')){
$domain = $domain . '/';
}
$image = $domain . $image;
}
$title = $graph->title;
$html = '<div>';
$html = '<div class="thumbnail">';
$html .= '<a target="_blank" href="'.$link.'"><h3>'.$title.'</h3>';
$html .= empty($graph->image) ? '' : '<img alt="" src="'.$graph->image.'" height="160" ></a>';
$html .= empty($image) ? '' : '<img alt="" src="'.$image.'" height="160" ></a>';
$html .= empty($graph->description) ? '' : '<div>'.$graph->description.'</div>';
$html .= "</div>";
return $html;
}
/**
* verify if Url Exist - Using Curl
* @param $uri url
*
* @return boolean
*/
public static function verifyUrl($uri)
{
$curl = curl_init($uri);
curl_setopt($curl, CURLOPT_FAILONERROR, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 15);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
$response = curl_exec($curl);
curl_close($curl);
if (!empty($response)) {
return true;
} else {
return false;
}
}
/**
* Get full image path from a path and a size
@ -1841,7 +1870,15 @@ class SocialManager extends UserManager
array('enctype' => 'multipart/form-data')
);
$form->addTextarea('social_wall_new_msg_main', null, array('placeholder' => get_lang('SocialWallWhatAreYouThinkingAbout')));
$form->addTextarea(
'social_wall_new_msg_main',
null,
[
'placeholder' => get_lang('SocialWallWhatAreYouThinkingAbout'),
'style' => 'width : 100%'
]
);
$form->addHidden('url_content', '');
$form->addButtonSend(get_lang('Post'));
$html = Display::panel($form->returnForm(), get_lang('SocialWall'));

Loading…
Cancel
Save