Index: trunk/kernel/include/item.php
===================================================================
diff -u -r4077 -r5340
--- trunk/kernel/include/item.php (.../item.php) (revision 4077)
+++ trunk/kernel/include/item.php (.../item.php) (revision 5340)
@@ -21,7 +21,7 @@
var $ReviewPerPageVar;
var $TitleField = '';
-
+
function clsItem($FullItem=FALSE)
{
$this->clsParsedItem();
@@ -77,7 +77,7 @@
function &AddReview($createdBy,$reviewText,$isPending,$ip=NULL,$ForceIP=0, $Module="", $CreatedOn = 0)
{
$this->Reviews->itemID=$this->Get("ResourceId");
-
+
if($ip == NULL)
$ip = $_SERVER["REMOTE_ADDR"];
@@ -111,7 +111,7 @@
}
function DeleteReviews()
- {
+ {
$res_id = $this->Get("ResourceId");
if($res_id)
{
@@ -125,7 +125,7 @@
/* item custom fields */
function LoadCustomFields($force = null, $temp_table = false)
- {
+ {
if ((!is_null($force) || !$this->CustomLoaded) && $this->Get('ResourceId')>0) {
$this->FieldClass = new clsCustomFieldList();
$this->FieldClass->Type = $this->type;
@@ -135,25 +135,26 @@
if (strlen($f->Get("ValueList") && (($f->Get("ElementType") == "select") || ($f->Get("ElementType") == "radio"))))
{
if ($f->HasField('Value'))
- {
- $ValueList = explode(",", $f->Get("ValueList"));
+ {
+ $objConfigDummy = new clsConfigAdminItem();
+ $ValueList = explode(",", $objConfigDummy->replace_sql($f->Get("ValueList")));
if (is_array($ValueList))
{
foreach ($ValueList as $curr => $value)
{
$c_data = explode("=", $value);
if ($c_data[0] == $f->Get('Value'))
{
- $this->CustomFields[$f->Get("FieldName")]['value'] = $f->Get('Value');
- $this->CustomFields[$f->Get("FieldName")]['lang_value'] = language($c_data[1]);
+ $this->CustomFields[$f->Get("FieldName")]['value'] = $f->Get('Value');
+ $this->CustomFields[$f->Get("FieldName")]['lang_value'] = language($c_data[1]);
}
}
}
else
{
- $this->CustomFields[$f->Get("FieldName")]['value'] = $f->HasField('Value') ? $f->Get('Value') : '';
- $this->CustomFields[$f->Get("FieldName")]['lang_value'] = null;
- }
+ $this->CustomFields[$f->Get("FieldName")]['value'] = $f->HasField('Value') ? $f->Get('Value') : '';
+ $this->CustomFields[$f->Get("FieldName")]['lang_value'] = null;
+ }
}
else
{
@@ -165,13 +166,13 @@
{
$this->CustomFields[$f->Get("FieldName")]['value'] = strlen($f->HasField('Value')) ? $f->Get('Value') : '';
$this->CustomFields[$f->Get("FieldName")]['lang_value'] = null;
-
+
}
}
$this->CustomLoaded = 1;
}
}
-
+
function SetCustomField($fieldname,$value)
{
// echo "Setting CF [$fieldname] = [$value]
";
@@ -223,26 +224,26 @@
return $ret;
}
*/
-
+
function GetCustomFieldValue($fieldname, $default = '', $ListValue = 0, $temp_table = false)
{
if (!$this->CustomLoaded) {
- $this->LoadCustomFields(null, $temp_table);
+ $this->LoadCustomFields(null, $temp_table);
}
elseif (is_array($this->CustomFields) && empty($this->CustomFields)) {
- $this->LoadCustomFields(1, $temp_table);
+ $this->LoadCustomFields(1, $temp_table);
}
-
+
$fieldname = strtolower($fieldname);
foreach($this->CustomFields as $k => $v) {
if (strtolower($k) == $fieldname) {
return $ListValue? $v['lang_value'] : $v['value'];
- }
+ }
}
-
- return $default;
+
+ return $default;
}
-
+
function DeleteCustomData()
{
$cdata = new clsCustomDataList();
@@ -252,7 +253,7 @@
function Delete($RecordOnly=FALSE)
{
global $objFavorites;
-
+
if($RecordOnly==FALSE)
{
$this->DeleteReviews();
@@ -291,7 +292,7 @@
}
function DeleteRelations()
- {
+ {
$res_id = $this->Get("ResourceId");
if($res_id)
{
@@ -332,7 +333,7 @@
}
return $result;
}
-
+
function HighlightText($text)
{
global $objConfig;
@@ -569,7 +570,7 @@
{
return $this->Images->GetDefaultImage($this->Get("ResourceId"));
}
-
+
function &GetAvatarImage()
{
return $this->Images->GetAvatarImage($this->Get("ResourceId"));
@@ -591,10 +592,10 @@
global $objSession, $objFavorites;
$res = FALSE;
-
+
// user can be added to favorites, but they have no primary category :)
$category_id = method_exists($this, 'GetPrimaryCategory') ? $this->GetPrimaryCategory() : $GLOBALS['m_var_list']['cat'];
-
+
if( $objSession->HasCatPermission("FAVORITES", $category_id) )
{
if(!$PortalUserId)
@@ -616,7 +617,7 @@
// user can be added to favorites, but they have no primary category :)
$category_id = method_exists($this, 'GetPrimaryCategory') ? $this->GetPrimaryCategory() : $GLOBALS['m_var_list']['cat'];
-
+
if( $objSession->HasCatPermission("FAVORITES", $category_id) )
{
if(!$PortalUserId)
@@ -736,7 +737,7 @@
}
function Delete($RecordOnly=FALSE)
- {
+ {
global $objFavorites;
parent::Delete($RecordOnly);
@@ -885,7 +886,7 @@
function RemoveFromCategory($CatId,$SourceTable="",$Force=0)
{
- if(!is_numeric($CatId)) return;
+ if(!is_numeric($CatId)) return;
global $objSession, $objCatList;
if(strlen($SourceTable)==0)
$SourceTable = GetTablePrefix()."CategoryItems";
@@ -919,18 +920,18 @@
}
function DeleteCategoryItems($CatId,$SourceTable = "")
- {
+ {
if(strlen($SourceTable)==0)
$SourceTable = GetTablePrefix()."CategoryItems";
$CatCount = $this->CategoryMemberCount($SourceTable);
if($CatCount>1)
- {
+ {
$this->RemoveFromCategory($CatId,$SourceTable);
$this->ClearCacheData();
}
else
- {
+ {
$this->Delete();
$sql = "DELETE FROM $SourceTable WHERE CategoryId=$CatId AND ItemResourceId=".$this->Get("ResourceId");
if($this->debuglevel)
@@ -940,7 +941,7 @@
}
}
function RemoveFromAllCategories($SourceTable = "")
- {
+ {
if(strlen($SourceTable)==0)
$SourceTable = GetTablePrefix()."CategoryItems";
@@ -1061,60 +1062,60 @@
$this->SetPrimaryCategory($TargetCat); // 2 updates
}
}
-
+
function refreshLastUpdate($cat_id = null)
{
$db =& GetADODBConnection();
$prefix = GetTablePrefix();
-
+
// 1,2,3,4 - set lastupdate date to item's primary category as recent
// change date of all items in this category of same type as this item
-
+
// 1. get item category or use passed one
if(!isset($cat_id)) $cat_id = $this->GetPrimaryCategory();
if($cat_id == 0) return false;
-
+
// 2. get all item ResourceIds in that category
$sql = 'SELECT ItemResourceId FROM '.$prefix.'CategoryItems WHERE CategoryId = '.$cat_id;
$item_rids = $db->GetCol($sql);
if($item_rids)
{
$item_rids = implode(',',$item_rids);
-
+
// 2a. get LastUpdate date based on all item in $cat_id category
$sql = 'SELECT MAX(IF(Modified=0,CreatedOn,Modified)) FROM '.$this->tablename.' WHERE ResourceId IN ('.$item_rids.')';
$item_last_update = $db->GetOne($sql);
}
- else
+ else
{
$item_last_update = 0;
}
-
+
// 3. get LastUpdate date based on all $cat_id subcategories
$sql = 'SELECT MAX(IF(Modified=0,CreatedOn,Modified)) FROM '.$prefix.'Category WHERE ParentId = '.$cat_id;
$cat_last_update = $db->GetOne($sql);
-
+
$last_update = max($item_last_update,$cat_last_update);
-
+
// 4. set $last_update date to $cat_id category
$sql = 'UPDATE '.$prefix.'Category SET Modified = '.$last_update.' WHERE CategoryId = '.$cat_id;
$db->Execute($sql);
-
+
// 5. get $cat_id parent CategoryId
$sql = 'SELECT ParentId FROM '.$prefix.'Category WHERE CategoryId = '.$cat_id;
if($cat_id > 0) $this->refreshLastUpdate( $db->GetOne($sql) );
}
-
+
function StripDisallowed($string)
{
$not_allowed = Array( ' ', '\\', '/', ':', '*', '?', '"', '<', '>', '|', '`',
'~', '!', '@', '#', '$', '%', '^', '&', '(', ')', '~',
'+', '=', '-', '{', '}', ']', '[', "'", ';', '.', ',');
-
+
$string = str_replace($not_allowed, '_', $string);
$string = preg_replace('/(_+)/', '_', $string);
$string = $this->checkAutoFilename($string);
-
+
return $string;
}
@@ -1126,7 +1127,7 @@
$sql = 'SELECT '.$this->IdField().' FROM '.$this->tablename.' WHERE Filename = '.$db->qstr($filename);
$found_item_ids = $db->GetCol($sql);
$has_page = preg_match('/(.*)_([\d]+)([a-z]*)$/', $filename, $rets);
-
+
$duplicates_found = (count($found_item_ids) > 1) || ($found_item_ids && $found_item_ids[0] != $this->UniqueId());
if ($duplicates_found || $has_page) // other category has same filename as ours OR we have filename, that ends with _number
{
@@ -1161,25 +1162,25 @@
$name = $this->Get($this->TitleField);
}
$name = $this->StripDisallowed($name);
-
+
if ( $name != $this->Get('Filename') ) $this->Set('Filename', $name);
}
-
+
function Update($UpdatedBy = null)
{
parent::Update($UpdatedBy);
-
+
$this->GenerateFilename();
parent::Update($UpdatedBy);
-
+
}
function Create()
{
parent::Create();
-
+
$this->GenerateFilename();
-
+
parent::Update();
}