clsCatItem(TRUE); //call parent constructor $this->tablename=GetTablePrefix()."Link"; $this->type=TYPE_LINK; $this->BasePermission ="LINK"; $this->id_field = "LinkId"; $this->TagPrefix = "link"; $this->TitleField = 'Name'; $this->ReviewSortOrder = trim($objConfig->Get("Link_ReviewsSort")." ".$objConfig->Get("Link_ReviewsOrder")); $this->ReviewSortOrder .= trim(",".$objConfig->Get("Link_ReviewsSort2")." ".$objConfig->Get("Link_ReviewsOrder2")); $this->Reviews->PerPage = $objConfig->Get("Perpage_LinkReviews"); /* keyword highlighting */ $this->OpenTagVar = "Link_Highlight_OpenTag"; $this->CloseTagVar = "Link_Highlight_CloseTag"; if(isset($LinkId)) $this->LoadFromDatabase($LinkId); if($objSession->HasSystemPermission("DEBUG.ITEM")) { $this->SetDebugLevel(1); } } function DetectChanges($name, $value) { global $objSession; if (!isset($this->Data[$name]) ) return false; //echo "class: ".get_class($this)."
"; if ($this->Data[$name] != $value && $value != '') { //echo "$name Modified tt ".$this->Data[$name]." : $value
"; if ($objSession->GetVariable("HasChanges") != 1) { $objSession->SetVariable("HasChanges", 2); } } } function ClearCacheData() { DeleteModuleTagCache('inlink'); /*$cats = explode(",",$this->CategoryMemberList()); if(is_array($cats)) { foreach($cats as $c) { if(is_numeric($c)) { $evar = "'%:m".$c."%'"; DeleteTagCache("l_list_links","",$evar); DeleteTagCache("l_link_more","",$evar); } } } DeleteTagCache("l_link_modified%",""); DeleteTagCache("LinkPopValue","",""); DeleteTagCache("LinkHotValue","",""); DeleteTagCache("LinkNewValue","","");*/ } function Delete() { parent::Delete(); if($this->tablename==GetTablePrefix()."Link") { $this->ClearCacheData(); // DeleteTagCache("m_itemcount","Link%"); } } function Update($UpdatedBy = null) { parent::Update($UpdatedBy); if($this->tablename == GetTablePrefix().'Link') $this->ClearCacheData(); } function Create() { parent::Create(); if($this->tablename == GetTablePrefix().'Link') $this->ClearCacheData(); } function SetNewItem() { global $objConfig; $value = $this->Get("CreatedOn"); $cutoff = adodb_date("U") - ($objConfig->Get("Link_NewDays") * 86400); $this->IsNew = FALSE; if($value>$cutoff) $this->IsNew = TRUE; return $this->IsNew; } function SetPopItem() { global $objConfig, $objLinkList; $cutoff = $objLinkList->GetPopValue(); $this->IsPop = FALSE; if($cutoff>0) { if($this->Get('CachedRating') >= $cutoff && $this->Get('CachedVotesQty') >= $objConfig->Get('Link_MinVotes')) { $this->IsPop = TRUE; } } return $this->IsPop; } function SetHotItem() { global $objConfig, $objLinkList, $objSession; $this->IsHot = FALSE; $cutoff = $objLinkList->GetHotValue(); if($cutoff>0) { if($this->Get("Hits")>=$cutoff) { $this->IsHot = TRUE; } } return $this->IsHot; } function Approve() { if($this->Get("Status")==-2) { $this->SendUserEventMail("LINK.MODIFY.APPROVE",$this->Get("CreatedById")); $this->SendAdminEventMail("LINK.MODIFY.APPROVE"); } else { $this->SendUserEventMail("LINK.APPROVE",$this->Get("CreatedById")); $this->SendAdminEventMail("LINK.APPROVE"); } $this->Set("Status", 1); $this->Update(); } function Deny() { if($this->Get("Status")==-2) { $this->SendUserEventMail("LINK.DENY.PENDING",$this->Get("CreatedById")); $this->SendAdminEventMail("LINK.DENY.PENDING"); $this->Delete(); } else { $this->SendUserEventMail("LINK.DENY",$this->Get("CreatedById")); $this->SendAdminEventMail("LINK.DENY"); $this->Set("Status", 0); $this->Update(); } } function Validate() { global $objSession, $Errors; $dataValid = true; if(!strlen($this->Get("Name"))) { $Errors->AddError("error.fieldIsRequired",'Name',"","",get_class($this),"Validate"); $dataValid = false; } // if(!isset($this->m_Url)) // { // $Errors->AddError("error.fieldIsRequired",'Url',"","",get_class($this),"Validate"); // $dataValid = false; // } if(!(int)$this->Get("CreatedOn")) { $Errors->AddError("error.fieldIsRequired",'CreatedOn',"","",get_class($this),"Validate"); $dataValid = false; } if(!(int)$this->Get("CreatedById")) { $Errors->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 LinkId = '%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(); return TRUE; } 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 ReviewCount($TodayOnly = FALSE) { // if($TodayOnly==FALSE && is_numeric($this->Get("CachedReviewsQty"))) // return (int)$this->Get("CachedReviewsQty"); //this is a performance boost if(!is_object($this->Reviews)) { $this->Reviews= new clsItemReviewList($this->Get("ResourceId")); } else { $this->Reviews->itemID=$this->Get("ResourceId"); } return $this->Reviews->GetItemReviewCount($TodayOnly); } function StatusIcon() { global $rootURL; $ret = $rootURL."/in-link/admin/images/"; switch(abs($this->Get("Status"))) { case STATUS_DISABLED: $ret .= "icon16_link_disabled.gif"; break; case STATUS_PENDING: $ret .= "icon16_link_pending.gif"; break; case STATUS_ACTIVE: $img = "icon16_link.gif"; if($this->IsPopItem()) $img = "icon16_link_pop.gif"; if($this->IsHotItem()) $img = "icon16_link_hot.gif"; if($this->IsNewItem()) $img = "icon16_link_new.gif"; if($this->Is("EditorsPick")) $img = "icon16_link_pick.gif"; $ret .= $img; break; } return $ret; } function ItemURL($Template=NULL,$SetCat=FALSE,$Action=NULL) { global $var_list_update,$var_list,$l_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; //} $l_var_list_update["id"] = $this->Get("LinkId"); if( isset($Action) && $Action ) $url_params['Action'] = $Action; $ret = HREF_Wrapper('', $url_params); unset($l_var_list_update["id"], $var_list_update["t"],$m_var_list_update["cat"]); return $ret; } function ParseObject($element) { /* when updating this function, update the comments at the top of the file */ global $objConfig, $objCatList, $rootURL, $var_list, $var_list_update, $l_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 'pending_approval': $ret = $this->isPending() ? true : ''; if ($element->GetAttributeByName('_Not')) { $ret = $ret ? '' : true; } break; /* @field:link.url @description:Returns link URL or default value if URL is empty */ case 'url': $ret = $this->Get('Url'); $default = $element->GetAttributeByName('_default'); if( empty($ret) && !empty($default) ) { $ret = language($default); } break; case 'additional_params': $ret = ''; if( $objConfig->Get('Link_UrlStatus') ) { $link_url = addslashes( htmlspecialchars( $this->Get('Url') ) ); $ret = ' onmouseover="window.status = \''.$link_url.'\'; return true;" onmouseout="window.status = \'\';"'; } break; case "name": /* @field:link.name @description:Returns the link name */ //echo "test"; $ret= $this->HighlightField("Name"); break; case "description": /* @field:link.description @description:Link Description @attrib:_maxlength:int:Maximum number of characters to return @attrib:_wordchop:bool:If truncating the description, setting wordchop causes the result to be truncated at the last space before the split */ $ret = inp_unescape(($this->Get("Description"))); $len = (int)$element->GetAttributeByName('_maxlength'); if($len>0 && strlen($ret)>$len) { $ret = substr($ret,0,$len); $wordchop = $element->GetAttributeByName('_wordchop'); if(strlen($wordchop)==0 || $wordchop = "1") { if(substr($wordchop,-1)!=" ") { $pos = strrpos($ret," "); $ret = substr($ret,0,$pos); } } $ret .= " .."; } $ret = $this->HighlightText($ret); break; case "createdby": /* @field:link.createdby @description:parse a user field of the user that created the link @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:link.date @description:Returns the date/time the link 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:link.modified @description:Returns the date/time the link 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 "expire": /* @field:link.expire @description:Returns the date/time the link suppose to expire. @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 @attrib:_dataexists:bool: Used with opeing/closing tags to exclude the whole block when expiration date is not set. @attrib:_noexpirelabel:lang:Returns language tag when link is immortal (expire set to 0). */ $d = $this->Get("Expire"); if($d == 0) { if($element->attributes['_datenotset'] == 1) { $ret = 1; break; } if(strlen($element->attributes['_noexpirelabel'])) $ret = language($element->attributes['_noexpirelabel']); else $ret = ""; } elseif ($d > 0) { $ret = $this->ParseTimeStamp($d, $element->attributes); } else $ret = ""; break; case "delete_link": /* @field:link.delete_link @description:Returns a URL to delete the link @attrib:_template:tpl:Template URL should point to */ $catid = $this->GetPrimaryCategory(); if($objSession->HasCatPermission("LINK.DELETE",$catid) || ($objSession->Get("PortalUserId")==$this->Get("CreatedById") && $objSession->HasCatPermission("LINK.OWNER.DELETE",$catid))) { $t = $element->attributes["_template"]; if(!strlen($t)) $t = $var_list["t"]; $ret = $this->ItemURL($t); } break; case "edit_link": /* @field:link.edit_link @description:Returns a URL to edit the link @attrib:_template:tpl:Template URL should point to */ $catid = $this->GetPrimaryCategory(); if(($objSession->HasCatPermission("LINK.MODIFY",$catid) || $objSession->HasCatPermission("LINK.MODIFY.PENDING",$catid)) || (($objSession->Get("PortalUserId")==$this->Get("CreatedById") && $objSession->HasCatPermission("LINK.OWNER.MODIFY",$catid)) || ($objSession->Get("PortalUserId")==$this->Get("CreatedById") && $objSession->HasCatPermission("LINK.OWNER.MODIFY.PENDING",$catid)))) { $t = $element->attributes["_template"]; if(!strlen($t)) $t = $var_list["t"]; $ret = $this->ItemURL($t); } break; case 'is_enhanced': if (!class_exists('kApplication') || $this->isPending() ) { return ''; } $application =& kApplication::Instance(); $l_tag_processor =& $application->recallObject('l_TagProcessor'); $application->SetVar('l_id', $this->Get('LinkId')); $res = $l_tag_processor->LinkIsEnhanced( Array() ); $ret = getArrayValue($element->attributes, '_not') ? !$res : $res; return $ret ? 1 : ''; break; case "redirect": /* @field:link.redirect @description:Returns a URL to redirect the browser to the link's URL */ $ret = $rootURL."in-link/inlink_redirect.php?env=". BuildEnv()."&linkid=".$this->Get("LinkId"); break; case "add_favorite_link": /* @field:link.add_favorite_link @description:Returns a URL to add this link to the user's favorites @attrib:_template:tpl:Template URL should point to */ $t = $element->attributes["_template"]; if(!strlen($t)) $t = $var_list["t"]; $ret = $this->ItemURL($t,FALSE,"l_add_favorite"); break; case "del_favorite_link": /* @field:link.del_favorite_link @description:Returns a URL to remove this link from the user's favorites @attrib:_template:tpl:Template URL should point to */ $t = $element->attributes["_template"]; if(!strlen($t)) $t = $var_list["t"]; $ret = $this->ItemURL($t,FALSE,"l_del_favorite"); break; /* @field:link.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 link is already a favorite @attrib: _delimage::Image url to include in link if removing the favorite */ case "favorite_toggle": $catid = $this->GetPrimaryCategory(); $unregister=false; if($objSession->HasCatPermission("FAVORITES", $catid)) { $t = $element->GetAttributeByName('_template'); } else { $t = $element->GetAttributeByName('_denytemplate'); RegisterEnv("dest", $element->GetAttributeByName('_denytemplate')); $unregister = true; } // echo "RES: ".$unregister; if(!strlen($t)) $t = $var_list["t"]; if(!$this->IsFavorite($objSession->Get("PortalUserId"), $this->GetPrimaryCategory())) { $action = "l_add_favorite"; if( $element->GetAttributeByName('_addlabel') ) { $label = language($element->attributes["_addlabel"]); } else { if(strlen($element->attributes["_addimage"])) { $result = MakeHTMLTag($element,'_img'); $label = ''; } } } else { $action = "l_del_favorite"; if(strlen($element->attributes["_dellabel"])) { $label = language($element->attributes["_dellabel"]); } else { if(strlen($element->attributes["_delimage"])) { $result = MakeHTMLTag($element,'_img'); $label = ''; } } } $action = $unregister? NULL : $action; $ret = "ItemURL($t,FALSE,$action)."\">$label"; if ($unregister) UnregisterEnv("dest"); break; /* @field:link.hits @description:Returns number of hits for item */ case "hits": $ret= round($this->Get("Hits")); break; /* @field:link.votes @description:Returns number of votes for item rating */ /* @field:link.cat_link @description:Returns a URL setting the link to the current link and the link's category to the current category @attrib:_template:tpl:Template URL should point to */ /* @field:link.link @description:Returns a URL setting the link to the current link @attrib:_template:tpl:Template URL should point to */ /* @field:link.rating @description:Displays the links rating @attrib:_displaymode:: How the rating should be displayed
@attrib:_onimage::on image tick shown in graphical display mode @attrib:_offimage::off image tick shown in graphical display mode @attrib:_separator::In graphical display mode, this html is placed between each tick image */ /* @field:link.reviews @description:Return the number of reviews for think link @attrib:_today:bool:Count reviews added today only */ /* @field:link.new @description:returns text if link's status is "new" @attrib:_label:lang: Text to return if status is new */ /* @field:link.pop @description:returns text if link's status is "popular" @attrib:_label:lang: Text to return if status is popular */ /* @field:link.hot @description:returns text if link's status is "hot" @attrib:_label:lang: Text to return if status is "hot" */ /* @field:link.pick @description:returns text if link's status is "hot" @attrib:_label:lang: Text to return if status is "hot" */ /* @field:link.custom @description:Returns a custom field @attrib:_customfield::field name to return @attrib:_default::default value @attrib:_listvalue::default value */ /* @field:link.category @description:Return a category field from the link's category @attrib:_cattag::Category field to parse */ /* @field:link.fullpath @description:The full category path of the item */ /* @field:link.relevance @description:Displays the link relevance in search results @attrib:_displaymode:: How the relevance should be displayed
@attrib:_onimage::Zero relevance image shown in graphical display mode. Also used as prefix to build other images (i.e. prefix+"_"+percentage+".file_extension" @attrib:_OffBackGroundColor::Off background color of HTML cell in bar display mode @attrib:_OnBackGroundColor::On background color of HTML cell in bar display mode */ break; default: unset($ret); break; } if(!isset($ret) || !strlen($ret) ) { $ret = parent::ParseObject($element); } } else $ret= "Undefined"; return $ret; } function parsetag($tag) { global $objConfig,$mytempdata, $rootURL, $var_list, $var_list_update, $l_var_list_update; $ret=""; //echo "test"; switch($tag) { case "link_": case "link_name": $ret= $this->Get("Name"); break; case "link_desc": $ret= $this->Get("Description"); break; case "link_url": $ret = $this->Get("Url"); break; case "link_link": $ret = $rootURL."in-link/inlink_redirect.php?env=". BuildEnv()."&linkid=".$this->Get("LinkId"); break; case "link_id": $ret= $this->Get("LinkId"); break; case "link_date": if($this->Get("CreatedOn")<=0) return ""; $ret = LangDate($this->Get('CreatedOn'), 0, true); break; case "link_expire": if($this->Get("Expire")<=0) return ''; $ret = LangDate($this->Get('Expire'), 0, true); break; case "link_hits": $ret=$this->Get("Hits"); break; case "link_hot": if($this->IsHotItem()) { $ret="hot"; } else $ret = ""; break; case "link_new": if($this->IsNewItem()) { $ret="New"; } else $ret = ""; break; case "link_pop": if($this->IsPopItem()) { $ret = "pop"; } else $ret = ""; break; case "link_pick": if ($this->Get("EditorsPick")) $ret="pick"; break; case "link_priority": if($this->Get("Priority")!=0) { $ret = (int)$this->Get("Priority"); } else $ret = ""; break; case "link_add_fav": $var_list_update["t"] = "inlink/add_fav"; $ret = HREF_Wrapper( Array('id' => $this->Get('LinkId') ) ); unset($var_list_update["t"]); break; case "link_suggest_friend": $var_list_update["t"] = "inlink/link_suggest"; $ret= HREF_Wrapper( Array('id' => $this->Get('LinkId') ) ); unset($var_list_update["t"]); break; case "link_edit_link": $l_var_list_update["id"]=$this->Get("LinkId"); $var_list_update["t"] = "inlink/modify_link"; $ret= HREF_Wrapper(); unset($l_var_list_update["id"]); unset($var_list_update["t"]); break; case "link_rating_img": $ret= "inlink/rating/".RatingImage($this->Get("CachedRating")).".gif"; break; case "link_votes": $ret=$this->Get("CachedVotesQty"); break; case "link_reviews": $ret= $this->Get("CachedReviewsQty"); break; case "link_rating": $ret = round($this->Get("CachedRating"),1); break; case "link_resourceid": $ret= $this->Get("ResourceId"); break; case "link_num_reviews": $ret = $this->ReviewCount(); break; case "link_rating_txt": return RatingText($this->Get("CachedRating")); break; default: $ret= "Undefined:$tag"; break; } return $ret; } function isPending() { return $this->Get('Status') == -2 || $this->Get('Status') == 2; } } /*clsLink*/ class _clsLinkList extends clsCatItemList { function _clsLinkList() { global $l_var_list,$objSession; $this->clsCatItemList(); // $this->clsItemCollection(); //call the parent constructor $this->classname = "clsLink"; //class type for items $this->SourceTable = GetTablePrefix()."Link"; $this->PageEnvarIndex = 'p'; $this->PerPageVar = "Perpage_Links"; $this->PageEnvar = "l_var_list_update"; $this->Page = (int)$l_var_list["p"]; $this->AdminSearchFields = array("Name","Description","Url"); $this->BasePermission = "LINK"; $this->PerPageVarLong = "Perpage_Links"; $this->PerPageShortVar = "Perpage_Links_Short"; $this->AddSortField("Link_SortField","Link_SortOrder"); $this->AddSortField("Link_SortField2","Link_SortOrder2"); $this->ItemType = TYPE_LINK; if( $objSession->HasSystemPermission("DEBUG.ITEM") ) $this->debuglevel = 1; } function SqlMyItems($attribs= array()) { global $objSession; // pending modified links $sql = 'SELECT OrgId, LinkId FROM '.$this->SourceTable.' WHERE (CreatedById = '.$objSession->Get('PortalUserId').') AND (OrgId > 0)'; $pending_modified = Array(); $original_links = Array(); $db =& GetADODBConnection(); $rs = $db->Execute($sql); while (!$rs->EOF) { $pending_modified[] = $rs->fields['LinkId']; $original_links[] = $rs->fields['OrgId']; $rs->MoveNext(); } $TableName = $this->SourceTable; if ($pending_modified && $original_links) { $where = " (".$TableName.".Status > -1 OR LinkId IN (".implode(',', $pending_modified).") ) AND (LinkId NOT IN (".implode(',', $original_links).")) AND ".$TableName.".CreatedById=".$objSession->Get("PortalUserId"); } else { $where = " (".$TableName.".Status > -1) AND ".$TableName.".CreatedById=".$objSession->Get("PortalUserId"); } if(getArrayValue($attribs,'_today')) { $today = mktime(0,0,0,date("m"),date("d"),date("Y")); $where .= " AND ($TableName.CreatedOn>=$today)"; } $CategoryTable = GetTablePrefix()."Category"; $sql = "SELECT $TableName.*,$CategoryTable.CategoryId,$CategoryTable.CachedNavBar FROM $TableName "; $p = $this->BasePermission.".VIEW"; $sql .= $this->GetJoinedSQL($p,null,$where); // maybe null should be replaced by some CategoryId $OrderBy = $this->QueryOrderByClause(TRUE,TRUE,TRUE); $sql .= " ".$OrderBy; return $sql; } function &SetCurrentItem() { global $l_var_list; $this->CurrentItem = $l_var_list["id"]; } function LoadLinks($where="",$orderClause=NULL,$JoinCats=TRUE,$SkipCount=FALSE) { global $objConfig; $this->Clear(); if(!$SkipCount) $this->QueryItemCount=TableCount($this->SourceTable,$where,$JoinCats); return $this->Query_Link($where,$orderClause,$JoinCats); } function CountPending() { return TableCount($this->SourceTable,"Status=".STATUS_PENDING,0); } function Query_Link($whereClause,$orderByClause=NULL,$JoinCats=TRUE) { global $objSession, $Errors; if($JoinCats) { $cattable = GetTablePrefix()."CategoryItems"; $t = $this->SourceTable; $CategoryTable = GetTablePrefix()."Category"; $sql = "SELECT ".$this->SourceTable.".*,$CategoryTable.CategoryId as CategoryId,CachedNavBar FROM $t INNER JOIN $cattable ON $cattable.ItemResourceId=$t.ResourceId "; $sql .= "INNER JOIN $CategoryTable ON ($CategoryTable.CategoryId=$cattable.CategoryId)"; } else $sql = "SELECT * FROM ". $this->SourceTable; if(trim($whereClause)!="") { if(isset($whereClause)) $sql = sprintf('%s WHERE %s',$sql,$whereClause); } if (trim($orderByClause)!="") { if(isset($orderByClause)) $sql = sprintf('%s ORDER BY %s',$sql,$orderByClause); } if($objSession->HasSystemPermission("DEBUG.LIST")) echo $sql."
\n"; return $this->Query_Item($sql,null); } function SaveNewPage() { global $l_var_list; $l_var_list["p"] = $this->Page; } function ExpireItems() { $now = adodb_date("U"); $sql = "UPDATE ".$this->SourceTable." SET Status=0 WHERE Expire<$now AND Expire != 0 AND Status=1"; $this->adodbConnection->Execute($sql); DeleteModuleTagCache('inlink'); } function Delete_Item($Id, $DetectCategories = false) { $l = $this->GetItem($Id); $link_id = $l->Get('LinkId'); $sql = "DELETE FROM ".GetTablePrefix()."LinkValidation WHERE LinkId = $link_id"; $this->adodbConnection->Execute($sql); DeleteModuleTagCache('inlink'); return parent::Delete_Item($Id, $DetectCategories); } function &Add_Link($CategoryId, $Name, $Description, $Url, $CreatedOn, $Expire, $Status, $EditorsPick, $NewItem, $PopItem, $HotItem, $CreatedById, $Rating=0, $Votes=0, $Hits=0, $Priority=0, $auto_filename = 1, $filename = '') { global $objSession, $objConfig; $l = new clsLink(NULL); $filename = $l->StripDisallowed($filename); $l->BasePermission=$this->BasePermission; $l->tablename = $this->SourceTable; $l->Set(Array( 'Name', 'Description', 'Url', 'CreatedOn', 'Expire', 'Status', 'EditorsPick', 'NewItem', 'PopItem', 'HotItem', 'CreatedById', 'CachedRating', 'CachedVotesQty', 'Hits', 'Priority', 'AutomaticFilename', 'Filename'), Array( $Name, $Description, $Url, $CreatedOn, $Expire, $Status, $EditorsPick, $NewItem, $PopItem, $HotItem, $CreatedById, $Rating, $Votes, $Hits, $Priority, $auto_filename, $filename) ); $l->Create($Pending); $ci_table = $objSession->GetEditTable( GetTablePrefix().'CategoryItems' ); if ($l->TableExists($ci_table)) $l->AddToCategory($CategoryId, $ci_table, 1); $l->SendUserEventMail("LINK.ADD", $CreatedById); $l->SendAdminEventMail("LINK.ADD"); return $l; } function &Edit_Link($LinkId, $Name, $Description, $Url, $CreatedOn, $Expire, $Status, $EditorsPick, $NewItem, $PopItem, $HotItem, $Rating, $Votes, $Hits, $Priority=0, $auto_filename = 1, $filename = '') { $l = $this->GetItem($LinkId); $filename = $l->StripDisallowed($filename); $l->BasePermission = $this->BasePermission; if ( !$CreatedOn ) $CreatedOn = $l->Get('CreatedOn'); if ( !is_numeric($Status) ) $Status = $l->Get('Status'); if( !is_numeric($EditorsPick) ) $EditorsPick = $l->Get('EditorsPick'); $l->Set(Array( 'Name', 'Description', 'Url', 'CreatedOn', 'Expire', 'Status', 'EditorsPick', 'NewItem', 'PopItem', 'HotItem', 'CachedRating', 'CachedVotesQty', 'Hits', 'Priority', 'AutomaticFilename', 'Filename'), Array( $Name, $Description, $Url, $CreatedOn, $Expire, $Status, $EditorsPick, $NewItem, $PopItem, $HotItem, $Rating, $Votes, $Hits, $Priority, $auto_filename, $filename) ); $l->Update(); $l->SendUserEventMail("LINK.MODIFY", $l->Get("ModifiedById")); $l->SendAdminEventMail("LINK.MODIFY"); return $l; } function LoadListCategory($attribs=array()) { global $objCatList, $objSession, $objConfig, $content_set; $this->Clear(); $catid = (int)getArrayValue($attribs,'_catid'); if(!$catid) $catid = $objCatList->CurrentCategoryID(); if(!$catid && (int)$attribs["_useroot"]) $catid = (int)$objConfig->Get("Link_Root"); if(!$objSession->HasCatPermission("LINK.VIEW", $catid)) { $content_set = 0; $this->QueryItemCount = 0; return 0; } if($attribs["_shortlist"]) { if ($objConfig->Get("Perpage_Links_Short") > 0) { $this->PerPageVar = "Perpage_Links_Short"; } else { $this->PerPageVar = "Perpage_Links"; } } $CatTable = GetTablePrefix()."CategoryItems"; $t = $this->SourceTable; $sql = "SELECT *,CategoryId FROM $t INNER JOIN $CatTable ON $CatTable.ItemResourceId=$t.ResourceId "; $where = "CategoryId=".$catid." AND Status=1"; $sql .= "WHERE $where"; $OrderBy = $this->QueryOrderByClause($objConfig->Get("Link_ShowPick"), TRUE, TRUE); $sql .= " ".$OrderBy; $this->QueryItemCount = TableCount($this->SourceTable,$where,TRUE); if($this->QueryItemCount>0) { return $this->Query_Item($sql); } else return FALSE; } function GetNewValue($CatId=NULL) { global $NewValues,$objConfig, $objSystemCache; if(is_numeric($NewValues["link"])) { return $NewValues["link"]; } else { $CachedValue = $objSystemCache->GetValue("LinkNewValue","inlink",""); if(strlen($CachedValue)) { $NewValues["link"] = $CachedValue; return $CachedValue; } $ado = &GetADODBConnection(); if ($CategoryId) { $days = (int)$objConfig->Get("Link_NewDays"); $cutoffdate = adodb_mktime(0,0,0,adodb_date("m"),adodb_date("d")-$days,adodb_date("Y")); $sql = "SELECT CreatedOn FROM ".GetTablePrefix()."Link INNER JOIN ".GetTablePrefix()."CategoryItems AS cat ON (".GetTablePrefix()."Link.ResourceId = cat.ItemResourceId) WHERE cat.CategoryId=$CategoryId AND CreatedOn>=$cutoffdate ORDER BY CreatedOn DESC "; } else { $days = (int)$objConfig->Get("Link_NewDays"); $cutoffdate = adodb_mktime(0,0,0,adodb_date("m"),adodb_date("d")-$days,adodb_date("Y")); $sql = "SELECT CreatedOn FROM ".GetTablePrefix()."Link WHERE CreatedOn>=$cutoffdate ORDER BY CreatedOn DESC "; } $rs = $ado->Execute($sql); $NewValues["link"] = adodb_mktime(0,0,0,adodb_date("m"),adodb_date("d")-$days,adodb_date("Y")); while($rs && !$rs->EOF) { $NewValues["link"] = $rs->fields["CreatedOn"]; $rs->MoveNext(); } return $NewValues["link"]; } } function GetHotValue() { global $objConfig; $ado = &GetADODBConnection(); $sql = "SELECT Hits FROM ".GetTablePrefix()."Link ORDER BY Hits DESC LIMIT 0,".$objConfig->Get("Link_VotesToHot"); $rs = $ado->Execute($sql); $hot_val = 0; while ($rs && !$rs->EOF) { if ($rs->fields['Hits'] > 0) { $hot_val = $rs->fields['Hits']; } $rs->MoveNext(); } return $hot_val; } function GetPopValue() { global $PopValues,$objConfig, $objSystemCache; if(is_numeric($PopValues["link"]) && $PopValues["link"] > 0) { return $PopValues["link"]; } else { $CachedValue = $objSystemCache->GetValue('LinkPopValue','inlink',''); if(strlen($CachedValue) && $CachedValue > 0) { $PopValues['link'] = $CachedValue; return $CachedValue; } else { $PopValues['link'] = $objConfig->Get('Link_TopCount'); } /*$ado = &GetADODBConnection(); $sql = "SELECT CachedRating FROM ".GetTablePrefix()."Link WHERE CachedRating >= ".(int)$objConfig->Get("Link_TopCount")." ORDER BY Hits DESC"; $rs = $ado->Execute($sql); $PopValues["link"] = 0; while($rs && !$rs->EOF) { //echo $rs->fields["CachedRating"]."
"; $PopValues["link"] = $rs->fields["CachedRating"]; // this works fine? next value overwrites previous $rs->MoveNext(); }*/ $objSystemCache->EditCacheItem('LinkPopValue',$PopValues['link'],'inlink',adodb_mktime()+3600,''); //echo "PopValues: ".$PopValues["link"]."
"; return $PopValues['link']; } } } /*clsLinkList*/ ?>