Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F772918
in-portal
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Feb 1, 8:57 PM
Size
46 KB
Mime Type
text/x-diff
Expires
Mon, Feb 3, 8:57 PM (1 d, 14 h)
Engine
blob
Format
Raw Data
Handle
556197
Attached To
rINP In-Portal
in-portal
View Options
Index: trunk/kernel/include/itemreview.php
===================================================================
--- trunk/kernel/include/itemreview.php (revision 329)
+++ trunk/kernel/include/itemreview.php (revision 330)
@@ -1,614 +1,614 @@
<?php
function ip_exists($ip,$id,$SourceTable)
{
$count = 0;
$sql = "SELECT count(*) as DupCount FROM $SourceTable WHERE IPAddress='$ip' and ItemId=$id";
$adodbConnection = GetADODBConnection();
$rs = $adodbConnection->Execute($sql);
if($rs)
{
$count = $rs->fields["DupCount"];
}
return ($count>0);
}
RegisterPrefix("clsItemReview","review","kernel/include/itemreview.php");
class clsItemReview extends clsParsedItem
{
function clsItemReview($ReviewId=NULL,$table="ItemReview")
{
$this->clsParsedItem();
$this->tablename = $table;
$this->id_field = "ReviewId";
$this->type=-20;
$this->NoResourceId=1;
$this->TagPrefix = "review";
if($ReviewId!=NULL)
$this->LoadFromDatabase($ReviewId);
}
function Validate()
{
global $Errors;
$dataValid = true;
if(!isset($this->m_CreatedOn))
{
$Errors->AddError("error.fieldIsRequired",'CreatedOn',"","",get_class($this),"Validate");
$dataValid = false;
}
if(!isset($this->m_ReviewText))
{
$Errors->AddError("error.fieldIsRequired",'ReviewText',"","",get_class($this),"Validate");
$dataValid = false;
}
if(!isset($this->m_Pending))
{
$Error->AddError("error.fieldIsRequired",'Pending',"","",get_class($this),"Validate");
$dataValid = false;
}
if(!isset($this->m_IPAddress))
{
$Error->AddError("error.fieldIsRequired",'IPAddress',"","",get_class($this),"Validate");
$dataValid = false;
}
if(!isset($this->m_ItemId))
{
$Error->AddError("error.fieldIsRequired",'ItemId',"","",get_class($this),"Validate");
$dataValid = false;
}
if(!isset($this->m_CreatedById))
{
$Error->AddError("error.fieldIsRequired",'CreatedBy',"","",get_class($this),"Validate");
$dataValid = false;
}
return $dataValid;
}
function LoadFromDatabase($Id)
{
global $objSession, $Errors;
if(!isset($Id))
{
$Errors->AddError("error.AppError",NULL,'Internal error: LoadFromDatabase id',"",get_class($this),"LoadFromDatabase");
return false;
}
$sql = sprintf("SELECT * FROM ".$this->tablename." WHERE ReviewId = '%s'",$Id);
if( $GLOBALS['debuglevel'] ) echo $sql."<br>";
$result = $this->adodbConnection->Execute($sql);
if ($result === false)
{
$Errors->AddError("error.DatabaseError",NULL,$this->adodbConnection->ErrorMsg(),"",get_class($this),"LoadFromDatabase");
return false;
}
$data = $result->fields;
if(is_array($data))
$this->SetFromArray($data);
$this->Clean();
return TRUE;
}
function MoveUp()
{
$this->Increment("Priority");
}
function MoveDown()
{
$this->Decrement("Priority");
}
function ParseObject($element)
{
global $objConfig, $objCatList, $rootURL, $objUsers;
$extra_attribs = ExtraAttributes($element->attributes);
if(strtolower($element->name)==$this->TagPrefix)
{
$field = strtolower($element->attributes["_field"]);
switch($field)
{
case "id":
/*
@field:review.id
@description: review id
*/
$ret = $this->Get("ReviewId");
break;
case "item_id":
/*
@field:review.item_id
@description: ID of the item being reviewed
*/
$ret = inp_unescape($this->Get("ItemId"));
break;
case "text":
/*
@field:review.text
@description:Review text
*/
if($this->Get("TextFormat")==0 || $element->attribues["_textonly"])
{
$ret = inp_escape($this->Get("ReviewText"),0);
}
else
{
$ret = $this->Get("ReviewText");
}
break;
case "ip":
/*
@field:review.ip
@description:IP address of remote host submitting the review
*/
$ret = $this->Get("IPAddress");
break;
case "pending":
/*
@field:review.pending
@description: Returns the review pening status
*/
$ret = $this->Get("Pending");
break;
case "item_type":
/*
@field:review.item_type
@description:Returns the name of the reviewed item type
*/
$type =& $objItemTypes->GetItem($this->Get("ItemType"));
if(is_object($type))
$ret = $type->Get("ItemName");
break;
case "date":
/*
@field:review.date
@description:Returns the date/time the review was created
@attrib:_tz:bool:Convert the date to the user's local time
@attrib:_part::Returns part of the date. The following options are available: month,day,year,time_24hr,time_12hr
*/
$d = $this->Get("CreatedOn");
if($element->attributes["_tz"])
{
$d = GetLocalTime($d,$objSession->Get("tz"));
}
$part = strtolower($element->attributes["_part"]);
if(strlen($part))
{
$ret = ExtractDatePart($part,$d);
}
else
{
if($d<=0)
{
$ret = "";
}
else
$ret = LangDate($d);
}
break;
case "reviewer":
/*
@field:revier.reviewer
@description:Parse a user tag for the user submitting the review
@attrib:_usertag::User tag to parse, defaults to the users login name
*/
$userfield = $element->attributes["_usertag"];
if(!strlen($userfield))
{
$userfield = "login";
}
if($this->Get("CreatedById")>0)
{
$u =& $objUsers->GetItem($this->Get("CreatedById"));
$e = new clsHtmlTag();
$e->name = $u->TagPrefix;
$e->attributes = $element->attributes;
$e->attributes["_field"] = $userfield;
$ret = $u->ParseObject($e);
}
else
if($userfield=="login")
$ret = "root";
break;
default:
$tag = $this->TagPrefix."_".$field;
$ret = "Undefined: ".$tag->name;
break;
}
}
else
{
$ret = $element->Execute();
}
return $ret;
}
function parsetag($tag)
{
global $objConfig, $objUsers, $objItemTypes;
if(is_object($tag))
{
$tagname = $tag->name;
}
else
$tagname = $tag;
switch($tagname)
{
case "review_id":
return $this->Get("ReviewId");
break;
case "review_item_id":
return inp_unescape($this->Get("ItemId"));
break;
case "review_text":
return $this->Get("ReviewText");
break;
case "review_ip_address":
return $this->Get("IPAddress");
break;
case "review_pending":
return $this->Get("Pending");
break;
case "review_item_type":
$type =& $objItemTypes->GetItem($this->Get("ItemType"));
$res = $type->Get("ItemName");
return $res;
break;
case "review_created_date":
return LangDate($this->Get("CreatedOn"));
break;
case "review_created_time":
if($this->Get("CreatedOn")<=0)
return "";
return adodb_date($objConfig->TimeFormat(), $this->Get("CreatedOn"));
break;
case "review_created_date_month":
return adodb_date("m", $this->Get("CreatedOn"));
break;
case "review_created_date_day":
return adodb_date("d", $this->Get("CreatedOn"));
break;
case "review_created_date_year":
return adodb_date("Y", $this->Get("CreatedOn"));
break;
default:
if (substr($tagname, 0, 16) == "review_createdby")
{
/* parse the created by user */
$u = $objUsers->GetUser($this->Get("CreatedById"));
$usertag = substr($tag,17);
return $u->parsetag($usertag);
}
else
return "Undefined:$tagname";
break;
}
}
function SendUserEventMail($Suffix,$ToUserId,$LangId=NULL)
{
global $objItemTypes, $objMessageList;
$type =& $objItemTypes->GetItem($this->Get("ItemType"));
$res = $type->Get("ItemName");
$EventName = $res.$Suffix;
$Event =& $objMessageList->GetEmailEventObject($EventName,0,$LangId);
if(is_object($Event))
{
if($Event->Get("Enabled")=="1")
{
$Event->Item = $this;
return $Event->SendToUser($ToUserId);
}
}
}
function SendAdminEventMail($EventName,$LangId=NULL)
{
- global $objItemTypes,$objMessageList;
+ global $objItemTypes, $objMessageList;
$type =& $objItemTypes->GetItem($this->Get("ItemType"));
$res = $type->Get("ItemName");
- $EventName = $res.$Suffix;
+ $EventName = $res; //.$Suffix;
$Event =& $objMessageList->GetEmailEventObject($EventName,1,$LangId);
if(is_object($Event))
{
if($Event->Get("Enabled")=="1")
{
$Event->Item = $this;
return $Event->SendAdmin($ToUserId);
}
}
}
} /*clsIItemReview*/
class clsItemReviewList extends clsItemCollection
{
var $itemID;
var $Page;
var $PerPageVar;
function clsItemReviewList($id=NULL)
{
$this->clsItemCollection();
$this->classname = "clsItemReview";
$this->SourceTable = GetTablePrefix()."ItemReview";
$this->Page = 1;
$this->PerPageVar = "Perpage_Review";
if(isset($id))
$this->itemID=$id;
$this->AdminSearchFields = array("ReviewText");
}
function ItemCount()
{
return $this->NumItems();
}
function GetReview($ID)
{
return $this->GetItem($ID);
}
function GetReviewList($StatusWhere = "Status=1", $OrderBy=NULL)
{
$this->Clear();
$where = "ItemId=".$this->itemID;
$sql = "SELECT * FROM ".$this->SourceTable." WHERE ";
if(strlen($StatusWhere))
$where .= " AND ".$StatusWhere;
$sql .= $where;
if(strlen($OrderBy))
$sql .= " ORDER BY ".$OrderBy;
$Limit = $this->GetLimitSQL();
if(strlen($Limit))
$sql .= " ".$Limit;
$this->QueryItemCount=TableCount($this->SourceTable,$where,0);
return $this->Query_item($sql);
}
function GetItemReviewCount($TodayOnly = FALSE)
{
$sql = "SELECT count(*) as ItemCount FROM ".$this->SourceTable." WHERE ItemId=".$this->itemID." AND Status=1";
if($TodayOnly)
{
$today = mktime(0,0,0,date("m"),date("d"),date("Y"));
$where .= " AND CreatedOn>=$today";
}
$rs = $this->adodbConnection->execute($sql);
$count=0;
if($rs)
$count = $rs->fields["ItemCount"];
return (int)$count;
}
function ip_exists($ip,$id)
{
return ip_exists($ip,id,$this->SourceTable);
}
function GetLimitSQL()
{
global $objConfig;
if($this->Page<1)
$this->Page=1;
$PerPage = $objConfig->Get($this->PerPageVar);
if(is_numeric($PerPage))
{
$Start = ($this->Page-1)*$PerPage;
$limit = "LIMIT ".$Start.",".$PerPage;
}
else
$limit = NULL;
return $limit;
}
function Query_Review($whereClause=NULL,$orderByClause=NULL)
{
global $Errors;
$this->Clear();
$sql = "SELECT * FROM ".$this->SourceTable." ";
if(isset($whereClause) && strlen(trim($whereClause))>0)
$sql = sprintf("%s WHERE %s",$sql,$whereClause);
if(isset($orderByClause) && strlen(trim($orderByClause))>0)
$sql = sprintf("%s ORDER BY %s",$sql,$orderByClause);
return $this->Query_Item($sql);
}
function &AddReview($CreatedOn,$ReviewText, $Status, $IPAddress,
$Priority, $ItemId,$ItemType,$CreatedById,$TextFormat=0,$Module)
{
global $objSession;
$r = new clsItemReview(NULL,$this->SourceTable);
$ReviewText = str_replace("env=".$objSession->GetSessionKey(), "env=",$ReviewText);
//$r->debuglevel = 1;
$r->Set(array("CreatedOn","ReviewText","Status", "IPAddress",
"Priority","ItemId","ItemType","CreatedById","TextFormat","Module"),
array($CreatedOn,$ReviewText,$Status, $IPAddress,
$Priority, $ItemId,$ItemType,$CreatedById,$TextFormat,$Module));
$r->Create();
array_push($this->Items,$r);
if($Status==1)
{
$r->SendUserEventMail("REVIEW.ADD",$CreatedById);
$r->SendAdminEventMail("REVIEW.ADD");
}
else
{
$r->SendUserEventMail("REVIEW.ADD.PENDING",$CreatedById);
$r->SendAdminEventMail("REVIEW.ADD.PENDING");
}
return $r;
}
function EditReview($ReviewId,$CreatedOn,$ReviewText, $Status,
$IPAddress, $Priority, $ItemId,$ItemType,$CreatedById,$TextFormat,$Module)
{
global $objSession;
$r = $this->GetItem($ReviewId);
if($CreatedById==0)
$CreatedById = $r->Get("CreatedById");
$r->Set(array("ReviewId","CreatedOn","ReviewText","Status",
"IPAddress", "Priority", "ItemId","ItemType","CreatedById","TextFormat","Module"),
array($ReviewId,$CreatedOn,$ReviewText,$Status,
$IPAddress, $Priority, $ItemId,$ItemType,$CreatedById,$TextFormat,$Module));
$r->Update();
//$r->SendUserEventMail("REVIEW.MODIFY",$objSession->Get("PortalUserId"));
$r->SendAdminEventMail("REVIEW.MODIFY");
return $r;
}
function DeleteReview($ReviewId)
{
$r = $this->GetItem($ReviewId);
$r->Delete();
}
function CopyToItemId($OldId,$NewId)
{
$this->Clear();
$this->Query_Review("ItemId=$OldId","");
if($this->NumItems()>0)
{
foreach($this->Items as $i)
{
$i->Set("ItemId",$NewId);
$i->UnsetIdField();
$i->Create();
}
}
}
function CopyFromEditTable($ResourceId)
{
global $objSession;
$edit_table = $objSession->GetEditTable($this->SourceTable);
$idlist = array();
$sql = "SELECT * FROM $edit_table";
$this->Clear();
$rs = $this->adodbConnection->Execute($sql);
while($rs && !$rs->EOF)
{
$data = $rs->fields;
$c = $this->AddItemFromArray($data);
$c->Dirty();
if($data["ReviewId"]>0)
{
$c->Update();
}
else
{
$c->UnsetIdField();
$c->Create();
}
$idlist[] = $c->Get("ReviewId");
$rs->MoveNext();
}
$sql = "DELETE FROM ".$this->SourceTable." WHERE ItemId=$ResourceId AND ReviewId NOT IN (".implode(",",$idlist).")";
$this->adodbConnection->Execute($sql);
@$this->adodbConnection->Execute("DROP TABLE IF EXISTS ".$edit_table);
}
function GetPageLinkList(&$UpdateVar,$dest_template=NULL,$page = NULL,$PagesToList=10,$HideEmpty=TRUE)
{
global $objConfig, $var_list_update, $var_list;
if(!strlen($page))
$page = GetIndexURL();
$PerPage = $objConfig->Get($this->PerPageVar);
if($PerPage<1)
$PerPage=20;
$NumPages = ceil($this->GetNumPages($PerPage));
if($NumPages==1 && $HideEmpty)
return "";
if(strlen($dest_template))
{
$var_list_update["t"] = $dest_template;
}
else
$var_list_update["t"] = $var_list["t"];
$o = "";
if($this->Page>$NumPages)
$this->Page=$NumPages;
$StartPage = (int)$this->Page - ($PagesToList/2);
if($StartPage<1)
$StartPage=1;
$EndPage = $StartPage+($PagesToList-1);
if($EndPage>$NumPages)
{
$EndPage = $NumPages;
$StartPage = $EndPage-($PagesToList-1);
if($StartPage<1)
$StartPage=1;
}
$o = "";
if($StartPage>1)
{
$UpdateVar["rp"] = $this->Page-$PagesToList;
$prev_url = $page."?env=".BuildEnv();
$o .= "<A HREF=\"$prev_url\"><<</A>";
}
for($p=$StartPage;$p<=$EndPage;$p++)
{
if($p!=$this->Page)
{
$UpdateVar["rp"]=$p;
$href = $page."?env=".BuildEnv();
$o .= " <A HREF=\"$href\" >$p</A> ";
}
else
{
$o .= "$p";
}
}
if($EndPage<$NumPages && $EndPage>0)
{
$UpdateVar["rp"]=$this->Page+$PagesToList;
$next_url = $page."?env=".BuildEnv();
$o .= "<A HREF=\"$next_url\"> >></A>";
}
unset($UpdateVar,$var_list_update["t"] );
return $o;
}
} /*clsItemReviewList*/
?>
Property changes on: trunk/kernel/include/itemreview.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.3
\ No newline at end of property
+1.4
\ No newline at end of property
Index: trunk/kernel/include/item.php
===================================================================
--- trunk/kernel/include/item.php (revision 329)
+++ trunk/kernel/include/item.php (revision 330)
@@ -1,977 +1,977 @@
<?php
require_once($pathtoroot."kernel/include/itemreview.php");
require_once($pathtoroot."kernel/include/itemrating.php");
class clsItem extends clsParsedItem
{
var $type;
var $Reviews;
var $Related;
var $Images;
var $PrimaryCat;
var $IsNew = FALSE;
var $IsHot = FALSE;
var $IsPop = FALSE;
var $Keywords;
var $OpenTagVar;
var $CloseTagVar;
var $AdminParser;
var $CustomFields;
var $FieldClass;
var $CustomLoaded=0;
var $ReviewSortOrder;
var $ReviewPerPageVar;
function clsItem($FullItem=FALSE)
{
$this->clsParsedItem();
if($FullItem==TRUE)
{
$this->Reviews = new clsItemReviewList();
$this->Related = new clsRelationshipList();
}
$this->Images = new clsImageList();
$this->CustomFields = array();
$this->FieldClass = new clsCustomFieldList();
}
function ClearCacheData()
{
}
/* item reviews */
function &GetItemReviews($Page=1)
{
$res_id = $this->Get("ResourceId");
$this->Reviews->itemID=$res_id;
$this->Reviews->PerPageVar = $this->ReviewPerPageVar;
$this->Reviews->Page = $Page;
$this->Reviews->GetReviewList("Status=1",$this->ReviewSortOrder);
return $this->Reviews;
}
function ReviewCount($TodayOnly=FALSE)
{
if(is_numeric($this->Get("CachedReviewsQty")) && !$TodayOnly)
return (int)$this->Get("CachedReviewsQty");
$this->Reviews->itemID=$this->Get("ResourceId");
return (int)$this->Reviews->GetItemReviewCount($TodayOnly);
}
function ReviewsLoaded()
{
if($this->Reviews->itemID==$this->Get("ResourceId"))
{
return $this->Reviews->ItemCount();
}
else
return 0;
}
function &AddReview($createdBy,$reviewText,$isPending,$ip=NULL,$ForceIP=0, $Module="")
{
$this->Reviews->itemID=$this->Get("ResourceId");
if($ip == NULL)
$ip = $_SERVER["REMOTE_ADDR"];
$CreatedOn = mktime(0,0,0,adodb_date("m"),adodb_date("d"),adodb_date("Y"));
$Status=1;
if($isPending)
$Status=2;
$AutoModule = GetModuleByAction(); // determine module name by action
- //echo "Auto Module: $AutoModule<br>";
+ if( $Module && ($AutoModule != $Module) ) $AutoModule = $Module;
$r = $this->Reviews->AddReview($CreatedOn,$reviewText,$Status,$ip,0,$this->Get("ResourceId"),$this->type,$createdBy,0,$AutoModule);
$this->Increment("CachedReviewsQty");
return $r;
}
function ReviewIPExists($ip)
{
return ip_exists($ip,$this->Get("ResourceId"),$this->Reviews->SourceTable);
}
function DeleteReview($reviewID)
{
$r = $this->Reviews->GetReview($reviewID);
if(is_object($r))
{
$r->Delete();
$this->Decrement("CachedReviewsQty");
}
}
function DeleteReviews()
{
$res_id = $this->Get("ResourceId");
if($res_id)
{
$sql = "DELETE FROM ".GetTablePrefix()."ItemReview WHERE ResourceId=$res_id";
$this->adodbConnection->Execute($sql);
unset($this->Reviews);
$this->Reviews = new clsItemReviewList($res_id);
}
}
/* item custom fields */
function LoadCustomFields()
{
if(!$this->CustomLoaded && $this->Get("ResourceId")>0)
{
$this->FieldClass = new clsCustomFieldList();
$this->FieldClass->Type = $this->type;
$this->FieldClass->LoadFieldsAndValues($this->Get("ResourceId"));
foreach($this->FieldClass->Items as $f)
{
$this->CustomFields[$f->Get("FieldName")] = $f->HasField('Value') ? $f->Get('Value') : '';
}
$this->CustomLoaded = 1;
}
}
function SetCustomField($fieldname,$value)
{
// echo "Setting CF [<b>$fieldname</b>] = [$value]<br>";
if(!$this->CustomLoaded)
$this->LoadCustomFields();
$this->CustomFields[$fieldname] = $value;
}
function SaveCustomFields()
{
//echo "Saving CFs<br>";
if(!(int)$this->Get("ResourceId"))
return TRUE;
if(!$this->CustomLoaded)
return TRUE;
$data = new clsCustomDataList();
$data->LoadResource($this->Get("ResourceId"));
foreach($this->FieldClass->Items as $f)
{
$value = $this->CustomFields[$f->Get("FieldName")];
$data->SetFieldValue($f->Get("CustomFieldId"),$this->Get("ResourceId"),$value);
}
$data->SaveData();
unset($data);
}
function GetCustomFieldValue($fieldname,$default="")
{
if(!$this->CustomLoaded)
$this->LoadCustomFields();
if(isset($this->CustomFields[$fieldname]))
{
$ret = $this->CustomFields[$fieldname];
}
else
$ret = $default;
return $ret;
}
function DeleteCustomData()
{
$cdata = new clsCustomDataList();
$cdata->DeleteResource($this->Get("ResourceId"));
}
function Delete($RecordOnly=FALSE)
{
global $objFavorites;
if($RecordOnly==FALSE)
{
$this->DeleteReviews();
$this->DeleteRelations();
$this->DeleteCustomData();
if($this->NoResourceId==0)
{
if($this->UsingTempTable()==FALSE)
{
if(is_object($this->Images))
$this->Images->DeleteResource($this->Get("ResourceId"));
$objFavorites->DeleteItem($this->Get("ResourceId"));
}
}
}
parent::Delete();
}
/* item relationships */
function GetRelatedItems()
{
global $objConfig;
$where = "SourceId = ".$this->Get("ResourceId");
$where .= " OR (TargetId=".$this->Get("ResourceId")." AND Type=1)";
$orderBy = $objConfig->Get("Relation_Sortfield")." ".$objConfig->Get("Relation_Sortorder");
$orderBy = trim($orderBy);
$this->Related->Clear();
$res = $this->Related->LoadRelated($where,$orderBy);
return $res;
}
function &RelationObject()
{
return $this->Related;
}
function DeleteRelations()
{
$res_id = $this->Get("ResourceId");
if($res_id)
{
$sql = "DELETE FROM ".GetTablePrefix()."Relationship WHERE SourceId=$res_id OR TargetId=$res_id";
$this->adodbConnection->Execute($sql);
unset($this->Reviews);
$this->Related = new clsRelationshipList($res_id);
}
}
/* keyword highlighting for searches */
function HighlightField($field)
{
global $objConfig;
if(/*!strlen($OpenTag) || !strlen($CloseTag) ||*/ !is_array($this->Keywords))
{
//echo "Missing something<br>\n";
return $this->Get($field);
}
if(strlen($this->OpenTagVar))
$OpenTag = $objConfig->Get($this->OpenTagVar);
if(strlen($this->CloseTagVar))
$CloseTag = $objConfig->Get($this->CloseTagVar);
$k = array_merge($this->Keywords["required"],$this->Keywords["normal"]);
if(count($k))
{
$result = HighlightKeywords($k, $this->Get($field), $OpenTag, $CloseTag);
}
else
{
$result = $this->Get($field);
//echo "No Keywords<br>\n";
}
return $result;
}
function HighlightText($text)
{
global $objConfig;
if(strlen($this->OpenTagVar))
$OpenTag = $objConfig->Get($this->OpenTagVar);
if(strlen($this->CloseTagVar))
$CloseTag = $objConfig->Get($this->CloseTagVar);
if(!strlen($OpenTag) || !strlen($CloseTag) || !is_array($this->Keywords))
return $text;
$k = array_merge($this->Keywords["required"],$this->Keywords["normal"]);
if(count($k))
{
$result = HighlightKeywords($k,$text, $OpenTag, $CloseTag);
}
else
$result = $text;
return $result;
}
/* item status functions */
function Is($name)
{
$var = "m_" . $name;
return ( isset($this->$var) && $this->$var ) ? true : false;
}
function IsHotItem()
{
switch($this->Get("HotItem"))
{
case ALWAYS:
return TRUE;
break;
case NEVER:
return FALSE;
break;
case AUTO:
return $this->IsHot;
break;
}
}
function SetHotItem()
{
$this->IsHot = FALSE;
}
function IsNewItem()
{
switch($this->Get("NewItem"))
{
case ALWAYS:
return TRUE;
break;
case NEVER:
return FALSE;
break;
case AUTO:
return $this->IsNew;
break;
}
}
function SetNewItem()
{
$this->IsNew = FALSE;
}
function IsPopItem()
{
switch($this->Get("PopItem"))
{
case ALWAYS:
return TRUE;
break;
case NEVER:
return FALSE;
break;
case AUTO:
return $this->IsPop;
break;
}
}
function SetPopItem()
{
$this->IsPop = FALSE;
}
function SetFromArray($data, $dirty = false)
{
parent::SetFromArray($data, $dirty);
if(is_array($data))
{
if(array_key_exists("NewItem",$data))
{
$this->SetNewItem();
}
if(array_key_exists("HotItem",$data))
{
$this->SetHotItem();
}
if(array_key_exists("PopItem",$data))
{
$this->SetPopItem();
}
}
}
function Validate()
{
/* skeleton*/
return true;
}
function LoadFromDatabase($Id, $IdField = null) // custom IdField by Alex)
{
/* skeleton */
parent::LoadFromDatabase($Id, $IdField);
}
//Changes priority
function MoveDown()
{
$this->Decrement("Priority");
}
function MoveUp()
{
$this->Increment("Priority");
}
function CheckPermission($permissionName)
{
//Check permission and if needs approval set approval
global $objSession,$objCatList;
$perm = $this->BasePermission;
if(strlen($perm)>0)
$perm .= ".";
$perm .= $permissionName;
//get an instance of the forum category
$cat =& $objCatList->GetCategory($this->Get("CategoryId"));
if(!is_object($cat))
{
return FALSE;
}
else
{
return ($cat->HasPermission($perm,$objSession->Get("GroupId")));
}
}
function SubmitVote($voteRating, $voteNotes)
{
global $Errors;
global $REMOTE_ADDR;
if($this->rating_ip_exists($REMOTE_ADDR))
{
// $Errors->AddError("error.already_voted","","","",get_class($this),"SubmitVote");
return false;
}
$vote = new clsItemRating(NULL);
$vote->Set("ItemId",$this->UniqueId());
$vote->Set("RatingValue",$voteRating);
if(!$vote->Create())
return false;
$NumVotes = (int)$this->Get("CachedVotesQty");
$CurrentRating = (int)$this->Get("CachedRating");
$Rating = (($NumVotes * $CurrentRating) + $voteRating)/($NumVotes+1);
$this->Set("CachedRating",$Rating);
$this->Update();
$this->Increment("CachedVotesQty");
}
function rating_ip_exists($ip)
{
$count = 0;
$id = $this->Get("ResourceId");
$sql = "SELECT count(*) as DupCount FROM ItemRating WHERE IPAddress='$ip' and ItemId=$id";
$adodbConnection = GetADODBConnection();
$rs = $adodbConnection->Execute($sql);
if($rs)
{
$count = $rs->fields["DupCount"];
}
return ($count>0);
//return FALSE;
}
function PurgeRatings()
{
global $objConfig;
$expired=time()-86400*$objConfig->Get("Timeout_Rating");
$query="DELETE FROM ItemRating WHERE CreatedOn<$expired";
$this->adodbConnection->Execute($query);
}
function GetThumbnailImage()
{
if($this->Images->NumItems()==0)
$this->Images->GetResourceImages($this->Get("ResourceId"));
return $this->Images->GetResourceThumbnail($this->Get("ResourceId"));
}
function GetImage($number)
{
return $this->Images->GetImageByResource($this->Get("ResourceId"),$number);
}
function GetImageByName($name)
{
if(!is_object($this->Images))
$this->Images = new clsImageList();
return $this->Images->GetImageByName($this->Get("ResourceId"),$name);
}
function &GetDefaultImage()
{
return $this->Images->GetDefaultImage($this->Get("ResourceId"));
}
function CreatePendingCopy()
{
$OrgId = $this->IdField();
$this->Dirty();
$this->Set("OrgId",$OrgId);
$this->UnsetIdField();
$this->Set("ResourceId",0);
$this->Set("Status",-2);
$this->Create();
}
function AddFavorite($PortalUserId=NULL)
{
global $objSession, $objFavorites;
$res = FALSE;
if($objSession->HasCatPermission("FAVORITES"))
{
if(!$PortalUserId)
$PortalUserId = $objSession->Get("PortalUserId");
if($PortalUserId==$objSession->Get("PortalUserId") || $objSession->HasSystemPermission("ADMIN"))
{
$objFavorites->AddFavorite($PortalUserId,$this->Get("ResourceId"), $this->type);
$res = TRUE;
}
}
return $res;
}
function DeleteFavorite($PortalUserId=NULL)
{
global $objSession, $objFavorites;
$res = FALSE;
if($objSession->HasCatPermission("FAVORITES"))
{
if(!$PortalUserId)
$PortalUserId = $objSession->Get("PortalUserId");
//echo $PortalUserId." ".$objSession->Get("PortalUserId");
if($PortalUserId==$objSession->Get("PortalUserId") || $objSession->HasSystemPermission("ADMIN"))
{
$objFavorites->DeleteFavorite($PortalUserId,$this->Get("ResourceId"));
$res = TRUE;
}
}
return $res;
}
function IsFavorite($PortalUserId=NULL)
{
global $objSession, $objFavorites;
$res = FALSE;
if($objSession->HasCatPermission("FAVORITES"))
{
if(!$PortalUserId)
$PortalUserId = $objSession->Get("PortalUserId");
if($PortalUserId==$objSession->Get("PortalUserId") || $objSession->HasSystemPermission("ADMIN"))
{
$i = $objFavorites->GetFavoriteObject($PortalUserId,$this->Get("ResourceId"));
if(is_object($i))
{
$res = TRUE;
}
else
$res = FALSE;
}
}
return $res;
}
function CheckBanned()
{
global $objBanList;
$objBanList->LoadItemRules($this->type);
$found = FALSE;
$MatchedRule = 0;
foreach($objBanList->Items as $b)
{
$field = $b->Get("ItemField");
if($this->FieldExists($field))
{
$ThisValue = strtolower($this->Get($field));
$TestValue = strtolower($b->Get("ItemValue"));
switch($b->Get("ItemVerb"))
{
case 0: /* any */
$found = TRUE;
break;
case 1: /* is */
if($ThisValue==$TestValue)
$found = TRUE;
break;
case 2: /* is not */
if($ThisValue != $TestValue)
$found = TRUE;
break;
case 3: /* contains */
if(strstr($ThisValue,$TestValue))
$found = TRUE;
break;
case 4: /* not contains */
if(!strstr($ThisValue,$TestValue))
$found = TRUE;
break;
case 5: /* Greater Than */
if($TestValue > $ThisValue)
$found = TRUE;
break;
case 6: /* Less Than */
if($TestValue < $ThisValue)
$found = TRUE;
break;
case 7: /* exists */
if(strlen($ThisValue)>0)
$found = TRUE;
break;
case 8: /* unique */
if($this->ValueExists($field,$ThisValue))
$found = TRUE;
break;
}
}
if($found)
{
if($b->Get("RuleType")==0)
{
$MatchedRule = $b->Get("RuleId");
}
else
{
$MatchedRule = 0;
}
break;
}
}
return $MatchedRule;
}
} /* clsItem */
class clsCatItem extends clsItem
{
function clsCatItem($FullItem=FALSE)
{
$this->clsItem($FullItem);
}
function Delete($RecordOnly=FALSE)
{
global $objFavorites;
parent::Delete($RecordOnly);
if($RecordOnly==FALSE)
{
$this->RemoveFromAllCategories();
}
}
/* category membership functions */
function AssignPrimaryCategory($SourceTable)
{
$catid = 0;
$sql = "SELECT * FROM $SourceTable WHERE ItemResourceId=".$this->Get("ResourceId")." LIMIT 1";
$rs = $this->adodbConnection->Execute($sql);
if($rs && !$rs->EOF)
{
$catid = $rs->fields["CategoryId"];
$this->SetPrimaryCategory($catid,$SourceTable);
}
return $catid;
}
function GetPrimaryCategory($SourceTable = "")
{
if(is_numeric($this->PrimaryCat))
return $this->PrimaryCat;
$this->PrimaryCat="";
if( strlen($SourceTable) == 0 ) $SourceTable = GetTablePrefix()."CategoryItems";
$res_id = $this->HasField('ResourceId') ? $this->Get('ResourceId') : 0;
$sql = "SELECT * FROM $SourceTable WHERE ItemResourceId=".$res_id." AND PrimaryCat=1";
$rs = $this->adodbConnection->Execute($sql);
if($rs && !$rs->EOF)
{
$this->PrimaryCat=$rs->fields["CategoryId"];
return $this->PrimaryCat;
}
else
{
$this->AssignPrimaryCategory($SourceTable);
return $this->PrimaryCat;
}
}
function SetPrimaryCategory($CategoryId,$SourceTable = "")
{
if(strlen($SourceTable)==0)
$SourceTable = GetTablePrefix()."CategoryItems";
$rs = $this->adodbConnection->Execute('SELECT * FROM '.$SourceTable.' WHERE CategoryId='.$CategoryId.' AND ItemResourceId='.$this->Get("ResourceId"));
$this->adodbConnection->Execute("UPDATE $SourceTable SET PrimaryCat=0 WHERE ItemResourceId=".$this->Get("ResourceId"));
$this->adodbConnection->Execute("UPDATE $SourceTable SET PrimaryCat=1 WHERE CategoryId=$CategoryId AND ItemResourceId=".$this->Get("ResourceId"));
$this->PrimaryCat=$CategoryId;
}
function CategoryMemberCount($SourceTable="")
{
if(strlen($SourceTable)==0)
$SourceTable = GetTablePrefix()."CategoryItems";
$sql = "SELECT count(*) as CatCount FROM $SourceTable WHERE ItemResourceId=".$this->Get("ResourceId");
if($this->debuglevel)
echo $sql."<br>\n";
$rs = $this->adodbConnection->Execute($sql);
$count = 0;
if($rs && !$rs->EOF)
$count = $rs->fields["CatCount"];
return $count;
}
function CategoryMemberList($SourceTable="")
{
$cats = array();
if(strlen($SourceTable)==0)
$SourceTable = GetTablePrefix()."CategoryItems";
$sql = "SELECT * FROM $SourceTable WHERE ItemResourceId=".$this->Get("ResourceId");
if($this->debuglevel)
echo $sql."<br>\n";
$rs = $this->adodbConnection->Execute($sql);
while($rs && !$rs->EOF)
{
$cats[] = $rs->fields["CategoryId"];
$rs->MoveNext();
}
$catlist = implode(",",$cats);
return $catlist;
}
function AddToCategory($CatId,$SourceTable="",$PrimaryValue=NULL)
{
global $objSession, $objCatList;
if(!$SourceTable)
$SourceTable = GetTablePrefix()."CategoryItems";
if($this->type>0)
{
$Primary = 0;
if(is_numeric($PrimaryValue))
{
$Primary = $PrimaryValue;
if($Primary==1)
$this->PrimaryCat = $CatId;
}
else
{
if(!is_numeric($this->GetPrimaryCategory()))
{
$Primary =1;
$this->PrimaryCat = $CatId;
}
}
// check if not exists
$db =& $this->adodbConnection;
$sql = sprintf('SELECT * FROM %s WHERE CategoryId = %s AND ItemResourceId = %s', $SourceTable, $CatId, $this->Get("ResourceId"));
$rs = $db->Execute($sql);
if($rs->RecordCount() == 0 )
{
$sql = "INSERT INTO $SourceTable (CategoryId,ItemResourceId, PrimaryCat) VALUES ('$CatId','".$this->Get("ResourceId")."',$Primary)";
if($this->debuglevel)
echo $sql."<br>\n";
$this->adodbConnection->Execute($sql);
}
$c = $objCatList->GetCategory($CatId);
}
}
function RemoveFromCategory($CatId,$SourceTable="",$Force=0)
{
global $objSession, $objCatList;
if(strlen($SourceTable)==0)
$SourceTable = GetTablePrefix()."CategoryItems";
if($this->type>0)
{
$primary = $this->GetPrimaryCategory();
if(($primary==$CatId && $this->CategoryMemberCount($SourceTable)>1) || ($primary != $CatId) || $Force)
{
$sql = "DELETE FROM $SourceTable WHERE CategoryId=$CatId AND ItemResourceId=".$this->Get("ResourceId");
if($objSession->HasSystemPermission("DEBUG.LIST"))
echo $sql."<br>\n";
$this->adodbConnection->Execute($sql);
$c = $objCatList->GetCategory($CatId);
$c->ClearCacheData();
}
}
}
function MoveToCategory($OldCatId,$NewCatId,$SourceTable="")
{
if(strlen($SourceTable)==0)
$SourceTable = GetTablePrefix()."CategoryItems";
$sql = "UPDATE $SourceTable SET CategoryId=$NewCatId WHERE CategoryId=$OldCatId AND ItemResourceId=".$this->Get("ResourceId");
if($this->debuglevel)
echo $sql."<br>\n";
$this->adodbConnection->Execute($sql);
}
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)
echo $sql."<br>\n";
$this->adodbConnection->Execute($sql);
}
}
function RemoveFromAllCategories($SourceTable = "")
{
if(strlen($SourceTable)==0)
$SourceTable = GetTablePrefix()."CategoryItems";
if($this->type>0)
{
$sql = "SELECT * FROM $SourceTable WHERE ResourceId=".$this->Get("ResourceId");
$rs = $this->adodbConnection->Execute($sql);
while ($rs && !$rs->EOF)
{
$CategoryId = $rs->fields["CategoryId"];
$rs->MoveNext();
}
$sql = "DELETE FROM $SourceTable WHERE ResourceId=".$this->Get("ResourceId");
if($this->debuglevel)
echo $sql."<br>\n";
$this->adodbConnection->Execute($sql);
}
}
function CopyToNewResource($TargetCat = NULL,$NameField="Name")
{
global $objSession;
$CatList = $this->CategoryMemberList();
$Cats = explode(",",$CatList);
//echo "Target: $TargetCat<br>";
$OldId = $this->Get("ResourceId");
$this->UnsetIdField();
$this->Dirty();
if(!is_numeric($this->Get("OrgId")))
$this->UnsetField("OrgId");
$this->UnsetField("ResourceId");
if(is_numeric($TargetCat) && strlen($NameField))
{
$OldName = $this->Get($NameField);
if(substr($OldName,0,5)=="Copy ")
{
$parts = explode(" ",$OldName,4);
if($parts[2]=="of" && is_numeric($parts[1]))
{
$Name = $parts[3];
}
else
if($parts[1]=="of")
{
$Name = $parts[2]." ".$parts[3];
}
else
$Name = $OldName;
}
else
$Name = $OldName;
$Names = CategoryItemNameCount($TargetCat,$this->tablename,$NameField,$Name);
if(count($Names)>0)
{
$NameCount = count($Names);
$found = FALSE;
$NewName = "Copy of $Name";
if(!in_array("Copy of $Name",$Names))
{
$found = TRUE;
}
else
{
for($x=2;$x<$NameCount+2;$x++)
{
$NewName = "Copy ".$x." of ".$Name;
if(!in_array($NewName,$Names))
{
$found = TRUE;
break;
}
}
}
if(!$found)
{
$NameCount++;
$NewName = "Copy $NameCount of $Name";
}
$this->Set($NameField,$NewName);
}
}
$this->Create();
// copy relationships
$NewId = $this->Get("ResourceId");
$reldata = new clsRelationshipList($DestCat,$this->IdField());
$reldata->CopyToResource($OldId,$NewId);
// copy reviews
$rdata = new clsItemReviewList();
$rdata->CopyToItemId($OldId,$NewId);
unset($rdata);
// copy custom fields
$cdata = new clsCustomDataList();
$cdata->CopyResource($OldId,$NewId);
unset($cdata);
// copy images
if(is_object($this->Images))
$this->Images->CopyResource($OldId,$NewId);
$this->AddToCategory($TargetCat, '', 0); // insert (but with duplicate records check)
//echo "ok";
if(is_numeric($TargetCat))
{
if(is_array($Cats))
{
if(!in_array($TargetCat,$Cats))
{
$this->AddToCategory($TargetCat, 0); // insert
}
}
$this->SetPrimaryCategory($TargetCat); // 2 updates
}
}
}
?>
\ No newline at end of file
Property changes on: trunk/kernel/include/item.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.4
\ No newline at end of property
+1.5
\ No newline at end of property
Event Timeline
Log In to Comment