/* * This file is a part of Winix * and is not publicly distributed * * Copyright (c) 2011-2014, Tomasz Sowa * All rights reserved. * */ #include "meta.h" #include "core/log.h" namespace Winix { namespace Fun { Meta::Meta() { fun.url = L"meta"; // !! CHECKME what about follow symlinks? } bool Meta::HasAccess() { if( cur->request->IsParam(L"a") ) return cur->session->puser && cur->session->puser->super_user; else return system->HasWriteAccess(*cur->request->last_item); } bool Meta::Parse(const std::wstring & meta_str) { space.Clear(); conf_parser.SetSpace(space); conf_parser.UTF8(config->utf8); conf_parser.SplitSingle(true); return (conf_parser.ParseString(meta_str) == PT::SpaceParser::ok); } bool Meta::EditAdminMeta(long item_id, const std::wstring & meta_str, bool use_ses_log) { if( Parse(meta_str) ) { if( db->EditAdminMetaById(space, item_id) == WINIX_ERR_OK ) { return true; } else { log << log1 << "Meta: a database problem with changing admin meta information for item id: " << item_id << logend; } } else { log << log2 << "Meta: Syntax error in line: " << conf_parser.line << logend; if( use_ses_log ) slog << logerror << T("syntax_error_in_line") << ' ' << conf_parser.line << logend; } return false; } bool Meta::EditMeta(long item_id, const std::wstring & meta_str, bool use_ses_log) { if( Parse(meta_str) ) { if( db->EditMetaById(space, item_id) == WINIX_ERR_OK ) { return true; } else { log << log1 << "Meta: a database problem with changing meta information for item id: " << item_id << logend; } } else { log << log2 << "Meta: Syntax error in line: " << conf_parser.line << logend; if( use_ses_log ) slog << logerror << T("syntax_error_in_line") << ' ' << conf_parser.line << logend; } return false; } void Meta::ChangeAdminMeta() { if( cur->session->puser && cur->session->puser->super_user ) { const std::wstring & meta_str = cur->request->PostVar(L"itemmeta"); if( EditAdminMeta(cur->request->last_item->id, meta_str, true) ) system->RedirectToLastItem(); } } void Meta::ChangeMeta() { if( system->HasWriteAccess(*cur->request->last_item) ) { const std::wstring & meta_str = cur->request->PostVar(L"itemmeta"); if( EditMeta(cur->request->last_item->id, meta_str, true) ) system->RedirectToLastItem(); } } void Meta::MakePost() { if( cur->request->IsParam(L"a") ) ChangeAdminMeta(); else ChangeMeta(); } } // namespace } // namespace Winix