MyBB Community Forums

Full Version: Replace raw url text to title
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5
Hello guys..

I finally decided to make this as code edits and NOT a plugin.. keeping in mindeverything that conflicts the plugin...

See Below :

Edits :
  • Find the lines below in inc/class_parser.php

    /*
    options = array(
    	allow_html
    	allow_smilies
    	allow_mycode
    	nl2br
    	filter_badwords
    	me_username
    	shorten_urls
    )
    */

    Now, Add the code below after the found lines

    function urltitlefind($link, $text='')
    	{
    		// Ensure $link is a valid URL        
    		$url = $link;
    		
    		$fp = @fopen($url, 'r');
    		if (!$fp) {
    			$title = (!$text ? $link : $text);
    			return "(Broken Link)";
    		}
    
    		// Grab <title>*</title> from the first "chunk" of data
    		$title = url_grab_title($fp);
    
    		// No <title> tag in first chunk...    
    		if (!$title) {
    			$title = (!$text ? $link : $text);
    			return "<a href='$url'>::Link (no title found)::</a>";
    		}
    
    		// User gave me some text to append to the link title
    		if ($text) {    
    			$title .= ': '. $text;
    		}
    		
    		return $title;
    	}
    
    function url_grab_title($fp)
    	{
    		// How many bytes to grab in one chunk.
    		// Most sites seem to have <title> within 512
    		$chunk_size = 512;
    
    		$chunk = fread($fp, $chunk_size);
    		$chunk = preg_replace("/(\n|\r)/", '', $chunk);
    
    		// Look for <title>(.*?)</title> in the text
    		if (preg_match('/<title>(.*?)<\/title>/i', $chunk, $matches)) {
    			return $matches[1];
    		}
    
    		return null;
    	}

  • Now, Find the code below in the same file

    $name = $url;

    Replace this with the code below :

    $name = urltitlefind($url);

  • For Link Checking

    Files on the following websites will be checked :

    Quote:rapidshare.com
    megaupload.com
    megashares.com
    sendspace.com
    rapidshare.de
    mediafire.com
    • Find the code below in the Same file

      $fullurl = strtr($fullurl, array('$' => '%24', '^' => '%5E', '`' => '%60', '[' => '%5B', ']' => '%5D', '{' => '%7B', '}' => '%7D', '"' => '%22', '<' => '%3C', '>' => '%3E', ' ' => '%20'));

      Add the code below after the found code

      	if(strstr($fullurl,"rapidshare.com")){
      		$var = file_get_contents($fullurl);
      		$checked = $checked + 1;
      		if(strpos($var,"FILE DOWNLOAD")){
      		$status =  " <font color=\"green\">(file found!)<br></font>";
      		$working = $working + 1;
      		}
      		if(strpos($var,"The file could not be found")){
      		$status =  " <font color=\"red\">(file not found!)<br></font>";  
      		}	  
      		if(strpos($var," deleted.")){
      		$status =  "  <font color=\"red\">(file deleted!)<br></font>";
      		}
      
      
      	} elseif (strstr($fullurl,"megaupload.com")){
      		$var1 = file_get_contents($fullurl);
      		$checked = $checked +1;
      		if(strpos($var1,"Please enter")){
      			$status =  " <font color =\"green\">(file found!)<br></font>";
      			$working = $working + 1;
      		}
      		if(strpos($var1,"Unfortunately, the link you have clicked is not available.")){
      			$status =  " <font color =\"red\">(file not found!)<br></font>";	
      		}
      		
      	} elseif (strstr($fullurl,"megashares.com")){
      		$var2 = file_get_contents($fullurl);
      		$checked = $checked +1;
      		if(strpos($var2,"Filename:")){
      			$status =  " <font color =\"green\">(file found!)<br></font>";
      			$working = $working + 1;
      		}
      		if(strpos($var2,"Welcome to Megashares")){
      			$status =  " <font color =\"red\">(file not found!)<br></font>";	
      		}
      		if(strpos($var2,"have the correct URL")){
      			$status =  " <font color =\"red\">(file not found!)<br></font>";	
      		}
      		
      	} elseif (strstr($fullurl,"sendspace.com")){
      		$var3 = file_get_contents($fullurl);
      		$checked = $checked +1;
      		if(strpos($var3,"404 Page Not Found")){
      			$status =  " <font color =\"red\">(file not found!)<br></font>";	
      		
      		} elseif(strpos($var3,"Sorry, the file you requested is not available.")){
      			$status =  " <font color =\"red\">(file not found!)<br></font>";	
      		} else {
      			$status =  " <font color =\"green\">(file found!)<br></font>";
      			$working = $working + 1;
      			}
      	} elseif(strstr($fullurl,"rapidshare.de")){
      		$var5 = file_get_contents($fullurl);
      		$checked = $checked + 1;
      		if(strpos($var,"You want to download the file ")){
      		$status =  " <font color=\"green\">(file found!)<br></font>";
      		$working = $working + 1;
      		}
      		if(strpos($var,"File not found.")){
      		$status =  " <font color=\"red\">(file not found!)<br></font>";  
      		}	  
      		if(strpos($var," deleted.")){
      		$status =  " <font color=\"red\">(file deleted!)<br></font>";
      		}
      		
      	} elseif (strstr($fullurl,"mediafire.com")){
      		$var4 = file_get_contents($fullurl);
      		$checked = $checked +1;
      		if(strpos($var4,"Sharing")){
      			$status =  " <font color =\"green\">(file found!)<br></font>";	
      			$working = $working + 1;
      		}
      		if(strpos($var4,"Invalid Quickkey.")){
      			$status =  " <font color =\"red\">(file not found!)<br></font>";	
      		}
      		if(strpos($var4,"I want to upload")){
      			$status =  " <font color =\"red\">(file not found!)<br></font>";	
      		}
      	} else {
      		$status =  "";	
      	}


    • Find this code in the Same File :

      $link = "<a href=\"$fullurl\" target=\"_blank\">$name</a>";

      Replace this with :

      $link = "<a href=\"$fullurl\" target=\"_blank\">$name</a> -".$status;


