Index: trunk/admin/install/upgrades/inportal_upgrade_v1.1.4.php =================================================================== diff -u --- trunk/admin/install/upgrades/inportal_upgrade_v1.1.4.php (revision 0) +++ trunk/admin/install/upgrades/inportal_upgrade_v1.1.4.php (revision 3244) @@ -0,0 +1,25 @@ +Execute($sql); + while(!$items_rs->EOF) + { + $module_info['item_id'] = $items_rs->fields[ $module_info['id_field'] ]; + $filename = StripDisallowed($items_rs->fields[ $module_info['title_field'] ], $module_info); + $sql = 'UPDATE '.$table_prefix.$module_info['table'].' + SET AutomaticFilename = 1, Filename = '.$inst_ado->qstr($filename).' + WHERE '.$module_info['id_field'].' = '.$module_info['item_id']; + $inst_ado->Execute($sql); + $items_rs->MoveNext(); + } + +?> \ No newline at end of file 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; + } ?>