/* * This file is a part of Winix * and is not publicly distributed * * Copyright (c) 2013, Tomasz Sowa * All rights reserved. * */ #include "imgcrop.h" #include "functions.h" namespace Fun { ImgCrop::ImgCrop() { fun.url = L"imgcrop"; } bool ImgCrop::HasAccess() { if( cur->request->is_item ) return system->HasWriteAccess(cur->request->item); return true; } void ImgCrop::GetDirContent() { iq.sel_content = false; iq.WhereParentId(cur->request->dir_tab.back()->id); db->GetItems(cur->request->item_tab, iq); system->CheckWriteAccessToItems(cur->request->item_tab); } void ImgCrop::MakePost() { int xoffset = int(Tod(cur->request->PostVar(L"cropxtop")) + 0.5); int yoffset = int(Tod(cur->request->PostVar(L"cropytop")) + 0.5); int width = int(Tod(cur->request->PostVar(L"cropwidth")) + 0.5); int height = int(Tod(cur->request->PostVar(L"cropheight")) + 0.5); SetMinMax(xoffset, 0, 30000); SetMinMax(yoffset, 0, 30000); SetMinMax(width, 1, 30000); SetMinMax(height, 1, 30000); Item & item = cur->request->item; if( cur->request->is_item && item.type == Item::file && item.file_type == WINIX_ITEM_FILETYPE_IMAGE ) { if( system->HasWriteAccess(item) ) { // !! IMPROVE ME add info about modification (Item::modify_time) if( cur->request->IsParam(L"thumb") ) { Image::Scale scale = system->image.GetThumbScale(item.parent_id); system->image.CropThumb(item.id, xoffset, yoffset, width, height, scale.quality); } else if( cur->request->IsParam(L"newthumb") ) { Image::Scale scale = system->image.GetThumbScale(item.parent_id); system->image.CropNewThumb(item.id, xoffset, yoffset, width, height, scale.cx, scale.cy, scale.aspect_mode, scale.quality); } else { Image::Scale scale = system->image.GetImageScale(item.parent_id); system->image.Crop(item.id, xoffset, yoffset, width, height, scale.quality); } // !! IMPROVE ME redirect me somewhere else system->RedirectToLastItem(); } else { cur->request->status = WINIX_ERR_PERMISSION_DENIED; } } } void ImgCrop::MakeGet() { if( !cur->request->is_item ) GetDirContent(); } } // namespace