forked from siteserver/cms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChannelManager.cs
More file actions
801 lines (694 loc) · 29.4 KB
/
ChannelManager.cs
File metadata and controls
801 lines (694 loc) · 29.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI.WebControls;
using SiteServer.CMS.Core;
using SiteServer.CMS.DataCache.Core;
using SiteServer.CMS.DataCache.Stl;
using SiteServer.CMS.Model;
using SiteServer.CMS.Model.Attributes;
using SiteServer.CMS.Model.Enumerations;
using SiteServer.CMS.Plugin;
using SiteServer.CMS.Plugin.Impl;
using SiteServer.Plugin;
using SiteServer.Utils;
using SiteServer.Utils.Enumerations;
namespace SiteServer.CMS.DataCache
{
public static class ChannelManager
{
private static class ChannelManagerCache
{
private static readonly object LockObject = new object();
private static readonly string CacheKey = DataCacheManager.GetCacheKey(nameof(ChannelManager));
private static void Update(Dictionary<int, Dictionary<int, ChannelInfo>> allDict, Dictionary<int, ChannelInfo> dic, int siteId)
{
lock (LockObject)
{
allDict[siteId] = dic;
}
}
private static Dictionary<int, Dictionary<int, ChannelInfo>> GetAllDictionary()
{
var allDict = DataCacheManager.Get<Dictionary<int, Dictionary<int, ChannelInfo>>>(CacheKey);
if (allDict != null) return allDict;
allDict = new Dictionary<int, Dictionary<int, ChannelInfo>>();
DataCacheManager.Insert(CacheKey, allDict);
return allDict;
}
public static void Remove(int siteId)
{
var allDict = GetAllDictionary();
lock (LockObject)
{
allDict.Remove(siteId);
}
}
public static void Update(int siteId, ChannelInfo channelInfo)
{
var dict = GetChannelInfoDictionaryBySiteId(siteId);
lock (LockObject)
{
dict[channelInfo.Id] = channelInfo;
}
}
public static Dictionary<int, ChannelInfo> GetChannelInfoDictionaryBySiteId(int siteId)
{
var allDict = GetAllDictionary();
Dictionary<int, ChannelInfo> dict;
allDict.TryGetValue(siteId, out dict);
if (dict != null) return dict;
dict = DataProvider.ChannelDao.GetChannelInfoDictionaryBySiteId(siteId);
Update(allDict, dict, siteId);
return dict;
}
}
public static void RemoveCacheBySiteId(int siteId)
{
ChannelManagerCache.Remove(siteId);
StlChannelCache.ClearCache();
}
public static void UpdateCache(int siteId, ChannelInfo channelInfo)
{
ChannelManagerCache.Update(siteId, channelInfo);
StlChannelCache.ClearCache();
}
public static ChannelInfo GetChannelInfo(int siteId, int channelId)
{
ChannelInfo channelInfo = null;
var dict = ChannelManagerCache.GetChannelInfoDictionaryBySiteId(siteId);
dict?.TryGetValue(Math.Abs(channelId), out channelInfo);
return channelInfo;
}
public static int GetChannelId(int siteId, int channelId, string channelIndex, string channelName)
{
var retval = channelId;
if (!string.IsNullOrEmpty(channelIndex))
{
var theChannelId = GetChannelIdByIndexName(siteId, channelIndex);
if (theChannelId != 0)
{
retval = theChannelId;
}
}
if (!string.IsNullOrEmpty(channelName))
{
var theChannelId = GetChannelIdByParentIdAndChannelName(siteId, retval, channelName, true);
if (theChannelId == 0)
{
theChannelId = GetChannelIdByParentIdAndChannelName(siteId, siteId, channelName, true);
}
if (theChannelId != 0)
{
retval = theChannelId;
}
}
return retval;
}
public static int GetChannelIdByIndexName(int siteId, string indexName)
{
if (string.IsNullOrEmpty(indexName)) return 0;
var dict = ChannelManagerCache.GetChannelInfoDictionaryBySiteId(siteId);
var channelInfo = dict.Values.FirstOrDefault(x => x != null && x.IndexName == indexName);
return channelInfo?.Id ?? 0;
}
public static int GetChannelIdByParentIdAndChannelName(int siteId, int parentId, string channelName, bool recursive)
{
if (parentId <= 0 || string.IsNullOrEmpty(channelName)) return 0;
var dict = ChannelManagerCache.GetChannelInfoDictionaryBySiteId(siteId);
var channelInfoList = dict.Values.OrderBy(x => x.Taxis).ToList();
ChannelInfo channelInfo;
if (recursive)
{
if (siteId == parentId)
{
channelInfo = channelInfoList.FirstOrDefault(x => x.ChannelName == channelName);
//sqlString = $"SELECT Id FROM siteserver_Channel WHERE (SiteId = {siteId} AND ChannelName = '{AttackUtils.FilterSql(channelName)}') ORDER BY Taxis";
}
else
{
channelInfo = channelInfoList.FirstOrDefault(x => (x.ParentId == parentId || TranslateUtils.StringCollectionToIntList(x.ParentsPath).Contains(parentId)) && x.ChannelName == channelName);
// sqlString = $@"SELECT Id
//FROM siteserver_Channel
//WHERE ((ParentId = {parentId}) OR
// (ParentsPath = '{parentId}') OR
// (ParentsPath LIKE '{parentId},%') OR
// (ParentsPath LIKE '%,{parentId},%') OR
// (ParentsPath LIKE '%,{parentId}')) AND ChannelName = '{AttackUtils.FilterSql(channelName)}'
//ORDER BY Taxis";
}
}
else
{
channelInfo = channelInfoList.FirstOrDefault(x => x.ParentId == parentId && x.ChannelName == channelName);
//sqlString = $"SELECT Id FROM siteserver_Channel WHERE (ParentId = {parentId} AND ChannelName = '{AttackUtils.FilterSql(channelName)}') ORDER BY Taxis";
}
return channelInfo?.Id ?? 0;
}
//public static List<string> GetIndexNameList(int siteId)
//{
// var dic = ChannelManagerCache.GetChannelInfoDictionaryBySiteId(siteId);
// return dic.Values.Where(x => !string.IsNullOrEmpty(x?.IndexName)).Select(x => x.IndexName).Distinct().ToList();
//}
public static List<ChannelInfo> GetChannelInfoList(int siteId)
{
var dic = ChannelManagerCache.GetChannelInfoDictionaryBySiteId(siteId);
return dic.Values.Where(channelInfo => channelInfo != null).ToList();
}
public static List<int> GetChannelIdList(int siteId)
{
var dic = ChannelManagerCache.GetChannelInfoDictionaryBySiteId(siteId);
return dic.Values.OrderBy(c => c.Taxis).Select(channelInfo => channelInfo.Id).ToList();
}
public static List<int> GetChannelIdList(ChannelInfo channelInfo, EScopeType scopeType)
{
return GetChannelIdList(channelInfo, scopeType, string.Empty, string.Empty, string.Empty);
}
public static List<int> GetChannelIdList(ChannelInfo channelInfo, EScopeType scopeType, string group, string groupNot, string contentModelPluginId)
{
if (channelInfo == null) return new List<int>();
var dic = ChannelManagerCache.GetChannelInfoDictionaryBySiteId(channelInfo.SiteId);
var channelInfoList = new List<ChannelInfo>();
if (channelInfo.ChildrenCount == 0)
{
if (scopeType != EScopeType.Children && scopeType != EScopeType.Descendant)
{
channelInfoList.Add(channelInfo);
}
}
else if (scopeType == EScopeType.Self)
{
channelInfoList.Add(channelInfo);
}
else if (scopeType == EScopeType.All)
{
foreach (var nodeInfo in dic.Values)
{
if (nodeInfo.Id == channelInfo.Id || nodeInfo.ParentId == channelInfo.Id || StringUtils.In(nodeInfo.ParentsPath, channelInfo.Id))
{
channelInfoList.Add(nodeInfo);
}
}
}
else if (scopeType == EScopeType.Children)
{
foreach (var nodeInfo in dic.Values)
{
if (nodeInfo.ParentId == channelInfo.Id)
{
channelInfoList.Add(nodeInfo);
}
}
}
else if (scopeType == EScopeType.Descendant)
{
foreach (var nodeInfo in dic.Values)
{
if (nodeInfo.ParentId == channelInfo.Id || StringUtils.In(nodeInfo.ParentsPath, channelInfo.Id))
{
channelInfoList.Add(nodeInfo);
}
}
}
else if (scopeType == EScopeType.SelfAndChildren)
{
foreach (var nodeInfo in dic.Values)
{
if (nodeInfo.Id == channelInfo.Id || nodeInfo.ParentId == channelInfo.Id)
{
channelInfoList.Add(nodeInfo);
}
}
}
var filteredChannelInfoList = new List<ChannelInfo>();
foreach (var nodeInfo in channelInfoList)
{
if (!string.IsNullOrEmpty(group))
{
if (!StringUtils.In(nodeInfo.GroupNameCollection, group))
{
continue;
}
}
if (!string.IsNullOrEmpty(groupNot))
{
if (StringUtils.In(nodeInfo.GroupNameCollection, groupNot))
{
continue;
}
}
if (!string.IsNullOrEmpty(contentModelPluginId))
{
if (!StringUtils.EqualsIgnoreCase(nodeInfo.ContentModelPluginId, contentModelPluginId))
{
continue;
}
}
filteredChannelInfoList.Add(nodeInfo);
}
return filteredChannelInfoList.OrderBy(c => c.Taxis).Select(channelInfoInList => channelInfoInList.Id).ToList();
}
public static bool IsExists(int siteId, int channelId)
{
var nodeInfo = GetChannelInfo(siteId, channelId);
return nodeInfo != null;
}
public static bool IsExists(int channelId)
{
var list = SiteManager.GetSiteIdList();
foreach (var siteId in list)
{
var nodeInfo = GetChannelInfo(siteId, channelId);
if (nodeInfo != null) return true;
}
return false;
}
public static int GetChannelIdByParentsCount(int siteId, int channelId, int parentsCount)
{
if (parentsCount == 0) return siteId;
if (channelId == 0 || channelId == siteId) return siteId;
var nodeInfo = GetChannelInfo(siteId, channelId);
if (nodeInfo != null)
{
return nodeInfo.ParentsCount == parentsCount ? nodeInfo.Id : GetChannelIdByParentsCount(siteId, nodeInfo.ParentId, parentsCount);
}
return siteId;
}
public static string GetTableName(SiteInfo siteInfo, int channelId)
{
return GetTableName(siteInfo, GetChannelInfo(siteInfo.Id, channelId));
}
public static string GetTableName(SiteInfo siteInfo, ChannelInfo channelInfo)
{
return channelInfo != null ? GetTableName(siteInfo, channelInfo.ContentModelPluginId) : string.Empty;
}
public static string GetTableName(SiteInfo siteInfo, string pluginId)
{
var tableName = siteInfo.TableName;
if (string.IsNullOrEmpty(pluginId)) return tableName;
var contentTable = PluginContentTableManager.GetTableName(pluginId);
if (!string.IsNullOrEmpty(contentTable))
{
tableName = contentTable;
}
return tableName;
}
//public static ETableStyle GetTableStyle(SiteInfo siteInfo, int channelId)
//{
// return GetTableStyle(siteInfo, GetChannelInfo(siteInfo.Id, channelId));
//}
//public static ETableStyle GetTableStyle(SiteInfo siteInfo, NodeInfo nodeInfo)
//{
// var tableStyle = ETableStyle.BackgroundContent;
// if (string.IsNullOrEmpty(nodeInfo.ContentModelPluginId)) return tableStyle;
// var contentTable = PluginCache.GetEnabledPluginMetadata<IContentModel>(nodeInfo.ContentModelPluginId);
// if (contentTable != null)
// {
// tableStyle = ETableStyle.Custom;
// }
// return tableStyle;
//}
public static bool IsContentModelPlugin(SiteInfo siteInfo, ChannelInfo nodeInfo)
{
if (string.IsNullOrEmpty(nodeInfo.ContentModelPluginId)) return false;
var contentTable = PluginContentTableManager.GetTableName(nodeInfo.ContentModelPluginId);
return !string.IsNullOrEmpty(contentTable);
}
public static string GetNodeTreeLastImageHtml(SiteInfo siteInfo, ChannelInfo nodeInfo)
{
var imageHtml = string.Empty;
if (!string.IsNullOrEmpty(nodeInfo.ContentModelPluginId) || !string.IsNullOrEmpty(nodeInfo.ContentRelatedPluginIds))
{
var list = PluginContentManager.GetContentPlugins(nodeInfo, true);
if (list != null && list.Count > 0)
{
imageHtml += @"<i class=""ion-cube"" style=""font-size: 15px;vertical-align: baseline;""></i> ";
}
}
return imageHtml;
}
public static DateTime GetAddDate(int siteId, int channelId)
{
var retval = DateTime.MinValue;
var nodeInfo = GetChannelInfo(siteId, channelId);
if (nodeInfo != null)
{
retval = nodeInfo.AddDate;
}
return retval;
}
public static int GetParentId(int siteId, int channelId)
{
var retval = 0;
var nodeInfo = GetChannelInfo(siteId, channelId);
if (nodeInfo != null)
{
retval = nodeInfo.ParentId;
}
return retval;
}
public static string GetParentsPath(int siteId, int channelId)
{
var retval = string.Empty;
var nodeInfo = GetChannelInfo(siteId, channelId);
if (nodeInfo != null)
{
retval = nodeInfo.ParentsPath;
}
return retval;
}
public static int GetTopLevel(int siteId, int channelId)
{
var parentsPath = GetParentsPath(siteId, channelId);
return string.IsNullOrEmpty(parentsPath) ? 0 : parentsPath.Split(',').Length;
}
public static string GetChannelName(int siteId, int channelId)
{
var retval = string.Empty;
var nodeInfo = GetChannelInfo(siteId, channelId);
if (nodeInfo != null)
{
retval = nodeInfo.ChannelName;
}
return retval;
}
public static string GetChannelNameNavigation(int siteId, int channelId)
{
var nodeNameList = new List<string>();
if (channelId == 0) channelId = siteId;
if (channelId == siteId)
{
var nodeInfo = GetChannelInfo(siteId, siteId);
return nodeInfo.ChannelName;
}
var parentsPath = GetParentsPath(siteId, channelId);
var channelIdList = new List<int>();
if (!string.IsNullOrEmpty(parentsPath))
{
channelIdList = TranslateUtils.StringCollectionToIntList(parentsPath);
}
channelIdList.Add(channelId);
channelIdList.Remove(siteId);
foreach (var theChannelId in channelIdList)
{
var nodeInfo = GetChannelInfo(siteId, theChannelId);
if (nodeInfo != null)
{
nodeNameList.Add(nodeInfo.ChannelName);
}
}
return TranslateUtils.ObjectCollectionToString(nodeNameList, " > ");
}
public static void AddListItems(ListItemCollection listItemCollection, SiteInfo siteInfo, bool isSeeOwning, bool isShowContentNum, PermissionsImpl permissionsImpl)
{
var list = GetChannelIdList(siteInfo.Id);
var nodeCount = list.Count;
var isLastNodeArray = new bool[nodeCount];
foreach (var channelId in list)
{
var enabled = true;
if (isSeeOwning)
{
enabled = permissionsImpl.IsOwningChannelId(channelId);
if (!enabled)
{
if (!permissionsImpl.IsDescendantOwningChannelId(siteInfo.Id, channelId)) continue;
}
}
var nodeInfo = GetChannelInfo(siteInfo.Id, channelId);
var listitem = new ListItem(GetSelectText(siteInfo, nodeInfo, isLastNodeArray, isShowContentNum), nodeInfo.Id.ToString());
if (!enabled)
{
listitem.Attributes.Add("style", "color:gray;");
}
listItemCollection.Add(listitem);
}
}
public static void AddListItems(ListItemCollection listItemCollection, SiteInfo siteInfo, bool isSeeOwning, bool isShowContentNum, string contentModelId, PermissionsImpl permissionsImpl)
{
var list = GetChannelIdList(siteInfo.Id);
var nodeCount = list.Count;
var isLastNodeArray = new bool[nodeCount];
foreach (var channelId in list)
{
var enabled = true;
if (isSeeOwning)
{
enabled = permissionsImpl.IsOwningChannelId(channelId);
if (!enabled)
{
if (!permissionsImpl.IsDescendantOwningChannelId(siteInfo.Id, channelId)) continue;
}
}
var nodeInfo = GetChannelInfo(siteInfo.Id, channelId);
var listitem = new ListItem(GetSelectText(siteInfo, nodeInfo, isLastNodeArray, isShowContentNum), nodeInfo.Id.ToString());
if (!enabled)
{
listitem.Attributes.Add("style", "color:gray;");
}
if (!StringUtils.EqualsIgnoreCase(nodeInfo.ContentModelPluginId, contentModelId))
{
listitem.Attributes.Add("disabled", "disabled");
}
listItemCollection.Add(listitem);
}
}
public static void AddListItemsForAddContent(ListItemCollection listItemCollection, SiteInfo siteInfo, bool isSeeOwning, PermissionsImpl permissionsImpl)
{
var list = GetChannelIdList(siteInfo.Id);
var nodeCount = list.Count;
var isLastNodeArray = new bool[nodeCount];
foreach (var channelId in list)
{
var enabled = true;
if (isSeeOwning)
{
enabled = permissionsImpl.IsOwningChannelId(channelId);
}
var nodeInfo = GetChannelInfo(siteInfo.Id, channelId);
if (enabled)
{
if (nodeInfo.Additional.IsContentAddable == false) enabled = false;
}
if (!enabled)
{
continue;
}
var listitem = new ListItem(GetSelectText(siteInfo, nodeInfo, isLastNodeArray, true), nodeInfo.Id.ToString());
listItemCollection.Add(listitem);
}
}
/// <summary>
/// 得到栏目,并且不对(栏目是否可添加内容)进行判断
/// 提供给触发器页面使用
/// 使用场景:其他栏目的内容变动之后,设置某个栏目(此栏目不能添加内容)触发生成
/// </summary>
public static void AddListItemsForCreateChannel(ListItemCollection listItemCollection, SiteInfo siteInfo, bool isSeeOwning, PermissionsImpl permissionsImpl)
{
var list = GetChannelIdList(siteInfo.Id);
var nodeCount = list.Count;
var isLastNodeArray = new bool[nodeCount];
foreach (var channelId in list)
{
var enabled = true;
if (isSeeOwning)
{
enabled = permissionsImpl.IsOwningChannelId(channelId);
}
var nodeInfo = GetChannelInfo(siteInfo.Id, channelId);
if (!enabled)
{
continue;
}
var listitem = new ListItem(GetSelectText(siteInfo, nodeInfo, isLastNodeArray, true), nodeInfo.Id.ToString());
listItemCollection.Add(listitem);
}
}
public static string GetSelectText(SiteInfo siteInfo, ChannelInfo channelInfo, bool[] isLastNodeArray, bool isShowContentNum)
{
var retval = string.Empty;
if (channelInfo.Id == channelInfo.SiteId)
{
channelInfo.IsLastNode = true;
}
if (channelInfo.IsLastNode == false)
{
isLastNodeArray[channelInfo.ParentsCount] = false;
}
else
{
isLastNodeArray[channelInfo.ParentsCount] = true;
}
for (var i = 0; i < channelInfo.ParentsCount; i++)
{
retval = string.Concat(retval, isLastNodeArray[i] ? " " : "│");
}
retval = string.Concat(retval, channelInfo.IsLastNode ? "└" : "├");
retval = string.Concat(retval, channelInfo.ChannelName);
if (isShowContentNum)
{
var count = ContentManager.GetCount(siteInfo, channelInfo);
retval = string.Concat(retval, " (", count, ")");
}
return retval;
}
public static string GetContentAttributesOfDisplay(int siteId, int channelId)
{
var nodeInfo = GetChannelInfo(siteId, channelId);
if (nodeInfo == null) return string.Empty;
if (siteId != channelId && string.IsNullOrEmpty(nodeInfo.Additional.ContentAttributesOfDisplay))
{
return GetContentAttributesOfDisplay(siteId, nodeInfo.ParentId);
}
return nodeInfo.Additional.ContentAttributesOfDisplay;
}
public static List<InputListItem> GetContentsColumns(SiteInfo siteInfo, ChannelInfo channelInfo, bool includeAll)
{
var items = new List<InputListItem>();
var attributesOfDisplay = TranslateUtils.StringCollectionToStringCollection(channelInfo.Additional.ContentAttributesOfDisplay);
var pluginIds = PluginContentManager.GetContentPluginIds(channelInfo);
var pluginColumns = PluginContentManager.GetContentColumns(pluginIds);
var styleInfoList = ContentUtility.GetAllTableStyleInfoList(TableStyleManager.GetContentStyleInfoList(siteInfo, channelInfo));
styleInfoList.Insert(0, new TableStyleInfo
{
AttributeName = ContentAttribute.Sequence,
DisplayName = "序号"
});
foreach (var styleInfo in styleInfoList)
{
if (styleInfo.InputType == InputType.TextEditor) continue;
var listitem = new InputListItem
{
Text = styleInfo.DisplayName,
Value = styleInfo.AttributeName
};
if (styleInfo.AttributeName == ContentAttribute.Title)
{
listitem.Selected = true;
}
else
{
if (attributesOfDisplay.Contains(styleInfo.AttributeName))
{
listitem.Selected = true;
}
}
if (includeAll || listitem.Selected)
{
items.Add(listitem);
}
}
if (pluginColumns != null)
{
foreach (var pluginId in pluginColumns.Keys)
{
var contentColumns = pluginColumns[pluginId];
if (contentColumns == null || contentColumns.Count == 0) continue;
foreach (var columnName in contentColumns.Keys)
{
var attributeName = $"{pluginId}:{columnName}";
var listitem = new InputListItem
{
Text = $"{columnName}({pluginId})",
Value = attributeName
};
if (attributesOfDisplay.Contains(attributeName))
{
listitem.Selected = true;
}
if (includeAll || listitem.Selected)
{
items.Add(listitem);
}
}
}
}
return items;
}
public static bool IsAncestorOrSelf(int siteId, int parentId, int childId)
{
if (parentId == childId)
{
return true;
}
var nodeInfo = GetChannelInfo(siteId, childId);
if (nodeInfo == null)
{
return false;
}
if (StringUtils.In(nodeInfo.ParentsPath, parentId.ToString()))
{
return true;
}
return false;
}
public static List<KeyValuePair<int, string>> GetChannels(int siteId, PermissionsImpl permissionsImpl, params string[] channelPermissions)
{
var options = new List<KeyValuePair<int, string>>();
var list = GetChannelIdList(siteId);
foreach (var channelId in list)
{
var enabled = permissionsImpl.HasChannelPermissions(siteId, channelId, channelPermissions);
var channelInfo = GetChannelInfo(siteId, channelId);
if (enabled && channelPermissions.Contains(ConfigManager.ChannelPermissions.ContentAdd))
{
if (channelInfo.Additional.IsContentAddable == false) enabled = false;
}
if (enabled)
{
var tuple = new KeyValuePair<int, string>(channelId,
GetChannelNameNavigation(siteId, channelId));
options.Add(tuple);
}
}
return options;
}
public static bool IsCreatable(SiteInfo siteInfo, ChannelInfo channelInfo)
{
if (siteInfo == null || channelInfo == null) return false;
if (!channelInfo.Additional.IsChannelCreatable || !string.IsNullOrEmpty(channelInfo.LinkUrl)) return false;
var isCreatable = false;
var linkType = ELinkTypeUtils.GetEnumType(channelInfo.LinkType);
if (linkType == ELinkType.None)
{
isCreatable = true;
}
else if (linkType == ELinkType.NoLinkIfContentNotExists)
{
var count = ContentManager.GetCount(siteInfo, channelInfo, true);
isCreatable = count != 0;
}
else if (linkType == ELinkType.LinkToOnlyOneContent)
{
var count = ContentManager.GetCount(siteInfo, channelInfo, true);
isCreatable = count != 1;
}
else if (linkType == ELinkType.NoLinkIfContentNotExistsAndLinkToOnlyOneContent)
{
var count = ContentManager.GetCount(siteInfo, channelInfo, true);
if (count != 0 && count != 1)
{
isCreatable = true;
}
}
else if (linkType == ELinkType.LinkToFirstContent)
{
var count = ContentManager.GetCount(siteInfo, channelInfo, true);
isCreatable = count < 1;
}
else if (linkType == ELinkType.NoLinkIfChannelNotExists)
{
isCreatable = channelInfo.ChildrenCount != 0;
}
else if (linkType == ELinkType.LinkToLastAddChannel)
{
isCreatable = channelInfo.ChildrenCount <= 0;
}
else if (linkType == ELinkType.LinkToFirstChannel)
{
isCreatable = channelInfo.ChildrenCount <= 0;
}
return isCreatable;
}
}
}