/* * This file is a part of Winix * and is not publicly distributed * * Copyright (c) 2008-2009, Tomasz Sowa * All rights reserved. * */ #include "content.h" #include "../core/request.h" #include "../core/misc.h" #include "../core/db.h" // returning true if the 'url' has to be changed bool Content::ReadItemUrlSubject(Item & item, Item::Type item_type) { bool with_url = false; std::string * new_url = request.PostVar("url"); std::string * new_subject = request.PostVar("subject"); if( item_type == Item::file ) { if( !request.is_item || (new_url && *new_url != item.url) ) with_url = true; } else { with_url = true; } if( new_url ) item.url = *new_url; if( new_subject ) item.subject = *new_subject; if( item.subject.empty() ) { item.subject = request.dir_table.back()->subject; item.subject += "_msg_"; item.subject += ToStr(db.Size(request.dir_table.back()->id, Item::file)); } // if item.url is empty then it will be set from item.subject PrepareUrl(item); return with_url; } void Content::ReadItemContentWithType(Item & item) { item.content_type = Item::ct_formatted_text; // default is formatted text request.PostVar("itemcontent", request.item.content); request.PostVar("contenttype", temp); // ct_text and ct_formatted_text can use everyone if( temp == "0" ) item.content_type = Item::ct_text; else if( temp == "1" ) item.content_type = Item::ct_formatted_text; // those below need special privileges if( !request.session->puser ) return; long user_id = request.session->puser->id; if( temp == "2" ) { if( request.CanUseHtml(user_id) ) item.content_type = Item::ct_html; } else if( temp == "3" ) { if( request.CanUseBBCode(user_id) ) item.content_type = Item::ct_bbcode; } else if( temp == "4" ) { if( request.CanUseRaw(user_id) ) item.content_type = Item::ct_raw; } } // item_type - the type of an item you are expecting to read // returns true if the url has to be changed // at the moment this is only checked for Item::file - for Item::dir it returns always true bool Content::ReadItem(Item & item, Item::Type item_type) { if( item_type == Item::none ) return false; item.type = item_type; item.parent_id = request.dir_table.back()->id; bool edit_with_url = ReadItemUrlSubject(item, item_type); SetUser(item); if( item_type == Item::file ) ReadItemContentWithType(item); return edit_with_url; } // if we don't have access we only remove the item from the table void Content::CheckAccessToItems() { size_t i = 0; while( i < request.item_table.size() ) { if( !request.HasReadAccess(request.item_table[i]) ) { request.item_table.erase(request.item_table.begin() + i); } else { i += 1; } } }