This makes URL clickable and youtube URL embed in post

Am Ghaz Posted in Technical Support 9 years ago

I share my own code that makes URL clickable and youtube URL embed in post in ossn script

  1. Open this file:
    /components/OssnWall/templates/activity-item.php

  2. Scroll to:
    <div class="description">
    <div class="post-text"><?php echo stripslashes($params['text']); ?>

  3. Replace it with this:

    <div class="description">
    <div class="post-text">
    <?php // $out = $params['text'];
    $out = stripslashes($params['text']);

$clickable = pregreplace('*(f|ht)tps?://[A-Za-z0-9./?=+&%]+*', '<a target="_blank" href="$0">$0</a>', $out);
echo $clickable;

if (strpos($clickable,'youtube.com')) {

preg_match(
        '/[\?\&]v=([^\?\&]+)/',
        $clickable,
        $matches
    ); 
$id = $matches[1]; 
$width = '400';
$height = '270'; 
echo '<div><br><iframe frameborder="0" class="youtube" width="' .$width. '" height="'.$height.'" src="//www.youtube.com/embed/'.$id.'" frameborder="0" allowfullscreen></iframe></div>';

}
?>

That's all.

I answered to the topic also here

https://ekav.info/question-answer/index.php?qa=5&qa_1=how-to-make-url-clickable-and-youtube-url-embed-with-php-code

Replies
Am Ghaz Replied 9 years ago

meanwhile you can add the code below to that part of code I offered for adding title of url

echo '<h2 style="color: #9BA9CF"> '; 

$url = preg_replace('*(f|ht)tps?://[A-Za-z0-9\./?=\+&%_-]+*', '<a target="_blank" href="$0">$0</a>', $out); 
  $urlContents = file_get_contents($out);

 preg_match("/<title>(.*)<\/title>/i", $urlContents, $matches);
  print($matches[1] . "\n")    ;  


 echo '</h2>';
ng Moneya Replied 9 years ago

@sathis kumar would that be available for 2.0

in Sathish kumar Replied 9 years ago

dont modify the core . we are developing it with something different

Am Ghaz Replied 9 years ago

good idea, I will try to find time tomorrow to generate the script :-)

ng Moneya Replied 9 years ago

@am Ghaz how about generating thumbnail from url...

Am Ghaz Replied 9 years ago

sure, these fields are custom, you can change the values for the player:

$width = '400';
$height = '270'; 
Ravi kumar Replied 9 years ago

hi it's wonder .

that code works for me

thanks alot

in Sathish kumar Replied 9 years ago

we will work on it thanks for the code ..

Am Ghaz Replied 9 years ago
Am Ghaz Replied 9 years ago

Because the script on this wraps some characters
I prepared this text file to view full instructions
click to download:

http://ekav.info/l/33