Get("PortalUserId");
$Topic =& $objTopicList->GetItem($id);
$Topic->AddFavorite($userid);
$cat_id = $Topic->GetPrimaryCategory();
UpdateCategoryCount("Topic", $cat_id, $objTopicList->CacheListType("favorites"));
break;
case "bb_del_favorite":
$id = $bb_var_list["top"];
$userid = $objSession->Get("PortalUserId");
$Topic =& $objTopicList->GetItem($id);
$Topic->DeleteFavorite($userid);
$cat_id = $Topic->GetPrimaryCategory();
UpdateCategoryCount("Topic", $cat_id, $objTopicList->CacheListType("favorites"));
break;
case "bb_lock_topic":
$id = $bb_var_list["top"];
$Topic =& $objTopicList->GetItem($id);
$Topic->Set("TopicType",0);
$Topic->Update();
break;
case "bb_unlock_topic":
$id = $bb_var_list["top"];
$Topic =& $objTopicList->GetItem($id);
$Topic->Set("TopicType",1);
$Topic->Update();
break;
case "bb_new_topic":
//phpinfo(INFO_VARIABLES);
$AddPerm = $objSession->HasCatPermission("TOPIC.ADD");
$PendingPerm = $objSession->HasCatPermission("TOPIC.ADD.PENDING");
//echo "Add: $AddPerm
\n";
if($AddPerm || $PendingPerm)
{
//echo "Adding Topic..
\n";
$cat =& $objCatList->GetCategory($objCatList->CurrentCategoryID());
if(trim($_POST["topic_subject"])!="")
{
$Status = ($AddPerm!=0) ? 1 : 2;
$Pick = (int)$_POST["topic_pick"];
$Notify = (int)$_POST["owner_notify"];
$CreatedOn = adodb_date("U");
$t =& $objTopicList->Add_Topic(inp_striptags($_POST["topic_subject"]),
$objCatList->CurrentCategoryID(), $Status, $Pick, $Notify, $CreatedOn);
/* @var $t clsTopic */
$TopicId = $t->Get("TopicId");
saveCustomFields('bb', $t->Get('ResourceId'), 3);
if(is_object($t))
{
$u =& $objSession->CurrentUser;
$PAlias= $t->Get("PostedBy");
//$body = inp_escape($_POST["bb_post_reply_body"],0);
$body = str_replace('
','',$_POST['bb_post_reply_body']);
$body = htmlspecialchars($body);
$p =& $t->AddPost($PAlias,$Status, $body);
/* @var $p clsPosting */
$p->SetPostOption("show_sig",(int)$_POST["topic_sig"]);
$p->SetPostOption("disable_smileys",(int)$_POST["topic_smile"]);
$p->SetPostOption("disable_bbcode",(int)$_POST["topic_bbcode"]);
$p->Set("ReplyTo",0);
$p->Update();
$bb_var_list_update["top"]=$t->Get("TopicId");
$env=BuildEnv();
unset($bb_var_list_update["top"]);
UpdateCategoryCount("Topic",$t->GetPrimaryCategory(),'_');
UpdateCategoryCount("Topic",$t->GetPrimaryCategory(),$objTopicList->CacheListType("myitems"));
}
if(strlen($_GET["Confirm"]))
{
$var_list["t"] = $_GET["Confirm"];
}
else
$var_list["t"] = $_GET["DestTemplate"];
$cat->SetLastUpdate( adodb_mktime() );
$objTopicList->ResetCache( $objCatList->CurrentCategoryID() );
$objPostingList->ResetCache( $objCatList->CurrentCategoryID() );
$t->SetTodayPosts(+1);
}
}
break;
case "bb_edit_topic":
$perm = 0;
$CategoryId=$objCatList->CurrentCategoryID();
$OrgTopic = $objTopicList->GetCurrentTopic();
$PermCat = $OrgTopic->GetPrimaryCategory();
if ($objSession->HasCatPermission("TOPIC.MODIFY.PENDING",$PermCat))
$perm = 2;
if ($objSession->HasCatPermission("TOPIC.MODIFY",$PermCat))
$perm = 1;
if($objSession->Get("PortalUserId")==$OrgTopic->Get("OwnerId") && $perm != 1)
{
if ($objSession->HasCatPermission("TOPIC.OWNER.MODIFY.PENDING",$PermCat))
$perm = 2;
if ($objSession->HasCatPermission("TOPIC.OWNER.MODIFY",$PermCat))
$perm = 1;
}
$topic = $OrgTopic;
if($perm==2)
{
$topic->CreatePendingCopy();
}
if ($perm == 0)
{
$MissingCount++;
$FormError["editlink"]["topic_subject"] = language("lu_ferror_no_access");
}
else
{
$subject = inp_striptags($_POST["topic_subject"]);
$Notify = (int)$_POST["owner_notify"];
$MissingCount = SetMissingDataErrors("edit_topic");
if(is_array($_FILES))
{
foreach($_FILES as $field => $file)
{
$allowed = TRUE;
if(strlen($_POST["imagetypes"][$field]))
{
$types = explode(",",strtolower($_POST["imagetypes"][$field]));
if(is_array($types))
{
if(count($types)>0)
{
$path_parts = pathinfo($file["name"]);
$ext = $path_parts["extension"];
$allowed = in_array($ext,$types);
if(!$allowed)
{
$MissingCount++;
$FormError["edit_topic"][$field] = language("lu_ferror_wrongtype");
}
}
}
}
$maxsize = (int)$_POST["maxsize"][$field];
if($maxsize>0 && $allowed && $file["size"]>$maxsize)
{
$allowed = FALSE;
$MissingCount++;
$FormError["edit_topic"][$field] = language("lu_ferror_toolarge");
}
}
}
if($MissingCount==0)
{
$topic->Set("TopicText",$subject);
$topic->Set("NotifyOwnerOnChanges",$Notify);
$topic->Update();
if($perm==1)
{
$topic->SendUserEventMail("TOPIC.MODIFY",$topic->Get("ModifiedById"));
$topic->SendAdminEventMail("TOPIC.MODIFY");
}
else
{
$topic->SendUserEventMail("TOPIC.MODIFY.PENDING",$topic->Get("ModifiedById"));
$topic->SendAdminEventMail("TOPIC.MODIFY.PENDING");
}
saveCustomFields('bb', $topic->Get('ResourceId'), 3);
$ResourceId = $topic->Get("ResourceId");
if($perm==2)
$topic->AddToCategory($CategoryId);
/* handle any image uploads */
if(is_array($_FILES))
{
foreach($_FILES as $field => $file)
{
if($file["size"]>0)
{
$imgname = $_POST["imagename"][$field];
$thumb = $_POST["isthumb"][$field];
$IsDefault = (int)$_POST["imgdefault"][$field];
if($thumb)
{
$LocalThumb=1;
}
else
$LocalImage=1;
$img = $objImageList->GetImageByName($ResourceId,$imgname);
if(!is_object($img))
{
$img =& $objImageList->Add($imgname, "", $ResourceId,
$LocalImage, $LocalThumb,
"", "", 1, 0, $IsDefault, 0,0);
}
if($thumb)
{
$img->Set("LocalThumb",1);
$url = $img->StoreUploadedImage($file, 1,"kernel/images/",$thumb);
$img->Set("ThumbPath",$url);
}
else
{
$img->Set("LocalImage",1);
$url = $img->StoreUploadedImage($file, 1,"kernel/images/",$thumb);
$img->Set("LocalPath",$url);
}
$img->Update();
}
}
}
if(strlen($_GET["Confirm"]))
{
$var_list["t"] = $_GET["Confirm"];
}
else
$var_list["t"] = $_GET["DestTemplate"];
}
$thiscat = $objCatList->GetCategory( $objCatList->CurrentCategoryID() );
$thiscat->SetLastUpdate( adodb_mktime() );
}
break;
case "bb_topic_reply": /* add post to topic */
$thiscat =& $objCatList->GetCategory( $objCatList->CurrentCategoryID() );
$ReplyPerm = $objSession->HasCatPermission("TOPIC.REPLY.ADD");
if($ReplyPerm)
{
$t = $objTopicList->GetCurrentTopic();
$u =& $objSession->CurrentUser;
$body = str_replace('
','',$_POST['bb_post_reply_body']);
$body = htmlspecialchars($body);
if (is_object($u)) {
$PAlias = $u->Get("Login");
}
$post =& $t->AddPost($PAlias,0, $body, $_POST["subject"]);
$post->SetPostOption("show_sig",(int)$_POST["topic_sig"]);
$post->SetPostOption("disable_smileys",(int)$_POST["topic_smile"]);
$post->SetPostOption("disable_bbcode",(int)$_POST["topic_bbcode"]);
$post->Set("ReplyTo",(int)$_POST["replyto"]);
$post->Update();
$ado = &GetADODBConnection();
$sql = "SELECT count(*) AS count FROM ".GetTablePrefix()."Posting WHERE TopicId = ".$t->Data['TopicId'];
$rs = $ado->Execute($sql);
if ($rs->fields['count'] == $objConfig->Get("AutoTopicLockPosts") && ($objConfig->Get("AutoTopicLockPosts") > 0 || $objConfig->Get("AutoTopicLockPosts") != ''))
{
$objTopicList->LockTopic($t->Data['TopicId']);
}
$thiscat->SetLastUpdate( adodb_mktime() );
$objPostingList->ResetCache( $objCatList->CurrentCategoryID() );
$t->SetTodayPosts(+1);
$t->Set('Modified', adodb_mktime() ); // topic modification date IS affected by this action
$t->Update();
}
else
{
Permission_Error("You do not have access to post to this topic.");
}
break;
case "bb_post_edit":
$CatPerms= $objSession->HasCatPermission("TOPIC.REPLY.MODIFY");
$OwnerPerms = $objSession->HasCatPermission("TOPIC.REPLY.OWNER.MODIFY");
$p =& $objPostingList->GetCurrentPost();
if(is_object($p))
{
$pid = $p->Get("PostingId");
$UserId = $objSession->Get("PortalUserId");
$u =& $objSession->CurrentUser;
if (($UserId==$p->Get("CreatedById") && $OwnerPerms) || $CatPerms==1)
{
$body = str_replace("
","",$_POST["bb_post_reply_body"]);
$body = htmlspecialchars($body);
$body .= "\n\n[".language("lu_editedby")." ".$u->Get("Login")." ".language("lu_on")." ";
$body .= LangDate(adodb_mktime())." ".LangTime(adodb_mktime())."]";
$p->Set("PostingText",$body);
$p->SetPostOption("show_sig",(int)$_POST["topic_sig"]);
$p->SetPostOption("disable_smileys",(int)$_POST["topic_smile"]);
$p->SetPostOption("disable_bbcode",(int)$_POST["topic_bbcode"]);
$p->Set("Subject",$_POST["subject"]);
$p->Update();
$p->SendUserEventMail("POST.MODIFY",$p->Get("ModifiedById"));
$p->SendAdminEventMail("POST.MODIFY");
$t = $objTopicList->GetCurrentTopic();
$t->Set('Modified', adodb_mktime() ); // topic modification date IS affected by this action
$t->Update();
}
$objPostingList->Clear();
$thiscat = $objCatList->GetCategory( $objCatList->CurrentCategoryID() );
$thiscat->SetLastUpdate( adodb_mktime() );
}
else
{
$poster=$pid;
Permission_Error("You do not have permission to edit this post.");
}
break;
case "bb_post_delete":
$CatPerms= $objSession->HasCatPermission("TOPIC.REPLY.DELETE");
$p =& $objPostingList->GetCurrentPost();
if(is_object($p))
{
$pid = $p->Get("CreatedById");
$UserId = $objSession->Get("PortalUserId");
if ($UserId==$pid || $CatPerms==1)
{
$Topic = $objTopicList->GetItem($p->Get("TopicId"));
$PostCreated = $p->Get('CreatedOn');
$p->Delete();
$Topic->Decrement("Posts");
$Topic->Set('ModifiedById', $objSession->Get("PortalUserId"));
// get last post modification date and set it as topic modification date
$db =& GetADODBConnection();
$prefix = GetTablePrefix();
$sql = 'SELECT MAX(IF(Modified=0,CreatedOn,Modified)) FROM '.$prefix.'Posting WHERE TopicId = '.$Topic->UniqueId();
$last_update = $db->GetOne($sql);
$Topic->Set('LastPostId',$Topic->GetLastPostId());
$Topic->Set('LastPostDate', $last_update);
$Topic->Update(null,$last_update);
$Topic->refreshLastUpdate();
$thiscat = $objCatList->GetCategory( $objCatList->CurrentCategoryID() );
$thiscat->SetLastUpdate( adodb_mktime() );
$u = $objUsers->GetUser($UserId);
$posts = (int)$u->GetPersistantVariable("bb_posts");
$posts--;
if($posts<0)
$posts=0;
$u->SetPersistantVariable("bb_posts",$posts);
$objTopicList->ResetCache( $objCatList->CurrentCategoryID() );
$objPostingList->ResetCache( $objCatList->CurrentCategoryID() );
// affect only today created posts during deleting
if( adodb_date('Y-m-d',$PostCreated) == adodb_date('Y-m-d', adodb_mktime() ) )
{
$Topic->SetTodayPosts(-1);
}
}
}
$objPostingList->Clear();
break;
case "bb_topic_delete":
$thiscat =& $objCatList->GetItem($objCatList->CurrentCategoryID());
$perm = $objSession->HasCatPermission("TOPIC.DELETE");
$OwnerPerm = $objSession->HasCatPermission("TOPIC.OWNER.DELETE");
if(is_array($_POST["topiclist"]))
{
foreach($_POST["topiclist"] as $topicid)
{
$t =& $objTopicList->GetItem($topicid);
if (($objSession->Get("PortalUserId") == $t->Get("OwnerId") && $OwnerPerm) || ($perm==1))
{
$objTopicList->Delete_Item($topicid);
}
}
}
else
{
$t = $objTopicList->GetCurrentTopic();
if(is_object($t))
{
if (($objSession->Get("PortalUserId") == $t->Get("OwnerId") && $OwnerPerm) || ($perm==1))
{
$objTopicList->Delete_Item($t->Get("TopicId"));
unset($t);
}
}
}
UpdateCategoryCount('Topic', $objCatList->CurrentCategoryID(), $objTopicList->GetListTypes());
// UpdateCategoryCount('Posting', $objCatList->CurrentCategoryID(), $objPostingList->GetListTypes());
$objTopicList->Clear();
break;
case "bb_rate_topic":
//phpinfo(INFO_VARIABLES);
if ($objSession->HasCatPermission("TOPIC.RATE"))
$perm = 1;
if ($perm == 0)
{
$MissingCount++;
$FormError["bb_rate"]["review"] = language("lu_ferror_no_access");
}
else
{
$MissingCount = SetMissingDataErrors("bb_rate");
$topic =& $objTopicList->GetCurrentTopic();
$value = $objSession->InSpamControl($topic->Get("ResourceId"),"Rating");
if($value)
{
$MissingCount++;
$FormError["bb_rate"]["review"] = language("lu_rating_alreadyvoted");
if(strlen($_GET["Duplicate"]))
{
$var_list["t"] = $_GET["Duplicate"];
}
else
$var_list["t"] = $_GET["DestTemplate"];
}
if($MissingCount==0)
{
$ValName = "topic_RatingDelay_Value";
$IntName = "topic_RatingDelay_Interval";
$exp_secs = $objConfig->Get($ValName) * $objConfig->Get($IntName);
$objSession->AddToSpamControl($topic->Get("ResourceId"),$exp_secs,"Rating");
$vote = $_POST["rating"];
$topic->SubmitVote($vote,"");
if(strlen($_GET["Confirm"]))
{
$var_list["t"] = $_GET["Confirm"];
}
else
$var_list["t"] = $_GET["DestTemplate"];
}
}
break;
case "m_simple_search":
$type = $objItemTypes->GetTypeByName("Topic");
$keywords = trim($_POST["keywords"]);
$length = $objConfig->Get('Search_MinKeyword_Length');
$isExact = (substr($keywords, 0, 2) == '\"' && substr($keywords, strlen($keywords) - 2, 2) == '\"');
if ($isExact) {
$performSearch = (strlen(trim(str_replace('\"', '', $keywords))) >= $length);
}
else {
$key_arr = explode(' ', $keywords);
/*foreach($key_arr as $value) {
if (strlen($value) < $length) {
$keywords = str_replace(' '.$value, '', $keywords);
$keywords = str_replace($value.' ', '', $keywords);
}
}
$keywords = str_replace(' ', ' ', $keywords);*/
$performSearch = (strlen($keywords) >= $length);
}
if ($performSearch) {
$objTopicSearch = new clsSearchResults("Topic",$objTopicList->classname);
$objTopicSearch->SetKeywords($keywords);
$objTopicSearch->AddSimpleFields('bb');
if (is_numeric($objConfig->Get("SearchRel_Pop_topics"))) {
$objTopicSearch->PctPop = ($objConfig->Get("SearchRel_Pop_topics")/100);
}
if(is_numeric($objConfig->Get("SearchRel_Keyword_topics"))) {
$objTopicSearch->PctRelevance = ($objConfig->Get("SearchRel_Keyword_topics")/100);
}
if (is_numeric($objConfig->Get("SearchRel_Rating_topics"))) {
$objTopicSearch->PctRating = ($objConfig->Get("SearchRel_Rating_topics")/100);
}
$objTopicSearch->PerformSearch($type->Get("ItemType"),$SortOrder,FALSE);
//$objTopicSearch->SetRelevence($type->Get("ItemType"), "TopicId");
}
break;
case "m_adv_search":
switch($_GET["type"])
{
case 3: /* link */
$objAdvSearch = new clsAdvancedSearchResults("Topic",$objTopicList->classname, $_GET["type"]);
foreach($objSearchConfig->Items as $field)
{
$fld = $field->Get("FieldName");
$Verb = $_POST["verb"][$field->Get("FieldName")];
if(!strlen($Verb) && $field->Get("FieldType")=="boolean")
{
if($_POST["value"][$field->Get("FieldName")]!=-1)
{
$Value = $_POST["value"][$field->Get("FieldName")];
$Verb = "is";
}
}
else
{
$Value = $_POST["value"][$field->Get("FieldName")];
}
switch( $_POST["andor"][$field->Get("FieldName")])
{
case 1:
$Conjuction = "AND";
break;
case 2:
$Conjuction = "OR";
break;
default:
$Conjuction = "";
break;
}
if (strlen($Value) && $Verb=="any")
{
$Verb = 'contains';
}
if(strlen($Value) && strlen($Verb)>0 && $Verb!="any") {
$objAdvSearch->AddAdvancedField($field->Get("TableName"),$field->Get("FieldName"),$Verb,$Value,$Conjuction, 'bb');
}
}
$objAdvSearch->PerformSearch(3,NULL,TRUE);
}
break;
case "m_simple_subsearch":
$keywords = $_POST["keywords"];
$type = $objItemTypes->GetTypeByName("Topic");
if(strlen($keywords))
{
$objTopicSearch = new clsSearchResults("Topic",$objTopicList->classname);
$objTopicSearch->SetKeywords($keywords);
$objTopicSearch->AddSimpleFields('bb');
if (is_numeric($objConfig->Get("SearchRel_Pop_topics"))) {
$objTopicSearch->PctPop = ($objConfig->Get("SearchRel_Pop_topics")/100);
}
if (is_numeric($objConfig->Get("SearchRel_Keyword_topics"))) {
$objTopicSearch->PctRelevance = ($objConfig->Get("SearchRel_Keyword_topics")/100);
}
if (is_numeric($objConfig->Get("SearchRel_Rating_topics"))) {
$objTopicSearch->PctRating = ($objConfig->Get("SearchRel_Rating_topics")/100);
}
//$SearchResultIdList = $objLinkSearch->Result_IdList();
if(count($SearchResultIdList)>0)
{
$objTopicSearch->PerformSearch($type->Get("ItemType"),$SortOrder,FALSE,$SearchResultIdList);
//$objTopicSearch->SetRelevence($type->Get("ItemType"), "TopicId");
}
}
break;
case "bb_pref":
//phpinfo(INFO_VARIABLES);
$u = $objUsers->GetItem($objSession->Get("PortalUserId"));
$objSession->SetPersistantVariable("Perpage_Topics",trim($_POST["perpage_topics"]));
$objSession->SetPersistantVariable("Perpage_Postings",trim($_POST["perpage_posts"]));
$objSession->SetPersistantVariable("owner_notify",trim( GetVar('owner_notify') ));
$objSession->SetPersistantVariable("bb_pm_notify", $_POST["pm_notify"]); // notify me by email about new private messages
$objSession->SetPersistantVariable("bbcode",trim($_POST["bbcode"])); // allow bbcodes
$objSession->SetPersistantVariable("smileys",trim($_POST["smileys"])); // allow smilies
$objSession->SetPersistantVariable("show_sig", trim(GetVar('show_sig')) ); // show signature
$objSession->SetPersistantVariable("bb_signatures",trim($_POST["user_signatures"])); // show other signarures
$signature = trim(GetVar('my_signature'));
$signature = preg_replace('/(.*)