Index: trunk/core/units/general/helpers/helpers_config.php =================================================================== diff -u -N --- trunk/core/units/general/helpers/helpers_config.php (revision 0) +++ trunk/core/units/general/helpers/helpers_config.php (revision 5505) @@ -0,0 +1,17 @@ + 'helpers', + 'EventHandlerClass' => Array('class' => 'kEventHandler', 'file' => '', 'build_event' => 'OnBuild'), + + 'RegisterClasses' => Array( + Array('pseudo'=>'MultiLanguageHelper','class'=>'kMultiLanguageHelper','file'=>'multilanguage.php','build_event'=>'','require_classes'=>'kHelper'), + Array('pseudo'=>'SearchHelper','class'=>'kSearchHelper','file'=>'search_helper.php','build_event'=>'','require_classes'=>'kHelper'), + Array('pseudo'=>'SectionsHelper','class'=>'kSectionsHelper','file'=>'sections_helper.php','build_event'=>'','require_classes'=>'kHelper'), + Array('pseudo'=>'PermissionsHelper','class'=>'kPermissionsHelper','file'=>'permissions_helper.php','build_event'=>'','require_classes'=>'kHelper'), + Array('pseudo'=>'ModulesHelper','class'=>'kModulesHelper','file'=>'modules.php','build_event'=>'','require_classes'=>'kHelper'), + Array('pseudo'=>'ModRewriteHelper','class'=>'kModRewriteHelper','file'=>'mod_rewrite_helper.php','build_event'=>'','require_classes'=>'kHelper'), + Array('pseudo'=>'RecursiveHelper','class'=>'kRecursiveHelper','file'=>'recursive_helper.php','build_event'=>'','require_classes'=>'kHelper'), + Array('pseudo'=>'FilenamesHelper','class'=>'kFilenamesHelper','file'=>'filenames_helper.php','build_event'=>'','require_classes'=>'kHelper'), + ), + ); \ No newline at end of file Index: trunk/kernel/units/general/helpers/helpers_config.php =================================================================== diff -u -N --- trunk/kernel/units/general/helpers/helpers_config.php (revision 0) +++ trunk/kernel/units/general/helpers/helpers_config.php (revision 5505) @@ -0,0 +1,17 @@ + 'helpers', + 'EventHandlerClass' => Array('class' => 'kEventHandler', 'file' => '', 'build_event' => 'OnBuild'), + + 'RegisterClasses' => Array( + Array('pseudo'=>'MultiLanguageHelper','class'=>'kMultiLanguageHelper','file'=>'multilanguage.php','build_event'=>'','require_classes'=>'kHelper'), + Array('pseudo'=>'SearchHelper','class'=>'kSearchHelper','file'=>'search_helper.php','build_event'=>'','require_classes'=>'kHelper'), + Array('pseudo'=>'SectionsHelper','class'=>'kSectionsHelper','file'=>'sections_helper.php','build_event'=>'','require_classes'=>'kHelper'), + Array('pseudo'=>'PermissionsHelper','class'=>'kPermissionsHelper','file'=>'permissions_helper.php','build_event'=>'','require_classes'=>'kHelper'), + Array('pseudo'=>'ModulesHelper','class'=>'kModulesHelper','file'=>'modules.php','build_event'=>'','require_classes'=>'kHelper'), + Array('pseudo'=>'ModRewriteHelper','class'=>'kModRewriteHelper','file'=>'mod_rewrite_helper.php','build_event'=>'','require_classes'=>'kHelper'), + Array('pseudo'=>'RecursiveHelper','class'=>'kRecursiveHelper','file'=>'recursive_helper.php','build_event'=>'','require_classes'=>'kHelper'), + Array('pseudo'=>'FilenamesHelper','class'=>'kFilenamesHelper','file'=>'filenames_helper.php','build_event'=>'','require_classes'=>'kHelper'), + ), + ); \ No newline at end of file Index: trunk/core/units/general/helpers/filenames_helper.php =================================================================== diff -u -N --- trunk/core/units/general/helpers/filenames_helper.php (revision 0) +++ trunk/core/units/general/helpers/filenames_helper.php (revision 5505) @@ -0,0 +1,81 @@ +', '|', '`', + '~', '!', '@', '#', '$', '%', '^', '&', '(', ')', '~', + '+', '=', '-', '{', '}', ']', '[', "'", ';', '.', ','); + + $filename = str_replace($not_allowed, '_', $filename); + $filename = preg_replace('/(_+)/', '_', $filename); + $filename = $this->checkAutoFilename($table, $id_field, $item_id, $filename); + + return $filename; + } + + function checkAutoFilename($table, $id_field, $item_id, $filename) + { + if(!$filename) return $filename; + + $item_id = !$item_id ? 0 : $item_id; + + if ($table == TABLE_PREFIX.'CategoryItems') { + $table = $this->Application->IsTempTable($table) ? $this->Application->GetLiveName($table) : $table; + $item_tmp_categories = $this->Conn->GetCol('SELECT CategoryId FROM '.$this->Application->GetTempName($table).' WHERE ItemResourceId = '.$item_id); + $item_live_categories = $this->Conn->GetCol('SELECT CategoryId FROM '.$table.' WHERE ItemResourceId = '.$item_id); + $item_categories = array_unique(array_merge($item_tmp_categories, $item_live_categories)); + if (!$item_categories) { + $item_categories = array($this->Application->GetVar('m_cat_id')); // this may happen when creating new item + } + $cat_filter = ' AND CategoryId IN ('.implode(',', $item_categories).')'; + } + else { + $cat_filter = ''; + } + + // check temp table + $sql_temp = 'SELECT '.$id_field.' FROM '.$table.' WHERE Filename = '.$this->Conn->qstr($filename).$cat_filter; + $found_temp_ids = $this->Conn->GetCol($sql_temp); + + // check live table + $sql_live = 'SELECT '.$id_field.' FROM '.$this->Application->GetLiveName($table).' WHERE Filename = '.$this->Conn->qstr($filename).$cat_filter; + $found_live_ids = $this->Conn->GetCol($sql_live); + + $found_item_ids = array_unique( array_merge($found_temp_ids, $found_live_ids) ); + + $has_page = preg_match('/(.*)_([\d]+)([a-z]*)$/', $filename, $rets); + + $duplicates_found = (count($found_item_ids) > 1) || ($found_item_ids && $found_item_ids[0] != $item_id); + if ($duplicates_found || $has_page) // other category has same filename as ours OR we have filename, that ends with _number + { + $append = $duplicates_found ? '_a' : ''; + if($has_page) + { + $filename = $rets[1].'_'.$rets[2]; + $append = $rets[3] ? $rets[3] : '_a'; + } + + // check live & temp table + $sql_temp = 'SELECT '.$id_field.' FROM '.$table.' WHERE (Filename = %s) AND ('.$id_field.' != '.$item_id.')'.$cat_filter; + $sql_live = 'SELECT '.$id_field.' FROM '.$this->Application->GetLiveName($table).' WHERE (Filename = %s) AND ('.$id_field.' != '.$item_id.')'.$cat_filter; + while ( $this->Conn->GetOne( sprintf($sql_temp, $this->Conn->qstr($filename.$append)) ) > 0 || + $this->Conn->GetOne( sprintf($sql_live, $this->Conn->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; + } + +} \ No newline at end of file Index: trunk/core/units/category_items/category_items_config.php =================================================================== diff -u -N -r4790 -r5505 --- trunk/core/units/category_items/category_items_config.php (.../category_items_config.php) (revision 4790) +++ trunk/core/units/category_items/category_items_config.php (.../category_items_config.php) (revision 5505) @@ -50,9 +50,11 @@ ), 'Fields' => Array( 'DummyId' => Array(), - 'CategoryId' => Array('type'=>'int','not_null'=>1,'default'=>0), + 'CategoryId' => Array('type'=>'int','not_null'=>1,'default'=>0), 'ItemResourceId' => Array('not_null' => 1, 'default' => 0), 'PrimaryCat' => Array('type' => 'int', 'not_null' => 1, 'default' => 0), + 'ItemPrefix' => Array('type' => 'string','not_null'=>1,'default'=>''), + 'Filename' => Array('type' => 'string','not_null'=>1,'default'=>''), ), 'VirtualFields' => Array( 'CategoryName' => Array(), Index: trunk/core/kernel/event_handler.php =================================================================== diff -u -N -r5219 -r5505 --- trunk/core/kernel/event_handler.php (.../event_handler.php) (revision 5219) +++ trunk/core/kernel/event_handler.php (.../event_handler.php) (revision 5505) @@ -221,7 +221,7 @@ } // get item's filename - $filename = $this->Application->getFilename($event->Prefix, $processed_params[$prefix_special.'_id'] ); + $filename = $this->Application->getFilename($event->Prefix, $processed_params[$prefix_special.'_id'], $category_id ); if($filename !== false) $ret .= $filename.'/'; } @@ -283,10 +283,14 @@ $db =& $this->Application->GetADODBConnection(); $id_field = $this->Application->getUnitOption($event->Prefix, 'IDField'); $table = $this->Application->getUnitOption($event->Prefix, 'TableName'); + + + $sql = 'SELECT item_table.'.$id_field.' FROM '.$table.' item_table LEFT JOIN '.TABLE_PREFIX.'CategoryItems cat_items ON item_table.ResourceId = cat_items.ItemResourceId WHERE (item_table.Filename = '.$db->qstr($url_part).') AND (cat_items.CategoryId = '.$this->Application->GetVar('m_cat_id').')'; + $item_id = $db->GetOne($sql); if($item_id !== false) { Index: trunk/kernel/units/general/helpers/filenames_helper.php =================================================================== diff -u -N --- trunk/kernel/units/general/helpers/filenames_helper.php (revision 0) +++ trunk/kernel/units/general/helpers/filenames_helper.php (revision 5505) @@ -0,0 +1,81 @@ +', '|', '`', + '~', '!', '@', '#', '$', '%', '^', '&', '(', ')', '~', + '+', '=', '-', '{', '}', ']', '[', "'", ';', '.', ','); + + $filename = str_replace($not_allowed, '_', $filename); + $filename = preg_replace('/(_+)/', '_', $filename); + $filename = $this->checkAutoFilename($table, $id_field, $item_id, $filename); + + return $filename; + } + + function checkAutoFilename($table, $id_field, $item_id, $filename) + { + if(!$filename) return $filename; + + $item_id = !$item_id ? 0 : $item_id; + + if ($table == TABLE_PREFIX.'CategoryItems') { + $table = $this->Application->IsTempTable($table) ? $this->Application->GetLiveName($table) : $table; + $item_tmp_categories = $this->Conn->GetCol('SELECT CategoryId FROM '.$this->Application->GetTempName($table).' WHERE ItemResourceId = '.$item_id); + $item_live_categories = $this->Conn->GetCol('SELECT CategoryId FROM '.$table.' WHERE ItemResourceId = '.$item_id); + $item_categories = array_unique(array_merge($item_tmp_categories, $item_live_categories)); + if (!$item_categories) { + $item_categories = array($this->Application->GetVar('m_cat_id')); // this may happen when creating new item + } + $cat_filter = ' AND CategoryId IN ('.implode(',', $item_categories).')'; + } + else { + $cat_filter = ''; + } + + // check temp table + $sql_temp = 'SELECT '.$id_field.' FROM '.$table.' WHERE Filename = '.$this->Conn->qstr($filename).$cat_filter; + $found_temp_ids = $this->Conn->GetCol($sql_temp); + + // check live table + $sql_live = 'SELECT '.$id_field.' FROM '.$this->Application->GetLiveName($table).' WHERE Filename = '.$this->Conn->qstr($filename).$cat_filter; + $found_live_ids = $this->Conn->GetCol($sql_live); + + $found_item_ids = array_unique( array_merge($found_temp_ids, $found_live_ids) ); + + $has_page = preg_match('/(.*)_([\d]+)([a-z]*)$/', $filename, $rets); + + $duplicates_found = (count($found_item_ids) > 1) || ($found_item_ids && $found_item_ids[0] != $item_id); + if ($duplicates_found || $has_page) // other category has same filename as ours OR we have filename, that ends with _number + { + $append = $duplicates_found ? '_a' : ''; + if($has_page) + { + $filename = $rets[1].'_'.$rets[2]; + $append = $rets[3] ? $rets[3] : '_a'; + } + + // check live & temp table + $sql_temp = 'SELECT '.$id_field.' FROM '.$table.' WHERE (Filename = %s) AND ('.$id_field.' != '.$item_id.')'.$cat_filter; + $sql_live = 'SELECT '.$id_field.' FROM '.$this->Application->GetLiveName($table).' WHERE (Filename = %s) AND ('.$id_field.' != '.$item_id.')'.$cat_filter; + while ( $this->Conn->GetOne( sprintf($sql_temp, $this->Conn->qstr($filename.$append)) ) > 0 || + $this->Conn->GetOne( sprintf($sql_live, $this->Conn->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; + } + +} \ No newline at end of file Index: trunk/kernel/units/category_items/category_items_config.php =================================================================== diff -u -N -r4790 -r5505 --- trunk/kernel/units/category_items/category_items_config.php (.../category_items_config.php) (revision 4790) +++ trunk/kernel/units/category_items/category_items_config.php (.../category_items_config.php) (revision 5505) @@ -50,9 +50,11 @@ ), 'Fields' => Array( 'DummyId' => Array(), - 'CategoryId' => Array('type'=>'int','not_null'=>1,'default'=>0), + 'CategoryId' => Array('type'=>'int','not_null'=>1,'default'=>0), 'ItemResourceId' => Array('not_null' => 1, 'default' => 0), 'PrimaryCat' => Array('type' => 'int', 'not_null' => 1, 'default' => 0), + 'ItemPrefix' => Array('type' => 'string','not_null'=>1,'default'=>''), + 'Filename' => Array('type' => 'string','not_null'=>1,'default'=>''), ), 'VirtualFields' => Array( 'CategoryName' => Array(), Index: trunk/kernel/units/general/cat_event_handler.php =================================================================== diff -u -N -r5431 -r5505 --- trunk/kernel/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 5431) +++ trunk/kernel/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 5505) @@ -1666,15 +1666,17 @@ if ($dst_field == 'ItemCategory') { $object =& $event->getObject(); // category item object (e.g. link, product, etc.) - $ci_prefix = $object->Prefix.'-ci'; + $object->assignToCategory($category_id); + + /*$ci_prefix = $object->Prefix.'-ci'; $ci_object =& $this->Application->recallObject($ci_prefix, null, Array('skip_autoload' => true)); $ci_object->Load($category_id); if (!$ci_object->isLoaded()) { $fields_hash = Array('CategoryId' => $category_id, 'ItemResourceId' => $object->GetDBField('ResourceId')); $ci_object->SetDBFieldsFromHash($fields_hash); $ci_object->Create(true); - } + }*/ } $this->finalizePopup($event); Index: trunk/core/kernel/application.php =================================================================== diff -u -N -r5340 -r5505 --- trunk/core/kernel/application.php (.../application.php) (revision 5340) +++ trunk/core/kernel/application.php (.../application.php) (revision 5505) @@ -425,6 +425,7 @@ $this->registerClass('kArray', KERNEL_PATH.'/utility/params.php'); $this->registerClass('Params', KERNEL_PATH.'/utility/params.php'); + $this->registerClass('kHelper', KERNEL_PATH.'/kbase.php'); $this->registerClass('kCache', KERNEL_PATH.'/utility/cache.php', 'Cache', Array('Params')); $this->registerClass('kHTTPQuery', KERNEL_PATH.'/utility/http_query.php', 'HTTPQuery', Array('Params') ); @@ -486,7 +487,7 @@ * @param int $id * @return string */ - function getFilename($prefix, $id) + function getFilename($prefix, $id, $category_id=null) { $filename = $this->getCache('filenames', $prefix.'_'.$id); if ($filename === false) { @@ -509,10 +510,15 @@ $this->setCache('item_templates', $id, $category_data['CachedItemTemplate']); } else { - $sql = 'SELECT Filename + $resource_id = $this->Conn->GetOne('SELECT ResourceId FROM '.$table.' WHERE '.$id_field.' = '.$this->Conn->qstr($id)); + if (is_null($category_id)) $category_id = $this->GetVar('m_cat_id'); + $sql = 'SELECT Filename FROM '.TABLE_PREFIX.'CategoryItems WHERE ItemResourceId = '.$resource_id.' AND CategoryId = '.$category_id; + $filename = $this->Conn->GetOne($sql); + + /*$sql = 'SELECT Filename FROM '.$table.' WHERE '.$id_field.' = '.$this->Conn->qstr($id); - $filename = $this->Conn->GetOne($sql); + $filename = $this->Conn->GetOne($sql);*/ } $this->setCache('filenames', $prefix.'_'.$id, $filename); } Index: trunk/core/units/general/cat_event_handler.php =================================================================== diff -u -N -r5431 -r5505 --- trunk/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 5431) +++ trunk/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 5505) @@ -1666,15 +1666,17 @@ if ($dst_field == 'ItemCategory') { $object =& $event->getObject(); // category item object (e.g. link, product, etc.) - $ci_prefix = $object->Prefix.'-ci'; + $object->assignToCategory($category_id); + + /*$ci_prefix = $object->Prefix.'-ci'; $ci_object =& $this->Application->recallObject($ci_prefix, null, Array('skip_autoload' => true)); $ci_object->Load($category_id); if (!$ci_object->isLoaded()) { $fields_hash = Array('CategoryId' => $category_id, 'ItemResourceId' => $object->GetDBField('ResourceId')); $ci_object->SetDBFieldsFromHash($fields_hash); $ci_object->Create(true); - } + }*/ } $this->finalizePopup($event); Index: trunk/admin/install/upgrades/inportal_upgrade_v1.2.1.sql =================================================================== diff -u -N -r5231 -r5505 --- trunk/admin/install/upgrades/inportal_upgrade_v1.2.1.sql (.../inportal_upgrade_v1.2.1.sql) (revision 5231) +++ trunk/admin/install/upgrades/inportal_upgrade_v1.2.1.sql (.../inportal_upgrade_v1.2.1.sql) (revision 5505) @@ -65,5 +65,7 @@ ALTER TABLE Permissions ADD UNIQUE PermIndex (Permission, GroupId, CatId, Type); REPLACE INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('CATEGORY.VIEW', 11, 1, 0, 0); +ALTER TABLE CategoryItems ADD `ItemPrefix` VARCHAR( 50 ) NOT NULL AFTER `PrimaryCat`, ADD `Filename` VARCHAR( 255 ) NOT NULL AFTER `ItemPrefix` ; +ALTER TABLE CategoryItems ADD INDEX `Filename` ( `Filename` ( 4 ) ); UPDATE Modules SET Version = '1.2.1' WHERE Name = 'In-Portal'; \ No newline at end of file Index: trunk/core/units/general/cat_dbitem.php =================================================================== diff -u -N -r5211 -r5505 --- trunk/core/units/general/cat_dbitem.php (.../cat_dbitem.php) (revision 5211) +++ trunk/core/units/general/cat_dbitem.php (.../cat_dbitem.php) (revision 5505) @@ -22,7 +22,7 @@ $this->SetDBField('ResourceId', $this->Application->NextResourceId()); $this->SetDBField('Modified', adodb_mktime() ); - + if ($this->mode != 't') { $this->SetDBField('CreatedById', $this->Application->GetVar('u_id')); } @@ -42,8 +42,8 @@ $table = TABLE_PREFIX.'CategoryItems'; } $cat_id = $this->Application->GetVar('m_cat_id'); - $query = 'INSERT INTO '.$table.' (CategoryId,ItemResourceId,PrimaryCat) - VALUES ('.$cat_id.','.$this->GetField('ResourceId').',1)'; + $query = 'INSERT INTO '.$table.' (CategoryId,ItemResourceId,PrimaryCat,ItemPrefix,Filename) + VALUES ('.$cat_id.','.$this->GetField('ResourceId').',1,'.$this->Conn->qstr($this->Prefix).','.$this->Conn->qstr($this->GetDBField('Filename')).')'; $this->Conn->Query($query); } return $ret; @@ -62,6 +62,11 @@ $ret = parent::Update($id, $system_update); + if ($ret) { + $table = $this->Application->IsTempTable($this->TableName) ? $this->Application->GetTempName(TABLE_PREFIX.'CategoryItems') : TABLE_PREFIX.'CategoryItems'; + $this->Conn->Query('UPDATE '.$table.' SET Filename = '.$this->Conn->qstr($this->GetDBField('Filename')).' WHERE ItemResourceId = '.$this->GetDBField('ResourceId')); + } + unset($this->VirtualFields['ResourceId']); return $ret; } @@ -197,63 +202,20 @@ * @param string $string * @return string */ - function stripDisallowed($string) + function stripDisallowed($filename) { - $not_allowed = Array( ' ', '\\', '/', ':', '*', '?', '"', '<', '>', '|', '`', - '~', '!', '@', '#', '$', '%', '^', '&', '(', ')', '~', - '+', '=', '-', '{', '}', ']', '[', "'", ';', '.', ','); - - $string = str_replace($not_allowed, '_', $string); - $string = preg_replace('/(_+)/', '_', $string); - $string = $this->checkAutoFilename($string); - - return $string; + $filenames_helper =& $this->Application->recallObject('FilenamesHelper'); + return $filenames_helper->stripDisallowed(TABLE_PREFIX.'CategoryItems', 'ItemResourceId', $this->GetDBField('ResourceId'), $filename); } + /* commented out because it's called only from stripDisallowed body, which is moved to helper + function checkAutoFilename($filename) { - if(!$filename) return $filename; + $filenames_helper =& $this->Application->recallObject('FilenamesHelper'); + return $filenames_helper->checkAutoFilename($this->TableName, $this->IDField, $this->GetID(), $filename); + }*/ - $item_id = !$this->GetID() ? 0 : $this->GetID(); - - // check temp table - $sql_temp = 'SELECT '.$this->IDField.' FROM '.$this->TableName.' WHERE Filename = '.$this->Conn->qstr($filename); - $found_temp_ids = $this->Conn->GetCol($sql_temp); - - // check live table - $sql_live = 'SELECT '.$this->IDField.' FROM '.$this->Application->GetLiveName($this->TableName).' WHERE Filename = '.$this->Conn->qstr($filename); - $found_live_ids = $this->Conn->GetCol($sql_live); - - $found_item_ids = array_unique( array_merge($found_temp_ids, $found_live_ids) ); - - $has_page = preg_match('/(.*)_([\d]+)([a-z]*)$/', $filename, $rets); - - $duplicates_found = (count($found_item_ids) > 1) || ($found_item_ids && $found_item_ids[0] != $item_id); - if ($duplicates_found || $has_page) // other category has same filename as ours OR we have filename, that ends with _number - { - $append = $duplicates_found ? '_a' : ''; - if($has_page) - { - $filename = $rets[1].'_'.$rets[2]; - $append = $rets[3] ? $rets[3] : '_a'; - } - - // check live & temp table - $sql_temp = 'SELECT '.$this->IDField.' FROM '.$this->TableName.' WHERE (Filename = %s) AND ('.$this->IDField.' != '.$item_id.')'; - $sql_live = 'SELECT '.$this->IDField.' FROM '.$this->Application->GetLiveName($this->TableName).' WHERE (Filename = %s) AND ('.$this->IDField.' != '.$item_id.')'; - while ( $this->Conn->GetOne( sprintf($sql_temp, $this->Conn->qstr($filename.$append)) ) > 0 || - $this->Conn->GetOne( sprintf($sql_live, $this->Conn->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; - } - /** * Generate item's filename based on it's title field value * @@ -297,7 +259,7 @@ */ function assignToCategory($category_id, $is_primary = false) { - $table = TABLE_PREFIX.'CategoryItems'; + $table = $this->mode == 't' ? $this->Application->GetTempName(TABLE_PREFIX.'CategoryItems') : TABLE_PREFIX.'CategoryItems'; $key_clause = '(ItemResourceId = '.$this->GetDBField('ResourceId').')'; // get all cateories, where item is in @@ -335,9 +297,12 @@ $this->Conn->Query($sql); } else { - $sql = 'INSERT INTO '.$table.' (CategoryId,ItemResourceId,PrimaryCat) VALUES (%s,%s,%s)'; - $this->Conn->Query( sprintf($sql, $category_id, $this->GetDBField('ResourceId'), $is_primary ? 1 : 0) ); + $sql = 'INSERT INTO '.$table.' (CategoryId,ItemResourceId,PrimaryCat,ItemPrefix,Filename) VALUES (%s,%s,%s,%s,%s)'; + $this->Conn->Query( sprintf($sql, $category_id, $this->GetDBField('ResourceId'), $is_primary ? 1 : 0, $this->Conn->qstr($this->Prefix), $this->Conn->qstr($this->GetDBField('Filename'))) ); } + // to ensure filename update after adding to another category + // this is critical since there may be an item with same filename in newly added category! + $this->Update(); } /** Index: trunk/admin/install/inportal_schema.sql =================================================================== diff -u -N -r5231 -r5505 --- trunk/admin/install/inportal_schema.sql (.../inportal_schema.sql) (revision 5231) +++ trunk/admin/install/inportal_schema.sql (.../inportal_schema.sql) (revision 5505) @@ -70,17 +70,21 @@ KEY l3_Description (l3_Description(5)), KEY l4_Description (l4_Description(5)), KEY l5_Description (l5_Description(5)) -) +) # -------------------------------------------------------- CREATE TABLE CategoryItems ( - CategoryId int(11) NOT NULL default '0', - ItemResourceId int(11) NOT NULL default '0', - PrimaryCat tinyint(4) NOT NULL default '0', - KEY CategoryId (CategoryId), - KEY ItemResourceId (ItemResourceId), - KEY PrimaryCat (PrimaryCat) + `CategoryId` int(11) NOT NULL default '0', + `ItemResourceId` int(11) NOT NULL default '0', + `PrimaryCat` tinyint(4) NOT NULL default '0', + `ItemPrefix` varchar(50) NOT NULL default '', + `Filename` varchar(255) NOT NULL default '', + KEY `CategoryId` (`CategoryId`), + KEY `ItemResourceId` (`ItemResourceId`), + KEY `PrimaryCat` (`PrimaryCat`), + KEY `ItemPrefix` (`ItemPrefix`), + KEY `Filename` (`Filename`(4)) ) # -------------------------------------------------------- Index: trunk/kernel/units/general/cat_dbitem.php =================================================================== diff -u -N -r5211 -r5505 --- trunk/kernel/units/general/cat_dbitem.php (.../cat_dbitem.php) (revision 5211) +++ trunk/kernel/units/general/cat_dbitem.php (.../cat_dbitem.php) (revision 5505) @@ -22,7 +22,7 @@ $this->SetDBField('ResourceId', $this->Application->NextResourceId()); $this->SetDBField('Modified', adodb_mktime() ); - + if ($this->mode != 't') { $this->SetDBField('CreatedById', $this->Application->GetVar('u_id')); } @@ -42,8 +42,8 @@ $table = TABLE_PREFIX.'CategoryItems'; } $cat_id = $this->Application->GetVar('m_cat_id'); - $query = 'INSERT INTO '.$table.' (CategoryId,ItemResourceId,PrimaryCat) - VALUES ('.$cat_id.','.$this->GetField('ResourceId').',1)'; + $query = 'INSERT INTO '.$table.' (CategoryId,ItemResourceId,PrimaryCat,ItemPrefix,Filename) + VALUES ('.$cat_id.','.$this->GetField('ResourceId').',1,'.$this->Conn->qstr($this->Prefix).','.$this->Conn->qstr($this->GetDBField('Filename')).')'; $this->Conn->Query($query); } return $ret; @@ -62,6 +62,11 @@ $ret = parent::Update($id, $system_update); + if ($ret) { + $table = $this->Application->IsTempTable($this->TableName) ? $this->Application->GetTempName(TABLE_PREFIX.'CategoryItems') : TABLE_PREFIX.'CategoryItems'; + $this->Conn->Query('UPDATE '.$table.' SET Filename = '.$this->Conn->qstr($this->GetDBField('Filename')).' WHERE ItemResourceId = '.$this->GetDBField('ResourceId')); + } + unset($this->VirtualFields['ResourceId']); return $ret; } @@ -197,63 +202,20 @@ * @param string $string * @return string */ - function stripDisallowed($string) + function stripDisallowed($filename) { - $not_allowed = Array( ' ', '\\', '/', ':', '*', '?', '"', '<', '>', '|', '`', - '~', '!', '@', '#', '$', '%', '^', '&', '(', ')', '~', - '+', '=', '-', '{', '}', ']', '[', "'", ';', '.', ','); - - $string = str_replace($not_allowed, '_', $string); - $string = preg_replace('/(_+)/', '_', $string); - $string = $this->checkAutoFilename($string); - - return $string; + $filenames_helper =& $this->Application->recallObject('FilenamesHelper'); + return $filenames_helper->stripDisallowed(TABLE_PREFIX.'CategoryItems', 'ItemResourceId', $this->GetDBField('ResourceId'), $filename); } + /* commented out because it's called only from stripDisallowed body, which is moved to helper + function checkAutoFilename($filename) { - if(!$filename) return $filename; + $filenames_helper =& $this->Application->recallObject('FilenamesHelper'); + return $filenames_helper->checkAutoFilename($this->TableName, $this->IDField, $this->GetID(), $filename); + }*/ - $item_id = !$this->GetID() ? 0 : $this->GetID(); - - // check temp table - $sql_temp = 'SELECT '.$this->IDField.' FROM '.$this->TableName.' WHERE Filename = '.$this->Conn->qstr($filename); - $found_temp_ids = $this->Conn->GetCol($sql_temp); - - // check live table - $sql_live = 'SELECT '.$this->IDField.' FROM '.$this->Application->GetLiveName($this->TableName).' WHERE Filename = '.$this->Conn->qstr($filename); - $found_live_ids = $this->Conn->GetCol($sql_live); - - $found_item_ids = array_unique( array_merge($found_temp_ids, $found_live_ids) ); - - $has_page = preg_match('/(.*)_([\d]+)([a-z]*)$/', $filename, $rets); - - $duplicates_found = (count($found_item_ids) > 1) || ($found_item_ids && $found_item_ids[0] != $item_id); - if ($duplicates_found || $has_page) // other category has same filename as ours OR we have filename, that ends with _number - { - $append = $duplicates_found ? '_a' : ''; - if($has_page) - { - $filename = $rets[1].'_'.$rets[2]; - $append = $rets[3] ? $rets[3] : '_a'; - } - - // check live & temp table - $sql_temp = 'SELECT '.$this->IDField.' FROM '.$this->TableName.' WHERE (Filename = %s) AND ('.$this->IDField.' != '.$item_id.')'; - $sql_live = 'SELECT '.$this->IDField.' FROM '.$this->Application->GetLiveName($this->TableName).' WHERE (Filename = %s) AND ('.$this->IDField.' != '.$item_id.')'; - while ( $this->Conn->GetOne( sprintf($sql_temp, $this->Conn->qstr($filename.$append)) ) > 0 || - $this->Conn->GetOne( sprintf($sql_live, $this->Conn->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; - } - /** * Generate item's filename based on it's title field value * @@ -297,7 +259,7 @@ */ function assignToCategory($category_id, $is_primary = false) { - $table = TABLE_PREFIX.'CategoryItems'; + $table = $this->mode == 't' ? $this->Application->GetTempName(TABLE_PREFIX.'CategoryItems') : TABLE_PREFIX.'CategoryItems'; $key_clause = '(ItemResourceId = '.$this->GetDBField('ResourceId').')'; // get all cateories, where item is in @@ -335,9 +297,12 @@ $this->Conn->Query($sql); } else { - $sql = 'INSERT INTO '.$table.' (CategoryId,ItemResourceId,PrimaryCat) VALUES (%s,%s,%s)'; - $this->Conn->Query( sprintf($sql, $category_id, $this->GetDBField('ResourceId'), $is_primary ? 1 : 0) ); + $sql = 'INSERT INTO '.$table.' (CategoryId,ItemResourceId,PrimaryCat,ItemPrefix,Filename) VALUES (%s,%s,%s,%s,%s)'; + $this->Conn->Query( sprintf($sql, $category_id, $this->GetDBField('ResourceId'), $is_primary ? 1 : 0, $this->Conn->qstr($this->Prefix), $this->Conn->qstr($this->GetDBField('Filename'))) ); } + // to ensure filename update after adding to another category + // this is critical since there may be an item with same filename in newly added category! + $this->Update(); } /** Index: trunk/core/units/general/my_application.php =================================================================== diff -u -N -r5177 -r5505 --- trunk/core/units/general/my_application.php (.../my_application.php) (revision 5177) +++ trunk/core/units/general/my_application.php (.../my_application.php) (revision 5505) @@ -24,14 +24,18 @@ $this->registerClass('kCountryStatesHelper',MODULES_PATH.'/kernel/units/general/country_states.php','CountryStatesHelper'); $this->registerClass('kBracketsHelper',MODULES_PATH.'/kernel/units/general/brackets.php','BracketsHelper'); $this->registerClass('kXMLHelper',MODULES_PATH.'/kernel/units/general/xml_helper.php','kXMLHelper'); - $this->registerClass('kMultiLanguageHelper',MODULES_PATH.'/kernel/units/general/helpers/multilanguage.php','kMultiLanguageHelper'); + + $this->registerClass('kModulesHelper', MODULES_PATH.'/kernel/units/general/helpers/modules.php', 'ModulesHelper'); + +/* $this->registerClass('kMultiLanguageHelper',MODULES_PATH.'/kernel/units/general/helpers/multilanguage.php','kMultiLanguageHelper'); $this->registerClass('kSearchHelper', MODULES_PATH.'/kernel/units/general/helpers/search_helper.php', 'SearchHelper'); $this->registerClass('kSectionsHelper', MODULES_PATH.'/kernel/units/general/helpers/sections_helper.php', 'SectionsHelper'); $this->registerClass('kPermissionsHelper', MODULES_PATH.'/kernel/units/general/helpers/permissions_helper.php', 'PermissionsHelper'); - $this->registerClass('kModulesHelper', MODULES_PATH.'/kernel/units/general/helpers/modules.php', 'ModulesHelper'); + $this->registerClass('kModRewriteHelper', MODULES_PATH.'/kernel/units/general/helpers/mod_rewrite_helper.php', 'ModRewriteHelper'); $this->registerClass('kRecursiveHelper', MODULES_PATH.'/kernel/units/general/helpers/recursive_helper.php', 'RecursiveHelper'); + $this->registerClass('kFilenamesHelper', MODULES_PATH.'/kernel/units/general/helpers/filenames_helper.php', 'kFilenamesHelper');*/ } function getUserGroups($user_id) Index: trunk/kernel/units/general/my_application.php =================================================================== diff -u -N -r5178 -r5505 --- trunk/kernel/units/general/my_application.php (.../my_application.php) (revision 5178) +++ trunk/kernel/units/general/my_application.php (.../my_application.php) (revision 5505) @@ -24,14 +24,18 @@ $this->registerClass('kCountryStatesHelper',MODULES_PATH.'/kernel/units/general/country_states.php','CountryStatesHelper'); $this->registerClass('kBracketsHelper',MODULES_PATH.'/kernel/units/general/brackets.php','BracketsHelper'); $this->registerClass('kXMLHelper',MODULES_PATH.'/kernel/units/general/xml_helper.php','kXMLHelper'); - $this->registerClass('kMultiLanguageHelper',MODULES_PATH.'/kernel/units/general/helpers/multilanguage.php','kMultiLanguageHelper'); + + $this->registerClass('kModulesHelper', MODULES_PATH.'/kernel/units/general/helpers/modules.php', 'ModulesHelper'); + +/* $this->registerClass('kMultiLanguageHelper',MODULES_PATH.'/kernel/units/general/helpers/multilanguage.php','kMultiLanguageHelper'); $this->registerClass('kSearchHelper', MODULES_PATH.'/kernel/units/general/helpers/search_helper.php', 'SearchHelper'); $this->registerClass('kSectionsHelper', MODULES_PATH.'/kernel/units/general/helpers/sections_helper.php', 'SectionsHelper'); $this->registerClass('kPermissionsHelper', MODULES_PATH.'/kernel/units/general/helpers/permissions_helper.php', 'PermissionsHelper'); - $this->registerClass('kModulesHelper', MODULES_PATH.'/kernel/units/general/helpers/modules.php', 'ModulesHelper'); + $this->registerClass('kModRewriteHelper', MODULES_PATH.'/kernel/units/general/helpers/mod_rewrite_helper.php', 'ModRewriteHelper'); $this->registerClass('kRecursiveHelper', MODULES_PATH.'/kernel/units/general/helpers/recursive_helper.php', 'RecursiveHelper'); + $this->registerClass('kFilenamesHelper', MODULES_PATH.'/kernel/units/general/helpers/filenames_helper.php', 'kFilenamesHelper');*/ } function getUserGroups($user_id)