This makes URL clickable and youtube URL embed in post

Am Ghaz Posted in Technical Support 1 decade 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 = preg_replace('(f|ht)tps?://[A-Za-z0-9./?=+&%_]+', '<a target="_blank" href="$0">$0</a>', $out);
echo $clickable;

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

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

}
?>

That's all.

I answered to the topic also here

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

Replies
Indonesian Arsalan Shah Replied 7 months ago

@Alfie you can use custom site pages or HTML side bar with custom code you can embed using admin panel

ph Alfie Ocana Replied 7 months ago

Is there a way we can embed online radio music player ?

Am Ghaz Replied 1 decade ago

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

echo "&lt;h2 style=&quot;color: #9BA9CF&quot;&gt; "; 
 
$url = preg_replace("*(f|ht)tps?://[A-Za-z0-9\./?=\+&amp;%_-]+*", "&lt;a target=&quot;_blank&quot; href=&quot;$0&quot;&gt;$0&lt;/a&gt;", $out); 
  $urlContents = file_get_contents($out);
 
 preg_match(&quot;/&lt;title&gt;(.*)&lt;\/title&gt;/i&quot;, $urlContents, $matches);
  print($matches[1] . &quot;\n&quot;)    ;  
 

 echo "&lt;/h2&gt;";
ng Moneya Replied 1 decade ago

@sathis kumar would that be available for 2.0

in Sathish kumar Replied 1 decade ago

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

Am Ghaz Replied 1 decade ago

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

ng Moneya Replied 1 decade ago

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

Am Ghaz Replied 1 decade ago

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

$width = '400';
$height = '270'; 
Ravi kumar Replied 1 decade ago

hi it's wonder .

that code works for me

thanks alot

in Sathish kumar Replied 1 decade ago

we will work on it thanks for the code ..