DCL 3.7.4
Loading...
Searching...
No Matches
LinkUtility.cpp
Go to the documentation of this file.
1#include <dcl/Config.h>
2
3#ifdef __WINNT__
4#include <windows.h>
5#endif
6
7#include "LinkUtility.h"
8
9#if __DCL_HAVE_THIS_FILE__
10#undef __THIS_FILE__
11static const char_t __THIS_FILE__[] = __T("fastpage/LinkUtility.cpp");
12#endif
13
14__DCL_BEGIN_NAMESPACE
15
17 TextTemplate* pSource, // "PART_LINK"
18 const String& strThis, // "n[&msg=][&rows=]"
19 const String& strLinkEnc // URLEncode(strToList)
20)
21{
22 __pSource = pSource;
23 if (__pSource) {
24 const wchar_t* aNames[] = { L"FIRST", L"PREV", L"GOTO", L"NEXT", L"LAST"};
25
26 for(int i = 0; i < 5; i++) {
27 TextTemplate* p = __pSource->atP(aNames[i]);
28 if (p) {
29 p->assign(L"THIS", strThis);
30 p->assign(L"_LIST", strLinkEnc);
31 }
32 }
33 }
34}
35
36static String __PART(int n)
37{
38 String s;
39 if (n > 1)
40 s = L"&part=" + String::valueOf(n);
41 return s;
42}
43
45 TextTemplate* pDest,
46 int nTotalPart,
47 int nCurrentPart,
48 int nGotoPart // PARTS
49)
50{
51 __DCL_ASSERT(NULL != pDest);
52 __DCL_ASSERT(nTotalPart > 0);
53 __DCL_ASSERT(nCurrentPart > 0);
54 __DCL_ASSERT(nGotoPart > 0);
55
56 int nStartPart = nCurrentPart - ((nCurrentPart - 1) % nGotoPart);
57 int nEndPart = nStartPart + nGotoPart - 1;
58 if (nEndPart > nTotalPart)
59 nEndPart = nTotalPart;
60
61 if (nStartPart <= nGotoPart) {
62 // 1 <= nStartPart <= nGotoPart
63// __pSource->erase(L"FIRST");
64// __pSource->erase(L"PREV");
65 }
66 else {
67 TextTemplate& FIRST = (*__pSource)[L"FIRST"];
68 FIRST.assign(L"PART", __PART(1));
69 __pSource->assign(L"FIRST", FIRST);
70
71 TextTemplate& PREV = (*__pSource)[L"PREV"];
72 PREV.assign(L"PART", __PART(nStartPart - 1));
73 __pSource->assign(L"PREV", PREV);
74 }
75
76 if ((nStartPart + nGotoPart) > nTotalPart) {
77// __pSource->erase(L"NEXT");
78// __pSource->erase(L"LAST");
79 }
80 else {
81 int nNext = nCurrentPart + nGotoPart - ((nCurrentPart - 1) % nGotoPart);
82
83 TextTemplate& NEXT = (*__pSource)[L"NEXT"];
84 NEXT.assign(L"PART", __PART(nNext));
85 __pSource->assign(L"NEXT", NEXT);
86
87 TextTemplate& LAST = (*__pSource)[L"LAST"];
88 LAST.assign(L"PART", __PART(nTotalPart));
89 __pSource->assign(L"LAST", LAST);
90 }
91
92 TextTemplate& GOTO = (*__pSource)[L"GOTO"];
93 TextTemplate& CURRENT = (*__pSource)[L"CURRENT"];
94// __pSource->erase(L"CURRENT");
95
96 for(int n = nStartPart; n <= nEndPart; n++) {
97 if (n == nCurrentPart) {
98 CURRENT.assign(L"NO", String::valueOf(n));
99 __pSource->append(L"GOTO", CURRENT);
100 }
101 else {
102 GOTO.assign(L"NO", String::valueOf(n));
103 GOTO.assign(L"PART", __PART(n));
104 __pSource->append(L"GOTO", GOTO);
105 }
106 }
107
108 pDest->assign(L"PART_LINK", *__pSource);
109}
110
112 TextTemplate* pSource,
113 const String& strDetailPage,
114 const String& strListEnc
115)
116{
117 __pSource = pSource;
118 __pPREV = NULL;
119 __pNEXT = NULL;
120 __pNPREV = NULL;
121 __pNNEXT = NULL;
122
123 if (pSource) {
124 __pPREV = &(*__pSource)[L"_PREV"];
125 __pNEXT = &(*__pSource)[L"_NEXT"];
126
127 __pNPREV = &(*__pSource)[L"N_PREV"];
128 __pNNEXT = &(*__pSource)[L"N_NEXT"];
129
130 __pPREV->assign(L"DETAIL", strDetailPage);
131 __pPREV->assign(L"_LIST", strListEnc);
132 __pNEXT->assign(L"DETAIL", strDetailPage);
133 __pNEXT->assign(L"_LIST", strListEnc);
134 }
135}
136
138 TextTemplate* pDest,
139 _CONST SQLFields& fields
140)
141{
142 if (__pSource) {
143 int nPREV_ID = fields.byName(L"PREV_ID").asInteger();
144 int nNEXT_ID = fields.byName(L"NEXT_ID").asInteger();
145
146 if (nPREV_ID > 0) {
147 __pPREV->assign(L"PREV_ID", String::valueOf(nPREV_ID));
148 pDest->assign(L"_PREV", *__pPREV);
149 }
150 else
151 pDest->assign(L"_PREV", *__pNPREV);
152
153 if (nNEXT_ID > 0) {
154 __pNEXT->assign(L"NEXT_ID", String::valueOf(nNEXT_ID));
155 pDest->assign(L"_NEXT", *__pNEXT);
156 }
157 else
158 pDest->assign(L"_NEXT", *__pNNEXT);
159 }
160}
161
163 TextTemplate* pDest,
164 _CONST SQLFields& fields,
165 const String& strListEnc
166)
167{
168 if (__pSource) {
169 __pPREV->assign(L"_LIST", strListEnc);
170 __pNEXT->assign(L"_LIST", strListEnc);
171
172 assign(pDest, fields);
173 }
174}
175
177 TextTemplate* pSource,
178 const String& strDetailPage,
179 const String& strToEdit,
180 const String& strThisEnc,
181 const String& strListEnc
182)
183{
184 __pSource = pSource;
185
186 __pADD = NULL;
187 __pREPLY = NULL;
188 __pAGREE = NULL;
190 __pMODIFY = NULL;
191 __pDELETE = NULL;
192
193 __pNADD = NULL;
194 __pNREPLY = NULL;
195 __pNAGREE = NULL;
199
200 if (__pSource) {
201 __pADD = __pSource->atP(L"_ADD");
202 if (__pADD) {
203 __pNADD = &(*__pSource)[L"N_ADD"];
204 __pADD->assign(L"DETAIL", strDetailPage);
205 __pADD->assign(L"EDIT", strToEdit);
206 __pADD->assign(L"_THIS", strThisEnc);
207 __pADD->assign(L"_LIST", strListEnc);
208 }
209 __pREPLY = __pSource->atP(L"_REPLY");
210 if (__pREPLY) {
211 __pNREPLY = &(*__pSource)[L"N_REPLY"];
212 __pREPLY->assign(L"DETAIL", strDetailPage);
213 __pREPLY->assign(L"EDIT", strToEdit);
214 __pREPLY->assign(L"_THIS", strThisEnc);
215 __pREPLY->assign(L"_LIST", strListEnc);
216 }
217 __pAGREE = __pSource->atP(L"_AGREE");
218 if (__pAGREE) {
219 __pNAGREE = &(*__pSource)[L"N_AGREE"];
220 __pAGREE->assign(L"EDIT", strToEdit);
221 __pAGREE->assign(L"_THIS", strThisEnc);
222 __pAGREE->assign(L"_LIST", strListEnc);
223 }
224 __pDISAGREE = __pSource->atP(L"_DISAGREE");
225 if (__pDISAGREE) {
226 __pNDISAGREE = &(*__pSource)[L"N_DISAGREE"];
227 __pDISAGREE->assign(L"EDIT", strToEdit);
228 __pDISAGREE->assign(L"_THIS", strThisEnc);
229 __pDISAGREE->assign(L"_LIST", strListEnc);
230 }
231 __pMODIFY = __pSource->atP(L"_MODIFY");
232 if (__pMODIFY) {
233 __pNMODIFY= &(*__pSource)[L"N_MODIFY"];
234 __pMODIFY->assign(L"DETAIL", strDetailPage);
235 __pMODIFY->assign(L"EDIT", strToEdit);
236 __pMODIFY->assign(L"_THIS", strThisEnc);
237 __pMODIFY->assign(L"_LIST", strListEnc);
238 }
239 __pDELETE = __pSource->atP(L"_DELETE");
240 if (__pDELETE) {
241 __pNDELETE = &(*__pSource)[L"N_DELETE"];
242 __pDELETE->assign(L"EDIT", strToEdit);
243 __pDELETE->assign(L"_THIS", strThisEnc);
244 __pDELETE->assign(L"_LIST", strListEnc);
245 }
246 }
247}
248
250 TextTemplate* pDest,
251 _CONST SQLFields& fields,
252 const Session& session,
253 const String& strMessageID,
254 const String& strToList,
255 const MessageTree& mt,
256 const MessageTree::Position& pos
257)
258{
259 if (__pSource) {
260 // 추가, 답글, 추천, 비난, 수정, 삭제
261 if (session.isSysGuest()) {
262 if (__pADD) {
264 // __pNADD->assign(L"TITLE", L"권한이 없습니다");
265 pDest->assign(L"_ADD", *__pNADD);
266 }
267 if (__pREPLY) {
269 // __pNREPLY->assign(L"TITLE", L"권한이 없습니다");
270 pDest->assign(L"_REPLY", *__pNREPLY);
271 }
272 if (__pAGREE) {
274 // __pNAGREE->assign(L"TITLE", L"권한이 없습니다");
275 pDest->assign(L"_AGREE", *__pNAGREE);
276 }
277 if (__pDISAGREE) {
279 // __pNDISAGREE->assign(L"TITLE", L"권한이 없습니다");
280 pDest->assign(L"_DISAGREE", *__pNDISAGREE);
281 }
282 if (__pMODIFY) {
284 // __pNMODIFY->assign(L"TITLE", L"권한이 없습니다");
285 pDest->assign(L"_MODIFY", *__pNMODIFY);
286 }
287 if (__pDELETE) {
289 // __pNDELETE->assign(L"TITLE", L"권한이 없습니다");
290 pDest->assign(L"_DELETE", *__pNDELETE);
291 }
292 }
293 else {
294 if (__pADD) {
295 __pADD->assign(L"PARENT_ID", fields.byName(L"PARENT_ID").asString());
296 pDest->assign(L"_ADD", *__pADD);
297 }
298
299 if (__pREPLY) {
301 int nChild = fields.byName(L"NCHILD").asInteger();
302 if (nChild == mt.width()) {
303 // __pNREPLY->assign(L"TITLE", L"최대 답글개수에 도달했습니다");
304 pDest->assign(L"_REPLY", *__pNREPLY);
305 }
306 else if (pos.nDepthIndex == (mt.depth() - 1)) {
307 // __pNREPLY->assign(L"TITLE", L"답글을 위한 최대 깊이에 도달했습니다");
308 pDest->assign(L"_REPLY", *__pNREPLY);
309 }
310 else {
311 __pREPLY->assign(L"MESSAGE_ID", strMessageID);
312 pDest->assign(L"_REPLY", *__pREPLY);
313 }
314 }
315
316 int nUserID = fields.byName(L"USER_ID").asInteger();
317 if (__pAGREE || __pDISAGREE) {
318 if (session.__nUserID == nUserID) {
319 if (__pAGREE) {
321 // __pNAGREE->assign(L"TITLE", L"자신의 글에 투표를 할 수 없습니다");
322 pDest->assign(L"_AGREE", *__pNAGREE);
323 }
324
325 if (__pDISAGREE) {
327 // __pNDISAGREE->assign(L"TITLE", L"자신의 글에 투표를 할 수 없습니다");
328 pDest->assign(L"_DISAGREE", *__pNDISAGREE);
329 }
330 }
331 else {
332 SQLField& VOTE_END = fields.byName(L"VOTE_END");
333 if (!VOTE_END.isNull() &&
334 VOTE_END.asDateTime() < DateTime::getCurrentLocalTime()
335 ) {
336 if (__pAGREE) {
338 // __pNAGREE->assign(L"TITLE", L"투표기간이 지났습니다");
339 pDest->assign(L"_AGREE", *__pNAGREE);
340 }
341 if (__pDISAGREE) {
343 // __pNDISAGREE->assign(L"TITLE", L"투표기간이 지났습니다");
344 pDest->assign(L"_DISAGREE", *__pNDISAGREE);
345 }
346 }
347 else {
348 if (__pAGREE) {
349 __pAGREE->assign(L"MESSAGE_ID", strMessageID);
350 pDest->assign(L"_AGREE", *__pAGREE);
351 }
352 if (__pDISAGREE) {
353 __pDISAGREE->assign(L"MESSAGE_ID", strMessageID);
354 pDest->assign(L"_DISAGREE", *__pDISAGREE);
355 }
356 }
357 }
358 }
359 if (__pMODIFY) {
360 if (session.__nUserID == nUserID) {
361 __pMODIFY->assign(L"MESSAGE_ID", strMessageID);
362 pDest->assign(L"_MODIFY", *__pMODIFY);
363 }
364 else {
366 // __pNMODIFY->assign(L"TITLE", L"권한이 없습니다");
367 pDest->assign(L"_MODIFY", *__pNMODIFY);
368 }
369 }
370 if (__pDELETE) {
371 if (session.__nUserID == nUserID || session.isSysAdmin()) {
372 __pDELETE->assign(L"MESSAGE_ID", strMessageID);
373 pDest->assign(L"_DELETE", *__pDELETE);
374 }
375 else {
377 // __pNDELETE->assign(L"TITLE", L"권한이 없습니다");
378 pDest->assign(L"_DELETE", *__pNDELETE);
379 }
380 }
381 }
382 } // if (__pSource)
383}
384
386 TextTemplate* pSource,
387 int nRecentHour
388)
389{
390 time_t tNow = time(NULL);
391 tNow -= nRecentHour * 60 * 60;
392 __dtBase.assign(tNow);
393
394 if (pSource) {
395 __pNew = pSource->atP(L"_NEW");
396 __pOld = pSource->atP(L"_OLD");
397 }
398}
399
401 TextTemplate* pDest,
402 DateTime dt
403)
404{
405 if (__dtBase < dt) {
406 if (__pNew)
407 pDest->assign(L"_RECENT", *__pNew);
408 }
409 else {
410 if (__pOld)
411 pDest->assign(L"_RECENT", *__pOld);
412 }
413}
414
416 TextTemplate* pSource,
417 int nGroup
418)
419{
420 __pOdd = NULL;
421 __pEven = NULL;
422 __nGroup = nGroup;
423 if (pSource) {
424 __pOdd = pSource->atP(L"ODD");
425 __pEven = pSource->atP(L"EVEN");
426 }
427}
429 TextTemplate* pDest,
430 int nRow // 1, 2, 3
431)
432{
433 int n = ((nRow - 1) / __nGroup) % 2;
434 if (n) {
435 // even
436 if (__pEven)
437 pDest->assign(L"_GROUP", *__pEven);
438 }
439 else {
440 if (__pOdd)
441 pDest->assign(L"_GROUP", *__pOdd);
442 }
443}
444
445__DCL_END_NAMESPACE
#define __THIS_FILE__
Definition _trace.h:14
#define NULL
Definition Config.h:312
wchar_t char_t
Definition Config.h:247
#define _CONST
Definition Config.h:325
#define __DCL_ASSERT(expr)
Definition Object.h:394
#define __T(str)
Definition Object.h:60
static DateTime getCurrentLocalTime()
Definition DateTime.cpp:954
int depth() const
Definition MessageTree.h:91
int width() const
Definition MessageTree.h:96
DateTime __dtBase
TextTemplate * __pOld
void assign(TextTemplate *pDest, DateTime dt)
TextTemplate * __pNew
RecentIcon(TextTemplate *pSource, int nRecentHour)
void assign(TextTemplate *pDest, int nRow)
TextTemplate * __pOdd
RowGroup(TextTemplate *pSource, int nGroup)
TextTemplate * __pEven
Definition SQL.h:48
int __nUserID
Definition Session.h:33
bool isSysAdmin() const
Definition Session.h:75
bool isSysGuest() const
Definition Session.h:70