clsCatItem(TRUE);
$this->tablename=GetTablePrefix()."News";
$this->type=TYPE_NEWS;
$this->Prefix = 'n';
$this->BasePermission="NEWS";
$this->id_field = "NewsId";
$this->TagPrefix="article";
$this->TitleField = 'Title';
if(isset($NewsId))
$this->LoadFromDatabase($NewsId);
if($objSession->HasSystemPermission("DEBUG.ITEM"))
{
$this->SetDebugLevel(1);
}
/* keyword highlighting */
$this->OpenTagVar = "News_Highlight_OpenTag";
$this->CloseTagVar = "News_Highlight_CloseTag";
}
function Validate()
{
global $objSession, $Errors;
$dataValid = true;
if(!strlen($this->Get("Title")))
{
$Errors->AddError("error.fieldIsRequired",'Name',"","",get_class($this),"Validate");
$dataValid = false;
}
if(!(int)($this->Get("CreatedOn")))
{
$Errors->AddError("error.fieldIsRequired",'CreatedOn',"","",get_class($this),"Validate");
$dataValid = false;
}
return $dataValid;
}
function SetNewItem()
{
global $objConfig;
$value = $this->Get("CreatedOn");
$cutoff = adodb_date("U") - ($objConfig->Get("News_NewDays") * 86400);
$this->IsNew = FALSE;
if($value>$cutoff)
$this->IsNew = TRUE;
return $this->IsNew;
}
function SetPopItem()
{
global $objConfig, $objArticleList;
$cutoff = $objArticleList->GetPopValue();
$this->IsPop = FALSE;
if($cutoff>0)
{
if($this->Get('CachedRating') >= $cutoff
&& $this->Get('CachedVotesQty') >= $objConfig->Get('News_MinPopVotes'))
{
$this->IsPop = TRUE;
}
}
return $this->IsPop;
}
function SetHotItem()
{
global $objConfig, $objArticleList;
$this->IsHot = FALSE;
$cutoff = $objArticleList->GetHotValue();
if($cutoff>0)
{
if($this->Get("Hits")>=$cutoff)
$this->IsHot = TRUE;
}
return $this->IsHot;
}
function Approve()
{
if($this->Get("Status")==-2)
{
$this->SendUserEventMail("ARTICLE.MODIFY.APPROVE",$this->Get("CreatedById"));
$this->SendAdminEventMail("ARTICLE.MODIFY.APPROVE");
}
else
{
$this->SendUserEventMail("ARTICLE.APPROVE",$this->Get("CreatedById"));
$this->SendAdminEventMail("ARTICLE.APPROVE");
}
$this->Set("Status", 1);
$this->Update();
}
function Deny()
{
if($this->Get("Status")==-2)
{
$this->SendUserEventMail("ARTICLE.DENY.PENDING",$this->Get("CreatedById"));
$this->SendAdminEventMail("ARTICLE.DENY.PENDING");
}
else
{
$this->SendUserEventMail("ARTICLE.DENY",$this->Get("CreatedById"));
$this->SendAdminEventMail("ARTICLE.DENY");
}
$this->Set("Status", 0);
$this->Update();
}
function LoadFromDatabase($Id)
{
global $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 ".$this->IdField()." = '%s'", $Id);
$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();
}
function LoadFromResourceId($Id)
{
global $objSession, $Errors;
if(!isset($Id))
{
$Errors->AddError("error.AppError",NULL,'Internal error: LoadFromDatabase id',"",get_class($this),"LoadFromResourceId");
return false;
}
$sql = sprintf("SELECT * FROM ".$this->tablename." WHERE ResourceId = '%s'",$Id);
$result = $this->adodbConnection->Execute($sql);
if ($result === false)
{
$Errors->AddError("error.DatabaseError",NULL,$adodbConnection->ErrorMsg(),"",get_class($this),"LoadFromResourceId");
return false;
}
$data = $result->fields;
if(is_array($data))
{
$this->SetFromArray($data);
$this->Clean();
}
return TRUE;
}
function GetGroupIcon()
{
$ret = "groupicons/".$this->m_GroupId.".gif";
return $ret;
}
function StatusIcon()
{
global $rootURL;
$ret = $rootURL."/in-news/admin/images/";
switch($this->Get("Status"))
{
case STATUS_DISABLED:
$ret .= "icon16_article_disabled.gif";
break;
case STATUS_PENDING:
$ret .= "icon16_article_pending.gif";
break;
case STATUS_ACTIVE:
$img = "icon16_article.gif";
if($this->IsPopItem())
$img = "icon16_article_pop.gif";
if($this->IsHotItem())
$img = "icon16_article_hot.gif";
if($this->IsNewItem())
$img = "icon16_article_new.gif";
if($this->Is("EditorsPick"))
$img = "icon16_article_pick.gif";
$ret .= $img;
break;
}
return $ret;
}
function ItemURL($Template=NULL,$SetCat=FALSE,$Action=NULL)
{
global $var_list_update,$var_list,$n_var_list_update,$m_var_list_update;
$url_params = Array();
$var_list_update["t"] = $Template ? $Template : $var_list["t"];
// if($SetCat)
// {
$cat = $this->Get("CategoryId");
if( !is_numeric($cat) ) $cat = $this->GetPrimaryCategory();
$m_var_list_update["cat"] = $cat;
// }
$n_var_list_update["id"] = $this->Get("NewsId");
if( isset($Action) && $Action ) $url_params['Action'] = $Action;
$ret = HREF_Wrapper('', $url_params);
unset($n_var_list_update["id"], $var_list_update["t"],$m_var_list_update["cat"]);
return $ret;
}
function ParseObject($element)
{
global $objConfig, $objCatList, $var_list_update, $var_list, $n_var_list_update, $m_var_list_update, $objSession, $objUsers;
$extra_attribs = ExtraAttributes($element->attributes);
if(strtolower($element->name)==$this->TagPrefix)
{
$field = strtolower($element->attributes["_field"]);
switch($field)
{
case "excerpt":
/*
@field:article.excerpt
@description Returns the artcle excerpt
*/
$ret = $this->HighlightField("Excerpt");
break;
case "body":
/*
@field:article.body
@description:The main body of the article
@attrib:_parsed:bool:If set, HTML and In-Portal tags in the body are preserved, otherwise they are escaped
*/
$this->Increment("Hits", true);
$parsed = $element->attributes["_parsed"];
if($parsed)
{
$body = inp_unescape($this->Get("Body"));
$body = $this->HighlightText($body);
if($this->Get("TextFormat")!=1)
{
$body = nl2br($body);
}
$ret = $this->ParseTemplateText($body);
}
else
$ret = inp_unescape($this->Get("Body"));
$ret = $this->HighlightText($ret);
break;
case "title":
/*
@field:article.title
@description: Article Title (headline)
*/
$ret = $this->HighlightField("Title");
break;
case "author":
/*
@field:article.author
@description:text by-line of the article
*/
$ret = $this->HighlightField("Author");
break;
case "createdby":
/*
@field:article.createdby
@description:parse a user field of the user that created the article
@attrib:_usertag::User field to return (defaults to login ID)
*/
$field = $element->attributes["_usertag"];
if(!strlen($field))
{
$field = "user_login";
}
$userId = $this->Get("CreatedById");
if (!empty($userId) && ($userId > 0))
{
$u =& $objUsers->GetItem($userId);
if (is_object($u))
{
$ret = $u->parsetag($field);
}
}
else
$ret = " ";
break;
case "date":
/*
@field:article.date
@description:Returns the date/time the article 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");
$ret = $this->ParseTimeStamp($d,$element->attributes);
break;
case "modified":
/*
@field:article.modified
@description:Returns the date/time the article was last modified
@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("Modified");
if($d<=0)
$d = $this->Get("CreatedOn");
$ret = $this->ParseTimeStamp($d,$element->attributes);
break;
case "enddate":
/*
@field:article.enddate
@description:Returns the date/time the article is to be archived
@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("EndOn");
$ret = $this->ParseTimeStamp($d,$element->attributes);
break;
/*
@field:article.startdate
@description:Returns the date/time the article is to begin being displayed
@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
*/
case "startdate":
$d = $this->Get("StartDate");
$ret = $this->ParseTimeStamp($d,$element->attributes);
break;
case "add_favorite_link":
/*
@field:article.add_favorite_link
@description:Returns a URL to add this article to the user's favorites
@attrib:_template:tpl:Template URL should point to
*/
if($objSession->HasCatPermission("FAVORITES"))
{
$t = $element->attributes["_template"];
if(!strlen($t))
$t = $var_list["t"];
$ret = $this->ItemURL($t,FALSE,"n_add_favorite");
}
else
{
$t = $element->attributes["_errortemplate"];
if(!strlen($t))
$t = "favorite_error.tpl";
$ret = $this->ItemURL($t,FALSE,"");
}
break;
case "del_favorite_link":
/*
@field:article.del_favorite_link
@description:Returns a URL to remove this article from the user's favorites
@attrib:_template:tpl:Template URL should point to
*/
if($objSession->HasCatPermission("FAVORITES"))
{
$t = $element->attributes["_template"];
if(!strlen($t))
$t = $var_list["t"];
$ret = $this->ItemURL($t,FALSE,"n_del_favorite");
}
else
{
$t = $element->attributes["_errortemplate"];
if(!strlen($t))
$t = "favorite_error.tpl";
$ret = $this->ItemURL($t,FALSE,"");
}
break;
/*
@field:article.favorite_toggle
@description: Returns a link to set or reset the favorite flag for the current user
@attrib: _template:tpl:Template to link to if user has the FAVORITES permission (defaults to current template)
@attrib: _denytemplate:tpl: Template to link to if user does not have favorites permission (ie Guest) Defaults to current template
@attrib: _addlabel:lang:Language tag to display if link is to add favorite
@attrib: _addimage::Image url to include in link if adding favorite
@attrib: _dellabel:lang:Language tag to display if item is already a favorite
@attrib: _delimage::Image url to include in link if removing the favorite
*/
case "favorite_toggle":
$catid = $this->GetPrimaryCategory();
$t = $element->attributes["_template"];
if(!strlen($t))
$t = $var_list["t"];
if($objSession->HasCatPermission('FAVORITES', $catid))
{
if(!$this->IsFavorite($objSession->Get("PortalUserId"), $this->GetPrimaryCategory()))
{
$action = "n_add_favorite";
$label = $element->attributes["_addlabel"];
}
else
{
$action = "n_del_favorite";
$label = $element->attributes["_dellabel"];
}
}
else
{
$action="";
$label = $element->attributes["_addlabel"];
$t = $element->attributes["_errortemplate"];
if(!strlen($t))
$t = "favorite_error.tpl";
}
$ret = "ItemURL($t,FALSE,$action)."\">".language($label)."";
break;
/*
@field:article.hits
@description:Returns number of hits for item
*/
case "hits":
$ret=round($this->Get("Hits"));
break;
/*
@field:article.link
@description:Returns a URL setting the link to the article
@attrib:_template:tpl:Template URL should point to
*/
/*
@field:article.cat_link
@description:Returns a URL setting the article to the current article and the article's category to the current category
@attrib:_template:tpl:Template URL should point to
*/
/*
@field:article.category
@description:Return a category field from the article's category
@attrib:_cattag::Category field to parse
*/
/*
@field:article.reviews
@description:Return the number of reviews for the article
@attrib:_today:bool:Count reviews added today only
*/
/*
@field:article.new
@description:returns text if article's status is "new"
@attrib:_label:lang: Text to return if status is new
*/
/*
@field:article.pop
@description:returns text if article's status is "popular"
@attrib:_label:lang: Text to return if status is popular
*/
/*
@field:article.hot
@description:returns text if article's status is "hot"
@attrib:_label:lang: Text to return if status is "hot"
*/
/*
@field:article.pick
@description:returns text if article's status is "hot"
@attrib:_label:lang: Text to return if status is "hot"
*/
/*
@field:article.rating
@description:Displays the article rating
@attrib:_displaymode:: How the rating should be displayed