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
Am Ghaz Replied 1 decade ago
Am Ghaz Replied 1 decade 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

Am Ghaz Replied 1 decade ago

OK, corrected, will not fall with this:

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

German Michael Zülsdorff Replied 1 decade ago

Well, I'm no regular expression wizzard, but with

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

it's obvious that urls like 'http://community.opensource-socialnetwork.org' will fall through.

Anyway, thanks for providing the idea.

Am Ghaz Replied 1 decade ago

the script ofnthis site preventing from posting php codes,html divs etc here

so see 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

Am Ghaz Replied 1 decade ago
Scroll to:   
   <div class="description">
            <div class="post-text"><?php echo stripslashes($params['text']); ?>

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('/[\\?\\&]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>';

} 
 ?>  
Premium Version

Due to the many requests in the past for additonal features and components we have decided to develope a premium version. Features like Hashtags, Videos, Polls, Events, Stories, Link Preview, etc included in it.

$199 (Life Time)
Learn More

Other Questions