Recent Topics

[HACK-01-1.9.2-oradoe] Optimzing pemanent link

Started by on Feb 07, 2007 – Contents updated: Feb 07, 2007

Feb 07, 2007 12:09    

Features:
[list]

  • Fixing non-ansi chararters. Eg: [url=http://server.com/Tr%E1%BA%A7n_Nguy%E1%BB%85n_Tr%C6%B0%E1%BB%9Dng_Sinh]http://server.com/Trần_Nguyễn_Trường_Sinh[/url] instead of http://server.com/Tr__7847_n_Nguy__7877_n_Tr__432___7901_ng_Sinh

  • Fixing increasing number in your own URL. Eg: [url=http://server.com/Tr%E1%BA%A7n_Nguy%E1%BB%85n_Tr%C6%B0%E1%BB%9Dng_Sinh_13]http://server.com/Trần_Nguyễn_Trường_Sinh 13[/url] then [url=http://server.com/Tr%E1%BA%A7n_Nguy%E1%BB%85n_Tr%C6%B0%E1%BB%9Dng_Sinh_13%201]http://server.com/Trần_Nguyễn_Trường_Sinh 13 1[/url] instead of [url=http://server.com/Tr%E1%BA%A7n_Nguy%E1%BB%85n_Tr%C6%B0%E1%BB%9Dng_Sinh_13]http://server.com/Trần_Nguyễn_Trường_Sinh 13[/url] then [url=http://server.com/Tr%E1%BA%A7n_Nguy%E1%BB%85n_Tr%C6%B0%E1%BB%9Dng_Sinh_14]http://server.com/Trần_Nguyễn_Trường_Sinh 14[/url]

  • Fixing increasing number without considering. Eg: [url=http://server.com/Tr%E1%BA%A7n_Nguy%E1%BB%85n_Tr%C6%B0%E1%BB%9Dng_Sinh%202]http://server.com/Trần_Nguyễn_Trường_Sinh 2[/url] (DB already have [url=http://server.com/Tr%E1%BA%A7n_Nguy%E1%BB%85n_Tr%C6%B0%E1%BB%9Dng_Sinh%201]http://server.com/Trần_Nguyễn_Trường_Sinh 1[/url] and [url=http://server.com/Tr%E1%BA%A7n_Nguy%E1%BB%85n_Tr%C6%B0%E1%BB%9Dng_Sinh%203]http://server.com/Trần_Nguyễn_Trường_Sinh 3[/url]) instead of [url=http://server.com/Tr%E1%BA%A7n_Nguy%E1%BB%85n_Tr%C6%B0%E1%BB%9Dng_Sinh%204]http://server.com/Trần_Nguyễn_Trường_Sinh 4[/url] (DB already have [url=http://server.com/Tr%E1%BA%A7n_Nguy%E1%BB%85n_Tr%C6%B0%E1%BB%9Dng_Sinh%201]http://server.com/Trần_Nguyễn_Trường_Sinh 1[/url] and [url=http://server.com/Tr%E1%BA%A7n_Nguy%E1%BB%85n_Tr%C6%B0%E1%BB%9Dng_Sinh%203]http://server.com/Trần_Nguyễn_Trường_Sinh 3[/url]), ignore [url=http://server.com/Tr%E1%BA%A7n_Nguy%E1%BB%85n_Tr%C6%B0%E1%BB%9Dng_Sinh%203]http://server.com/Trần_Nguyễn_Trường_Sinh 2[/url]

  • Hiding increasing number in Admin Panel. Eg: http://server.com/Trần_Nguyễn_Trường_Sinh (real URL [url=http://server.com/Tr%E1%BA%A7n_Nguy%E1%BB%85n_Tr%C6%B0%E1%BB%9Dng_Sinh%201]http://server.com/Trần_Nguyễn_Trường_Sinh 1[/url]) instead of [url=http://server.com/Tr%E1%BA%A7n_Nguy%E1%BB%85n_Tr%C6%B0%E1%BB%9Dng_Sinh%201]http://server.com/Trần_Nguyễn_Trường_Sinh 1[/url]

  • Using PHP function urlencode(), working fine with both IE and FF!

  • [/list:u]

    Feb 07, 2007 12:09

    ##########\inc\_blog_main.inc.php##########
    ##########FIND##########
    if( (!empty($p)) || (!empty($title)) || (!empty($preview)) )
    ##########ADD BEFORE##########
    $title=urldecode($title);
    ####################

    Feb 07, 2007 12:09

    ##########\inc\MODEL\items\_item.class.php##########
    ##########FIND##########
    		if( ! $Settings->get('links_extrapath') )
    ##########ADD BEFORE##########
    		$urltail=urlencode($urltail);
    ####################

    Feb 07, 2007 12:10

    ##########\inc\MODEL\items\_item.funcs.php##########
    ##########FIND##########
    function urltitle_validate( $urltitle, $title, $post_ID = 0, $query_only = false,
    															$dbprefix = 'post_', $dbIDname = 'post_ID', $dbtable = 'T_posts' )
    {
    	global $DB;
    
    	$urltitle = trim( $urltitle );
    
    	if( empty( $urltitle ) ) $urltitle = $title;
    	if( empty( $urltitle ) ) $urltitle = 'title';
    
    	// echo 'starting with: ', $urltitle, '<br />';
    
    	// Replace HTML entities
    	$urltitle = htmlentities( $urltitle, ENT_NOQUOTES );
    	// Keep only one char in entities!
    	$urltitle = preg_replace( '/&(.).+?;/', '$1', $urltitle );
    	// Remove non acceptable chars
    	$urltitle = preg_replace( '/[^A-Za-z0-9]+/', '_', $urltitle );
    	// Remove '_' at start and end:
    	$urltitle = preg_replace( '/^_+/', '', $urltitle );
    	$urltitle = preg_replace( '/_+$/', '', $urltitle );
    	// Uppercase the first character of each word in a string
    	$urltitle = strtolower( $urltitle );
    
    	preg_match( '/^(.*?)(_[0-9]+)?$/', $urltitle, $matches );
    
    	$urlbase = substr( $matches[1], 0, 40 );
    	$urltitle = $urlbase;
    	if( ! empty( $matches[2] ) )
    	{
    		$urltitle = $urlbase . $matches[2];
    	}
    
    
    	// Find all occurrences of urltitle+number in the DB:
    	$sql = 'SELECT '.$dbprefix.'urltitle
    					FROM '.$dbtable.'
    					WHERE '.$dbprefix."urltitle REGEXP '^".$urlbase."(_[0-9]+)?$'";
    	if( $post_ID )
    		$sql .= " AND $dbIDname <> $post_ID";
    	$exact_match = false;
    	$highest_number = 0;
    	foreach( $DB->get_results( $sql, ARRAY_A ) as $row )
    	{
    		$existing_urltitle = $row[$dbprefix.'urltitle'];
    		// echo "existing = $existing_urltitle <br />";
    		if( $existing_urltitle == $urltitle )
    		{ // We have an exact match, we'll have to change the number.
    			$exact_match = true;
    		}
    		if( preg_match( '/_([0-9]+)$/', $existing_urltitle, $matches ) )
    		{ // This one has a number, we extract it:
    			$existing_number = (integer) $matches[1];
    			if( $existing_number > $highest_number )
    			{ // This is the new high
    				$highest_number = $existing_number;
    			}
    		}
    	}
    	// echo "highest existing number = $highest_number <br />";
    
    	if( $exact_match && !$query_only )
    	{ // We got an exact match, we need to change the number:
    		$urltitle = $urlbase.'_'.($highest_number + 1);
    	}
    
    	// echo "using = $urltitle <br />";
    
    	return $urltitle;
    }
    ##########REPLACE##########
    function urltitle_validate( $urltitle, $title, $post_ID = 0, $query_only = false, $dbprefix = 'post_', $dbIDname = 'post_ID', $dbtable = 'T_posts' )
    {
    	global $DB;
    	if(empty($urltitle))$urltitle=$title;
    	if(empty($urltitle))$urltitle=T_('title');
    	$urltitle=trim($urltitle);
    	$urltitle=substr($urltitle,0,40);
    	$urltitle=trim($urltitle);
    	$urltitle=str_replace(' ','_',$urltitle);
    
    	// Find all occurrences of urltitle+number in the DB:
    	$sql = 'SELECT '.$dbprefix.'urltitle
    					FROM '.$dbtable.'
    					WHERE '.$dbprefix."urltitle REGEXP '^".$urltitle."( [0-9]+)?$'";
    	if($post_ID)$sql.=" AND $dbIDname <> $post_ID";
    	$exact_match=false;
    	$highest_number=0;
    	$ignore_number=array();
    	foreach( $DB->get_results( $sql, ARRAY_A ) as $row )
    	{
    		$existing_urltitle = $row[$dbprefix.'urltitle'];
    		if( $existing_urltitle == $urltitle )
    		{ // We have an exact match, we'll have to change the number.
    			$exact_match = true;
    		}
    		if( preg_match( '/ ([0-9]+)$/', $existing_urltitle, $matches ) )
    		{ // This one has a number, we extract it:
    			$existing_number = $matches[1];
    			if($k=array_search($existing_number,$ignore_number))unset($ignore_number[$k]);
    			$range=$existing_number-$highest_number;
    			if($range==1)$highest_number = $existing_number;// set new $highest_number
    			if($range>1){ // set new $highest_number and add $ignore_number
    				$highest_number=$existing_number;
    				for($i=1;$i<$range;$i++)$ignore_number[]=$existing_number-$i;
    				
    			}
    		}
    	}
    	sort($ignore_number,SORT_NUMERIC);
    	$return_num=(count($ignore_number)>0)?$ignore_number[0]:($highest_number+1);
    	if( $exact_match && !$query_only )
    	{ // We got an exact match, we need to change the number:
    		$urltitle.=' '.$return_num;
    	}
    	return $urltitle;
    }
    ####################

    Feb 07, 2007 12:10

    ##########\inc\VIEW\items\_item.form.php##########
    ##########FIND##########
    	$Form->text( 'post_urltitle',$post_urltitle, 40, T_('URL Title'),
    ##########ADD BEFORE##########
    	$post_urltitle=explode(' ',$post_urltitle);$post_urltitle=$post_urltitle[0];
    ####################

    Feb 07, 2007 12:14

    Package contains 4 files edited and 1 guides.


    Form is loading...

    Community software – This forum is powered by b2evolution CMS, a complete engine for your website.