Index: trunk/kernel/include/category.php =================================================================== diff -u -N -r3124 -r3145 --- trunk/kernel/include/category.php (.../category.php) (revision 3124) +++ trunk/kernel/include/category.php (.../category.php) (revision 3145) @@ -37,6 +37,20 @@ } } + + function StripDisallowed($string) + { + $not_allowed = Array(' ', '\\', '/', ':', '*', '?', '"', '<', '>', '|'); + $string = str_replace($not_allowed, '_', $string); + return preg_replace('/(_+)/', '_', $string); + } + + function GenerateFilename() + { + if ( !$this->Get('AutomaticFilename') && $this->Get('Filename') ) return false; + $name = $this->StripDisallowed( $this->Get('Name') ); + if ( $name != $this->Get('Filename') ) $this->Set('Filename', $name); + } function ClearCacheData() { @@ -93,20 +107,18 @@ function Update($UpdatedBy=NULL) { + $this->GenerateFilename(); parent::Update($UpdatedBy); - if($this->tablename==GetTablePrefix()."Category") - $this->ClearCacheData(); + if ($this->tablename == GetTablePrefix().'Category') $this->ClearCacheData(); } function Create() { - if( (int) $this->Get("CreatedOn") == 0) { - $this->Set("CreatedOn",date("U")); - } + $this->GenerateFilename(); + if( (int)$this->Get('CreatedOn') == 0 ) $this->Set('CreatedOn', date('U') ); + parent::Create(); - if($this->tablename == GetTablePrefix()."Category") { - $this->ClearCacheData(); - } + if ($this->tablename == GetTablePrefix().'Category') $this->ClearCacheData(); } function SetParentId($value) @@ -239,37 +251,36 @@ return $dataValid; } - function UpdateCachedPath() - { - if($this->UsingTempTable()==TRUE) - return; - $Id = $this->Get("CategoryId"); - $Id2 = $Id; - $NavPath = ""; - $path = array(); - do - { - $rs = $this->adodbConnection->Execute("SELECT ParentId,Name from ".$this->tablename." where CategoryId='$Id2'"); - $path[] = $Id2; - $nav[] = $rs->fields["Name"]; - if ($rs && !$rs->EOF) - { - //echo $path; - $Id2 = $rs->fields["ParentId"]; - - } - else - $Id2="0"; //to prevent infinite loop - } while ($Id2 != "0"); - $parentpath = "|".implode("|",array_reverse($path))."|"; - $NavBar = implode(">",array_reverse($nav)); - //echo "
\n"; - //$rs = $this->adodbConnection->Execute("update Category set ParentPath='$path' where CategoryId='$Id'"); - if($this->Get("ParentPath")!=$parentpath || $this->Get("CachedNavbar")!=$NavBar) + function UpdateCachedPath() + { + if( $this->UsingTempTable() == true) return ; + $Id = $this->Get('CategoryId'); + $Id2 = $Id; + + $path_parts = Array(); + $nav_parts = Array(); + $named_parts = Array(); + + do + { + $rs = $this->adodbConnection->Execute('SELECT ParentId, Name, Filename FROM '.$this->tablename.' WHERE CategoryId = '.$Id2); + $path_parts[] = $Id2; + $nav_parts[] = $rs->fields['Name']; + $named_parts[] = $rs->fields['Filename']; + $Id2 = ($rs && !$rs->EOF) ? $rs->fields['ParentId'] : '0'; + + }while ($Id2 != '0'); + + $parent_path = '|'.implode('|', array_reverse($path_parts) ).'|'; + $nav_bar = implode('>', array_reverse($nav_parts) ); + $named_path = implode('/', $named_parts); + + if($this->Get('ParentPath') != $parent_path || $this->Get('CachedNavbar') != $nav_bar || $this->Get('NamedParentPath') != $named_path ) { - $this->Set("ParentPath",$parentpath); - $this->Set("CachedNavbar",$NavBar); - $this->Update(); + $this->Set('ParentPath', $parent_path); + $this->Set('CachedNavbar', $nav_bar); + $this->Set('NamedParentPath', $named_path); + $this->Update(); } } @@ -1989,54 +2000,58 @@ return $nav; } - function &Add($ParentId, $Name, $Description, $CreatedOn, $EditorsPick, $Status, $Hot, $New, $Pop, - $Priority, $MetaKeywords,$MetaDesc) - { - global $objSession; + function &Add( $ParentId, $Name, $Description, $CreatedOn, $EditorsPick, $Status, $Hot, $New, $Pop, + $Priority, $MetaKeywords,$MetaDesc, $auto_filename = 1, $filename = '') + { + global $objSession; - $UserId = $objSession->Get("UserId"); + $UserId = $objSession->Get('UserId'); - $d = new clsCategory(NULL); - $d->tablename = $this->SourceTable; - if($d->UsingTempTable()) - $d->Set("CategoryId",-1); - $d->idfield = "CategoryId"; - $d->Set(array("ParentId", "Name", "Description", "CreatedOn", "EditorsPick", "Status", "HotItem", - "NewItem","PopItem", "Priority", "MetaKeywords", "MetaDescription", "CreatedById"), - array($ParentId, $Name, $Description, $CreatedOn, $EditorsPick, $Status, $Hot, $New, - $Pop, $Priority, $MetaKeywords,$MetaDesc, $UserId)); + $d = new clsCategory(NULL); + $filename = $d->StripDisallowed($filename); + $d->tablename = $this->SourceTable; + + if( $d->UsingTempTable() ) $d->Set('CategoryId', -1); + $d->idfield = 'CategoryId'; + + $d->Set(Array( 'ParentId', 'Name', 'Description', 'CreatedOn', 'EditorsPick', 'Status', 'HotItem', + 'NewItem','PopItem', 'Priority', 'MetaKeywords', 'MetaDescription', 'CreatedById', + 'AutomaticFilename', 'Filename'), + Array( $ParentId, $Name, $Description, $CreatedOn, $EditorsPick, $Status, $Hot, $New, + $Pop, $Priority, $MetaKeywords,$MetaDesc, $UserId, $auto_filename, $filename) ); - $d->Create(); - if($Status==1) - { - $d->SendUserEventMail("CATEGORY.ADD",$objSession->Get("PortalUserId")); - $d->SendAdminEventMail("CATEGORY.ADD"); - } - else - { - $d->SendUserEventMail("CATEGORY.ADD.PENDING",$objSession->Get("PortalUserId")); - $d->SendAdminEventMail("CATEGORY.ADD.PENDING"); - } - $d->UpdateCachedPath(); - //RunUp($ParentId, "Increment_Count"); - - return $d; + $d->Create(); + if($Status == 1) + { + $d->SendUserEventMail("CATEGORY.ADD",$objSession->Get("PortalUserId")); + $d->SendAdminEventMail("CATEGORY.ADD"); + } + else + { + $d->SendUserEventMail("CATEGORY.ADD.PENDING",$objSession->Get("PortalUserId")); + $d->SendAdminEventMail("CATEGORY.ADD.PENDING"); + } + $d->UpdateCachedPath(); +// RunUp($ParentId, 'Increment_Count'); + return $d; } - function &Edit_Category($CategoryId, $Name, $Description, $CreatedOn, $EditorsPick, $Status, $Hot, - $NewItem, $Pop, $Priority, $MetaKeywords,$MetaDesc) - { - $d =& $this->GetCategory($CategoryId); - $d->Set(array("Name", "Description", "CreatedOn", "EditorsPick", "Status", "HotItem", - "NewItem", "PopItem", "Priority", "MetaKeywords","MetaDescription"), - array($Name, $Description, $CreatedOn, $EditorsPick, $Status, $Hot, $NewItem, - $Pop, $Priority, $MetaKeywords,$MetaDesc)); - $d->Update(); - $d->UpdateCachedPath(); - return $d; + function &Edit_Category($CategoryId, $Name, $Description, $CreatedOn, $EditorsPick, $Status, $Hot, + $NewItem, $Pop, $Priority, $MetaKeywords,$MetaDesc, $auto_filename = 1, $filename = '') + { + $d =& $this->GetCategory($CategoryId); + + $filename = $d->StripDisallowed($filename); + $d->Set( Array( 'Name', 'Description', 'CreatedOn', 'EditorsPick', 'Status', 'HotItem', + 'NewItem', 'PopItem', 'Priority', 'MetaKeywords','MetaDescription', + 'AutomaticFilename', 'Filename'), + Array( $Name, $Description, $CreatedOn, $EditorsPick, $Status, $Hot, $NewItem, + $Pop, $Priority, $MetaKeywords,$MetaDesc, $auto_filename, $filename) ); + $d->Update(); + $d->UpdateCachedPath(); + return $d; + } - } - function Move_Category($Id, $ParentTo) { global $objCatList;