1 oradoe Feb 07, 2007 12:09
3 oradoe Feb 07, 2007 12:09
##########\inc\MODEL\items\_item.class.php##########
##########FIND##########
if( ! $Settings->get('links_extrapath') )
##########ADD BEFORE##########
$urltail=urlencode($urltail);
####################
4 oradoe 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;
}
####################
5 oradoe 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];
####################
6 oradoe Feb 07, 2007 12:14
Package contains 4 files edited and 1 guides.