Index: trunk/admin/install/install_lib.php =================================================================== diff -u -r2561 -r3244 --- trunk/admin/install/install_lib.php (.../install_lib.php) (revision 2561) +++ trunk/admin/install/install_lib.php (.../install_lib.php) (revision 3244) @@ -843,4 +843,48 @@ return $submit_value == $value ? ' checked' : ''; } + function StripDisallowed($string, $item_info) + { + $not_allowed = Array( ' ', '\\', '/', ':', '*', '?', '"', '<', '>', '|', + '~', '!', '@', '#', '$', '%', '^', '&', '(', ')', + '+', '=', '-', '{', '}', ']', '[', "'", ';', '.', ','); + + $string = str_replace($not_allowed, '_', $string); + $string = preg_replace('/(_+)/', '_', $string); + $string = checkAutoFilename($string, $item_info); + + return $string; + } + + function checkAutoFilename($filename, $item_info) + { + // 'table' => 'Category', 'id_field' => 'CategoryId', 'title_field' => 'Name' + $item_id = $item_info['item_id']; + $prefix = GetTablePrefix(); + $db =& inst_GetADODBConnection(); + + $sql = 'SELECT '.$item_info['id_field'].' FROM '.$prefix.$item_info['table'].' WHERE Filename = '.$db->qstr($filename); + $found_item_id = $db->GetOne($sql); + $has_page = preg_match('/(.*)_([\d]+)([a-z]*)$/', $filename, $rets); + if( ($found_item_id != $item_id) || $has_page ) // other category has same filename as ours OR we have filename, that ends with _number + { + $append = $found_item_id ? 'a' : ''; + if($has_page) + { + $filename = $rets[1].'_'.$rets[2]; + $append = $rets[3] ? $rets[3] : 'a'; + } + + $sql = 'SELECT '.$item_info['id_field'].' FROM '.$prefix.$item_info['table'].' WHERE (Filename = %s) AND ('.$item_info['id_field'].' != '.$item_id.')'; + while ( $db->GetOne( sprintf($sql, $db->qstr($filename.$append)) ) > 0 ) + { + if (substr($append, -1) == 'z') $append .= 'a'; + $append = substr($append, 0, strlen($append) - 1) . chr( ord( substr($append, -1) ) + 1 ); + } + + return $filename.$append; + } + + return $filename; + } ?>