X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Froomtokens.c;h=eecc1623623fe881d7cf0d2aac826d84564452d6;hb=fb6f6fa4ec4e3277e30d84326d48e6850822d318;hp=0e632365f761757bdbb3fa91ff04b0fd8b8d73a6;hpb=36821734e42c9200de69079d314b71c5a6b5526e;p=citadel.git diff --git a/webcit/roomtokens.c b/webcit/roomtokens.c index 0e632365f..eecc16236 100644 --- a/webcit/roomtokens.c +++ b/webcit/roomtokens.c @@ -1,5 +1,15 @@ /* * Lots of different room-related operations. + * + * Copyright (c) 1996-2012 by the citadel.org team + * + * This program is open source software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. */ #include "webcit.h" @@ -11,14 +21,13 @@ * * got The information returned from a GOTO server command * navbar_style Determines which navigation buttons to display - * */ void tmplput_roombanner(StrBuf *Target, WCTemplputParams *TP) { wcsession *WCC = WC; - /* refresh current room states... */ - /* dosen't work??? gotoroom(NULL); */ + /* Refresh current room states. Doesn't work? gotoroom(NULL); */ + wc_printf("
\n"); /* The browser needs some information for its own use */ @@ -26,7 +35,7 @@ void tmplput_roombanner(StrBuf *Target, WCTemplputParams *TP) " room_is_trash = %d; \n" "\n", ((WC->CurRoom.RAFlags & UA_ISTRASH) != 0) - ); + ); /* * If the user happens to select the "make this my start page" link, @@ -36,35 +45,35 @@ void tmplput_roombanner(StrBuf *Target, WCTemplputParams *TP) if (WCC->Hdr->this_page == NULL) { WCC->Hdr->this_page = NewStrBuf(); } - StrBufPrintf(WCC->Hdr->this_page, - "dotskip?room=%s", - ChrPtr(WC->CurRoom.name) - ); + StrBufPrintf(WCC->Hdr->this_page, "dotskip?room=%s", ChrPtr(WC->CurRoom.name)); - do_template("roombanner", NULL); - /* roombanner contains this for mobile */ - if (WC->is_mobile) - return; + do_template("roombanner"); - do_template("navbar", NULL); + do_template("navbar"); wc_printf("
\n"); } /******************************************************************************* ********************** FLOOR Tokens ******************************************* - ******************************************************************************/ + *******************************************************************************/ + + void tmplput_FLOOR_ID(StrBuf *Target, WCTemplputParams *TP) { Floor *myFloor = (Floor *)CTX; StrBufAppendPrintf(Target, "%d", myFloor->ID); } + + void tmplput_ROOM_FLOORID(StrBuf *Target, WCTemplputParams *TP) { folder *Folder = (folder *)CTX; StrBufAppendPrintf(Target, "%d", Folder->floorid); } + + void tmplput_ROOM_FLOOR_ID(StrBuf *Target, WCTemplputParams *TP) { folder *Folder = (folder *)CTX; @@ -76,6 +85,7 @@ void tmplput_ROOM_FLOOR_ID(StrBuf *Target, WCTemplputParams *TP) StrBufAppendPrintf(Target, "%d", pFloor->ID); } + void tmplput_ROOM_FLOOR_NAME(StrBuf *Target, WCTemplputParams *TP) { folder *Folder = (folder *)CTX; @@ -86,6 +96,8 @@ void tmplput_ROOM_FLOOR_NAME(StrBuf *Target, WCTemplputParams *TP) StrBufAppendTemplate(Target, TP, pFloor->Name, 0); } + + void tmplput_ThisRoomFloorName(StrBuf *Target, WCTemplputParams *TP) { wcsession *WCC = WC; @@ -101,6 +113,8 @@ void tmplput_ThisRoomFloorName(StrBuf *Target, WCTemplputParams *TP) StrBufAppendTemplate(Target, TP, pFloor->Name, 0); } + + void tmplput_FLOOR_NAME(StrBuf *Target, WCTemplputParams *TP) { Floor *myFloor = (Floor *)CTX; @@ -108,12 +122,15 @@ void tmplput_FLOOR_NAME(StrBuf *Target, WCTemplputParams *TP) StrBufAppendTemplate(Target, TP, myFloor->Name, 0); } + void tmplput_FLOOR_NROOMS(StrBuf *Target, WCTemplputParams *TP) { Floor *myFloor = (Floor *)CTX; StrBufAppendPrintf(Target, "%d", myFloor->NRooms); } + + void tmplput_ROOM_FLOOR_NROOMS(StrBuf *Target, WCTemplputParams *TP) { folder *Folder = (folder *)CTX; @@ -123,6 +140,8 @@ void tmplput_ROOM_FLOOR_NROOMS(StrBuf *Target, WCTemplputParams *TP) return; StrBufAppendPrintf(Target, "%d", pFloor->NRooms); } + + int ConditionalFloorHaveNRooms(StrBuf *Target, WCTemplputParams *TP) { Floor *MyFloor = (Floor *)CTX; @@ -133,6 +152,7 @@ int ConditionalFloorHaveNRooms(StrBuf *Target, WCTemplputParams *TP) return HaveN == MyFloor->NRooms; } + int ConditionalFloorIsRESTSubFloor(StrBuf *Target, WCTemplputParams *TP) { wcsession *WCC = WC; @@ -143,6 +163,8 @@ int ConditionalFloorIsRESTSubFloor(StrBuf *Target, WCTemplputParams *TP) return 1; return WCC->CurrentFloor == MyFloor; } + + int ConditionalFloorIsSUBROOM(StrBuf *Target, WCTemplputParams *TP) { wcsession *WCC = WC; @@ -160,24 +182,31 @@ int ConditionalFloorIsVirtual(StrBuf *Target, WCTemplputParams *TP) } - /******************************************************************************* ********************** ROOM Tokens ******************************************** - ******************************************************************************/ + *******************************************************************************/ /**** Name ******/ + + void tmplput_RoomName(StrBuf *Target, WCTemplputParams *TP) { StrBufAppendTemplate(Target, TP, WC->CurRoom.name, 0); } + + void tmplput_current_room(StrBuf *Target, WCTemplputParams *TP) { wcsession *WCC = WC; - if (WCC != NULL) + if (WCC != NULL) { StrBufAppendTemplate(Target, TP, - WCC->CurRoom.name, - 0); + WCC->CurRoom.name, + 0 + ); + } } + + void tmplput_ROOM_NAME(StrBuf *Target, WCTemplputParams *TP) { folder *Folder = (folder *)CTX; @@ -192,6 +221,8 @@ void tmplput_ROOM_NAME(StrBuf *Target, WCTemplputParams *TP) } StrBufAppendTemplate(Target, TP, Folder->name, 0); } + + void tmplput_ROOM_BASENAME(StrBuf *Target, WCTemplputParams *TP) { folder *room = (folder *)CTX; @@ -202,6 +233,8 @@ void tmplput_ROOM_BASENAME(StrBuf *Target, WCTemplputParams *TP) else StrBufAppendTemplate(Target, TP, room->name, 0); } + + void tmplput_ROOM_LEVEL_N_TIMES(StrBuf *Target, WCTemplputParams *TP) { folder *room = (folder *)CTX; @@ -217,13 +250,25 @@ void tmplput_ROOM_LEVEL_N_TIMES(StrBuf *Target, WCTemplputParams *TP) StrBufAppendBufPlain(Target, AppendMe, AppendMeLen, 0); } } + + int ConditionalRoomIsInbox(StrBuf *Target, WCTemplputParams *TP) { folder *Folder = (folder *)CTX; return Folder->is_inbox; } + /****** Properties ******/ +int ConditionalRoom_MayEdit(StrBuf *Target, WCTemplputParams *TP) +{ + wcsession *WCC = WC; + + LoadRoomXA (); + + return WCC->CurRoom.XALoaded == 1; +} + int ConditionalThisRoomHas_QRFlag(StrBuf *Target, WCTemplputParams *TP) { long QR_CheckFlag; @@ -243,6 +288,8 @@ int ConditionalThisRoomHas_QRFlag(StrBuf *Target, WCTemplputParams *TP) else return (WCC->CurRoom.QRFlags & QR_CheckFlag) == QR_CheckFlag; } + + int ConditionalRoomHas_QRFlag(StrBuf *Target, WCTemplputParams *TP) { long QR_CheckFlag; @@ -259,6 +306,8 @@ int ConditionalRoomHas_QRFlag(StrBuf *Target, WCTemplputParams *TP) else return (Folder->QRFlags & QR_CheckFlag) == QR_CheckFlag; } + + void tmplput_ROOM_QRFLAGS(StrBuf *Target, WCTemplputParams *TP) { folder *Folder = (folder *)CTX; @@ -286,6 +335,8 @@ int ConditionalThisRoomHas_QRFlag2(StrBuf *Target, WCTemplputParams *TP) else return (WCC->CurRoom.QRFlags2 & QR2_CheckFlag) == QR2_CheckFlag; } + + int ConditionalRoomHas_QRFlag2(StrBuf *Target, WCTemplputParams *TP) { long QR2_CheckFlag; @@ -298,6 +349,7 @@ int ConditionalRoomHas_QRFlag2(StrBuf *Target, WCTemplputParams *TP) return ((Folder->QRFlags2 & QR2_CheckFlag) != 0); } + int ConditionalRoomHas_UAFlag(StrBuf *Target, WCTemplputParams *TP) { folder *Folder = (folder *)(TP->Context); @@ -312,9 +364,6 @@ int ConditionalRoomHas_UAFlag(StrBuf *Target, WCTemplputParams *TP) } - - - void tmplput_ROOM_ACL(StrBuf *Target, WCTemplputParams *TP) { folder *Folder = (folder *)CTX; @@ -323,7 +372,6 @@ void tmplput_ROOM_ACL(StrBuf *Target, WCTemplputParams *TP) } - void tmplput_ROOM_RAFLAGS(StrBuf *Target, WCTemplputParams *TP) { folder *Folder = (folder *)(TP->Context); @@ -339,6 +387,8 @@ void tmplput_ThisRoomAide(StrBuf *Target, WCTemplputParams *TP) StrBufAppendTemplate(Target, TP, WCC->CurRoom.RoomAide, 0); } + + int ConditionalRoomAide(StrBuf *Target, WCTemplputParams *TP) { wcsession *WCC = WC; @@ -346,6 +396,7 @@ int ConditionalRoomAide(StrBuf *Target, WCTemplputParams *TP) ((WCC->CurRoom.RAFlags & UA_ADMINALLOWED) != 0) : 0; } + int ConditionalRoomAcessDelete(StrBuf *Target, WCTemplputParams *TP) { wcsession *WCC = WC; @@ -356,30 +407,30 @@ int ConditionalRoomAcessDelete(StrBuf *Target, WCTemplputParams *TP) } - int ConditionalHaveRoomeditRights(StrBuf *Target, WCTemplputParams *TP) { wcsession *WCC = WC; - return ( (WCC!= NULL) && - ((WCC->axlevel >= 6) || - ((WCC->CurRoom.RAFlags & UA_ADMINALLOWED) != 0) || - (WCC->CurRoom.is_inbox) )); + return ( (WCC != NULL) + && (WCC->logged_in) + && ( + (WCC->axlevel >= 6) + || ((WCC->CurRoom.RAFlags & UA_ADMINALLOWED) != 0) + || (WCC->CurRoom.is_inbox) + ) + ); } + + void tmplput_ThisRoomPass(StrBuf *Target, WCTemplputParams *TP) { wcsession *WCC = WC; LoadRoomXA(); - StrBufAppendTemplate(Target, TP, WCC->CurRoom.XAPass, 0); } - - - - void tmplput_ThisRoom_nNewMessages(StrBuf *Target, WCTemplputParams *TP) { wcsession *WCC = WC; @@ -387,6 +438,7 @@ void tmplput_ThisRoom_nNewMessages(StrBuf *Target, WCTemplputParams *TP) StrBufAppendPrintf(Target, "%d", WCC->CurRoom.nNewMessages); } + void tmplput_ThisRoom_nTotalMessages(StrBuf *Target, WCTemplputParams *TP) { wcsession *WCC = WC; @@ -395,10 +447,6 @@ void tmplput_ThisRoom_nTotalMessages(StrBuf *Target, WCTemplputParams *TP) } - - - - void tmplput_ThisRoomOrder(StrBuf *Target, WCTemplputParams *TP) { wcsession *WCC = WC; @@ -407,6 +455,8 @@ void tmplput_ThisRoomOrder(StrBuf *Target, WCTemplputParams *TP) StrBufAppendPrintf(Target, "%d", WCC->CurRoom.Order); } + + int ConditionalThisRoomOrder(StrBuf *Target, WCTemplputParams *TP) { wcsession *WCC = WC; @@ -420,6 +470,8 @@ int ConditionalThisRoomOrder(StrBuf *Target, WCTemplputParams *TP) CheckThis = GetTemplateTokenNumber(Target, TP, 2, 0); return CheckThis == WCC->CurRoom.Order; } + + void tmplput_ROOM_LISTORDER(StrBuf *Target, WCTemplputParams *TP) { folder *Folder = (folder *)CTX; @@ -427,9 +479,6 @@ void tmplput_ROOM_LISTORDER(StrBuf *Target, WCTemplputParams *TP) } - - - int ConditionalThisRoomXHavePic(StrBuf *Target, WCTemplputParams *TP) { wcsession *WCC = WC; @@ -452,22 +501,34 @@ int ConditionalThisRoomXHaveInfoText(StrBuf *Target, WCTemplputParams *TP) LoadXRoomInfoText(); return (StrLength(WCC->CurRoom.XInfoText)>0); } + + void tmplput_ThisRoomInfoText(StrBuf *Target, WCTemplputParams *TP) { wcsession *WCC = WC; + long nchars = 0; LoadXRoomInfoText(); - StrBufAppendTemplate(Target, TP, WCC->CurRoom.XAPass, 1); + nchars = GetTemplateTokenNumber(Target, TP, 0, 0); + if (!nchars) { + /* the whole thing */ + StrBufAppendTemplate(Target, TP, WCC->CurRoom.XInfoText, 1); + } + else { + /* only a certain number of characters */ + StrBuf *SubBuf; + SubBuf = NewStrBufDup(WCC->CurRoom.XInfoText); + if (StrLength(SubBuf) > nchars) { + StrBuf_Utf8StrCut(SubBuf, nchars); + StrBufAppendBufPlain(SubBuf, HKEY("..."), 0); + } + StrBufAppendTemplate(Target, TP, SubBuf, 1); + FreeStrBuf(&SubBuf); + } } - - - - - - void tmplput_ROOM_LASTCHANGE(StrBuf *Target, WCTemplputParams *TP) { folder *Folder = (folder *)CTX; @@ -475,12 +536,6 @@ void tmplput_ROOM_LASTCHANGE(StrBuf *Target, WCTemplputParams *TP) } - - - - - - void tmplput_ThisRoomDirectory(StrBuf *Target, WCTemplputParams *TP) { wcsession *WCC = WC; @@ -489,6 +544,8 @@ void tmplput_ThisRoomDirectory(StrBuf *Target, WCTemplputParams *TP) StrBufAppendTemplate(Target, TP, WCC->CurRoom.Directory, 0); } + + void tmplput_ThisRoomXNFiles(StrBuf *Target, WCTemplputParams *TP) { wcsession *WCC = WC; @@ -498,6 +555,7 @@ void tmplput_ThisRoomXNFiles(StrBuf *Target, WCTemplputParams *TP) StrBufAppendPrintf(Target, "%d", WCC->CurRoom.XDownloadCount); } + void tmplput_ThisRoomX_FileString(StrBuf *Target, WCTemplputParams *TP) { wcsession *WCC = WC; @@ -511,6 +569,18 @@ void tmplput_ThisRoomX_FileString(StrBuf *Target, WCTemplputParams *TP) } +int ConditionalIsThisThatRoom(StrBuf *Target, WCTemplputParams *TP) +{ + folder *Folder = (folder *)CTX; + wcsession *WCC = WC; + + if (WCC == NULL) + return 0; + + return Folder == WCC->ThisRoom; +} + + void InitModule_ROOMTOKENS (void) @@ -536,7 +606,7 @@ InitModule_ROOMTOKENS /**** Room... ******/ /**** Name ******/ RegisterNamespace("ROOMNAME", 0, 1, tmplput_RoomName, NULL, CTX_NONE); - RegisterNamespace("CURRENT_ROOM", 0, 1, tmplput_current_room, NULL, CTX_NONE); + RegisterNamespace("THISROOM", 0, 1, tmplput_current_room, NULL, CTX_NONE); RegisterNamespace("ROOM:INFO:NAME", 0, 1, tmplput_ROOM_NAME, NULL, CTX_ROOMS); RegisterNamespace("ROOM:INFO:PRINT_NAME", 0, 1, tmplput_ROOM_NAME, NULL, CTX_NONE); RegisterNamespace("ROOM:INFO:BASENAME", 0, 1, tmplput_ROOM_BASENAME, NULL, CTX_ROOMS); @@ -546,6 +616,7 @@ InitModule_ROOMTOKENS /****** Properties ******/ RegisterNamespace("ROOM:INFO:QRFLAGS", 0, 1, tmplput_ROOM_QRFLAGS, NULL, CTX_ROOMS); RegisterConditional(HKEY("COND:THISROOM:FLAG:QR"), 0, ConditionalThisRoomHas_QRFlag, CTX_NONE); + RegisterConditional(HKEY("COND:THISROOM:EDIT"), 0, ConditionalRoom_MayEdit, CTX_NONE); RegisterConditional(HKEY("COND:ROOM:FLAG:QR"), 0, ConditionalRoomHas_QRFlag, CTX_ROOMS); RegisterConditional(HKEY("COND:THISROOM:FLAG:QR2"), 0, ConditionalThisRoomHas_QRFlag2, CTX_NONE); @@ -579,10 +650,6 @@ InitModule_ROOMTOKENS RegisterNamespace("THISROOM:FILES:STR", 0, 1, tmplput_ThisRoomX_FileString, NULL, CTX_NONE); RegisterNamespace("THISROOM:DIRECTORY", 0, 1, tmplput_ThisRoomDirectory, NULL, CTX_NONE); - - - - - RegisterNamespace("ROOM:INFO:ACL", 0, 1, tmplput_ROOM_ACL, NULL, CTX_ROOMS); + RegisterConditional(HKEY("COND:THIS:THAT:ROOM"), 0, ConditionalIsThisThatRoom, CTX_ROOMS); }