Jump to content

php url detection


Silencez

Recommended Posts

<?php
 
if (!defined("IN_PASTE"))
      die("Access denied!");
 
/*
Plugin Name: Pastes links
Plugin URI: http://php-pastebin.com/
Description: Get link of paste
Version: 1.0
Author: Atmoner
Author URI: http://php-pastebin.com/
*/
 
//set plugin id as file name of plugin
$plugin_id = basename(__FILE__);
 
//some plugin data
$data['name'] = "Pastes links";
$data['author'] = "Atmoner";
$data['url'] = "http://php-pastebin.com/";
 
//register plugin data
register_plugin($plugin_id, $data);
 
//Hook , where to execute a function homeblock()
add_hook('paste_page','pasteLinks');
 
// Hook function
function pasteLinks() {
	global $hook,$startUp,$smarty;

	// Parse code in geshi lib
	include_once('libs/geshi/geshi.php');
	$id = (isset($_GET["id"])?$_GET["id"]:"");
	$p = $startUp->getPaste($id);

	if (!empty($p)) {

	// The Regular Expression filter
	$reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
	 var_dump($p['paste']);
	// Check if there is a url in the text
	if(preg_match($reg_exUrl, $p['paste'], $url)) { 
		    $paste = preg_replace( '/(http|ftp)+(s)?\/\/)((\w|\.)+)(\/)?(\S+)?/i', '<br /><a href="\0" target="_BLANK">\0</a>', $p['paste'] );
		$smarty->assign("result",$paste);
		$smarty->assign("getPaste",$p);
	} else {
	$geshi = new GeSHi(html_entity_decode(htmlspecialchars_decode($p['paste'])), $p['lang']);
	$geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS);
	$geshi->set_header_type(GESHI_HEADER_DIV); 
	$geshi->set_case_keywords(GESHI_CAPS_LOWER);
	$geshi->set_footer_content('Parsed in <TIME> seconds');
	 
	$paste = $geshi->parse_code();
	$smarty->assign("getPaste",$p);
	}



	// Update hits
	$startUp->updateHits($id);
	} 


	$hook->remove_addcontentpaste('defaultpaste');
	$hook->addcontentPaste('name_content',$paste,2);
}

Tho'

Currently the Code creates spacing with plain text what rolls over the site

Any idea on changes to make it compatible with plain text as well ?

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.