Niedawno dodałem do Sugar'a funkcje tablicy, gdzie użytkownicy mogą wysłać między sobą wiadomości widoczne dla wszystkich itd.

Znalazłem gotową bibliotekę do tego

https://github.com/salesagility/SuiteCRM/tr...dules/SugarFeed

Zależy mi na tym, żeby po wklejeniu linku z youtube'a i po kliknięciu 'send' na tablicy wyświetlała się miniatura tego linku, podobnie jeżeli chodzi o zdjęcie. Czytałem na tej stronie że w tym kodzie jest to już zawarte ale u mnie to nie działa. Wkleja linki bez miniaturek, niezależnie od tego czy to link do yt czy zdjęcie.

Macie jakiś pomysł ? Albo widzicie błąd w kodzie? Nie za bardzo poruszam się jeszcze w php.

Żebyście nie musieli grzebać w tej bibliotece tutaj są 2 kody odpowiedzialne za to:

Kod do miniaturki z yt
  1. require_once('modules/SugarFeed/linkHandlers/Link.php');
  2.  
  3. class FeedLinkHandlerYoutube extends FeedLinkHandlerLink {
  4. function getDisplay(&$data) {
  5. return '<div style="padding-left:10px"><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/' . $data['LINK_URL'] . '&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="wmode" value="opaque" /><embed src="http://www.youtube.com/v/' . $data['LINK_URL'] . '&hl=en&fs=1" type="application/x-shockwave-flash" allowfullscreen="true" wmode="opaque" width="425" height="344"></embed></object></div>';
  6. }
  7.  
  8. function handleInput($feed, $link_type, $link_url) {
  9. $match = array();
  10. preg_match('/v=([^\&]+)/', $link_url, $match);
  11.  
  12. if(!empty($match[1])){
  13. $feed->link_type = $link_type;
  14. $feed->link_url = $match[1];
  15. }
  16. }


Kod wyświetlający zdjęcie.
  1.  
  2. require_once('modules/SugarFeed/linkHandlers/Link.php');
  3.  
  4. class FeedLinkHandlerImage extends FeedLinkHandlerLink {
  5. function getDisplay(&$data) {
  6. $imageData = unserialize(base64_decode($data['LINK_URL']));
  7. if ( $imageData['width'] != 0 ) {
  8. $image_style = 'width: '.$imageData['width'].'px; height: '.$imageData['height'].'px; border: 0px;';
  9. } else {
  10. // Unknown width/height
  11. // Set it to a max width of 425 px, and include a tweak so that IE 6 can actually handle it.
  12. $image_style = 'width: expression(this.scrollWidth > 425 ? \'425px\':\'auto\'); max-width: 425px;';
  13. }
  14. return '<div style="padding-left:10px"><img src="'. $imageData['url']. '" style="'.$image_style.'"></div>';
  15. }
  16.  
  17. function handleInput($feed, $link_type, $link_url) {
  18. parent::handleInput($feed, $link_type, $link_url);
  19.  
  20. // The FeedLinkHandlerLink class will help sort this url out for us
  21. $link_url = $feed->link_url;
  22.  
  23. $imageData = @getimagesize($link_url);
  24.  
  25. if ( ! isset($imageData) ) {
  26. // The image didn't pull down properly, could be a link and allow_url_fopen could be disabled
  27. $imageData[0] = 0;
  28. $imageData[1] = 0;
  29. } else {
  30. if ( max($imageData[0],$imageData[1]) > 425 ) {
  31. // This is a large image, we need to set some specific width/height properties so that the browser can scale it.
  32. $scale = 425 / max($imageData[0],$imageData[1]);
  33. $imageData[0] = floor($imageData[0]*$scale);
  34. $imageData[1] = floor($imageData[1]*$scale);
  35. }
  36. }
  37.  
  38. $feed->link_url = base64_encode(serialize(array('url'=>$link_url,'width'=>$imageData[0],'height'=>$imageData[1])));
  39. }
  40. }