Preview :

[Image: or2z4x.jpg]


This will replace any links inserted without a given title, that is like http://www.google.com/ to its title as text, that is, it will be shown as Google
This plugin looks promising and very useful to identify post links easier!

I have a few questions:
1) Can you explain what you mean by "It also, adds any text given by user."
2) What happens if you click the last post link?
3) What happens if you click a permalink of the post (post #)?
(2009-06-23, 08:31 PM)Mushu Wrote: [ -> ]This plugin looks promising and very useful to identify post links easier!

I have a few questions:
1) Can you explain what you mean by "It also, adds any text given by user."
2) What happens if you click the last post link?
3) What happens if you click a permalink of the post (post #)?


Mushu , This plugin is only for links in a post and not the whole forum links. (It would be awful if i do it for the whole forum and every linked text would be more than 20 chars long which spoils the forum's look)

By Saying "It also, adds any text given by user." I mean it adds the user's text after the title as below (the mod is not installed here and this is just a demo) :

Code:
[url=http://www.google.com/]UserText[/url]

Result : Google : UserText

EDIT : And any Moderators here, please change the topic's title and link in the forum to "[Release for mybb 1.4.x] Append Url Title to its text"
Oh this is cool
Thank you Sushruth! I will find this very useful! Wink
Very Very good Idea..!

Its promissing and have a great potential on its own...!

Keep it up
Good, i was looking for something like this Smile

This consume bandwith for my server? Or Excessive resources (querys, etc)?
(2009-06-24, 02:07 PM)rafaweb Wrote: [ -> ]Good, i was looking for something like this Smile

This consume bandwith for my server? Or Excessive resources (querys, etc)?

Actually, a post does not contain more than 20 links right ?

it does not affect the page loading time untill there are more than 25-30 links in a single post of a thread.
Again new release :

UPDATE :

Fixed some bugs (major)

and some stupid code (lol)

changed version number to 0.3 Smile


ONE MORE UPDAET IN 5 MINS NOW Smile

FIXED : Clash with auto url parse
Very good, Thanks sushruth

Keep it up
Pages: 1 2 3 4 5