PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/CMSWebParts/Forums/Syndication/ForumPostsRSSFeed.ascx.cs

https://bitbucket.org/kudutest/kenticogit
C# | 560 lines | 393 code | 76 blank | 91 comment | 3 complexity | ad12e28cab46280ae6d1076229883df2 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Web;
  4. using System.Web.UI;
  5. using System.Web.UI.WebControls;
  6. using CMS.PortalControls;
  7. using CMS.GlobalHelper;
  8. using CMS.CMSHelper;
  9. public partial class CMSWebParts_Forums_Syndication_ForumPostsRSSFeed : CMSAbstractWebPart
  10. {
  11. #region "RSS Feed Properties"
  12. /// <summary>
  13. /// Querystring key which is used for RSS feed identification on a page with multiple RSS feeds.
  14. /// </summary>
  15. public string QueryStringKey
  16. {
  17. get
  18. {
  19. return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("QueryStringKey"), null), rssFeed.QueryStringKey);
  20. }
  21. set
  22. {
  23. SetValue("QueryStringKey", value);
  24. rssFeed.QueryStringKey = value;
  25. }
  26. }
  27. /// <summary>
  28. /// Feed name to identify this feed on a page with multiple feeds. If the value is empty the GUID of the web part instance will be used by default.
  29. /// </summary>
  30. public string FeedName
  31. {
  32. get
  33. {
  34. return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("FeedName"), null), GetIdentificator());
  35. }
  36. set
  37. {
  38. string valueToSet = value;
  39. // If no feed name was specified
  40. if (string.IsNullOrEmpty(valueToSet))
  41. {
  42. // Set default name
  43. valueToSet = GetIdentificator();
  44. }
  45. SetValue("FeedName", valueToSet);
  46. rssFeed.FeedName = valueToSet;
  47. }
  48. }
  49. /// <summary>
  50. /// Text for the feed link.
  51. /// </summary>
  52. public string LinkText
  53. {
  54. get
  55. {
  56. return ValidationHelper.GetString(GetValue("LinkText"), string.Empty);
  57. }
  58. set
  59. {
  60. SetValue("LinkText", value);
  61. rssFeed.LinkText = value;
  62. }
  63. }
  64. /// <summary>
  65. /// Icon which will be displayed in the feed link.
  66. /// </summary>
  67. public string LinkIcon
  68. {
  69. get
  70. {
  71. return ValidationHelper.GetString(GetValue("LinkIcon"), string.Empty);
  72. }
  73. set
  74. {
  75. SetValue("LinkIcon", value);
  76. rssFeed.LinkIcon = value;
  77. }
  78. }
  79. /// <summary>
  80. /// Indicates if the RSS feed is automatically discovered by the browser.
  81. /// </summary>
  82. public bool EnableRSSAutodiscovery
  83. {
  84. get
  85. {
  86. return ValidationHelper.GetBoolean(GetValue("EnableRSSAutodiscovery"), true);
  87. }
  88. set
  89. {
  90. SetValue("EnableRSSAutodiscovery", value);
  91. rssFeed.EnableAutodiscovery = value;
  92. }
  93. }
  94. #endregion
  95. #region "RSS Repeater properties"
  96. /// <summary>
  97. /// URL title of the feed.
  98. /// </summary>
  99. public string FeedTitle
  100. {
  101. get
  102. {
  103. return ValidationHelper.GetString(GetValue("FeedTitle"), string.Empty);
  104. }
  105. set
  106. {
  107. SetValue("FeedTitle", value);
  108. rssFeed.FeedTitle = value;
  109. }
  110. }
  111. /// <summary>
  112. /// Description of the feed.
  113. /// </summary>
  114. public string FeedDescription
  115. {
  116. get
  117. {
  118. return ValidationHelper.GetString(GetValue("FeedDescription"), string.Empty);
  119. }
  120. set
  121. {
  122. SetValue("FeedDescription", value);
  123. rssFeed.FeedDescription = value;
  124. }
  125. }
  126. /// <summary>
  127. /// Language of the feed. If the value is empty the content culture will be used.
  128. /// </summary>
  129. public string FeedLanguage
  130. {
  131. get
  132. {
  133. string cultureCode = ValidationHelper.GetString(GetValue("FeedLanguage"), null);
  134. if (string.IsNullOrEmpty(cultureCode))
  135. {
  136. cultureCode = CMSContext.PreferredCultureCode;
  137. }
  138. return cultureCode;
  139. }
  140. set
  141. {
  142. SetValue("FeedLanguage", value);
  143. rssFeed.FeedLanguage = value;
  144. }
  145. }
  146. /// <summary>
  147. /// Custom feed header XML which is generated before feed items. If the value is empty default header for RSS feed is generated.
  148. /// </summary>
  149. public string HeaderXML
  150. {
  151. get
  152. {
  153. return ValidationHelper.GetString(GetValue("HeaderXML"), null);
  154. }
  155. set
  156. {
  157. SetValue("HeaderXML", value);
  158. rssFeed.HeaderXML = value;
  159. }
  160. }
  161. /// <summary>
  162. /// Custom feed footer XML which is generated after feed items. If the value is empty default footer for RSS feed is generated.
  163. /// </summary>
  164. public string FooterXML
  165. {
  166. get
  167. {
  168. return ValidationHelper.GetString(GetValue("FooterXML"), null);
  169. }
  170. set
  171. {
  172. SetValue("FooterXML", value);
  173. rssFeed.FooterXML = value;
  174. }
  175. }
  176. #endregion
  177. #region "Transformation properties"
  178. /// <summary>
  179. /// Gets or sets ItemTemplate property.
  180. /// </summary>
  181. public string TransformationName
  182. {
  183. get
  184. {
  185. return ValidationHelper.GetString(GetValue("TransformationName"), string.Empty);
  186. }
  187. set
  188. {
  189. SetValue("TransformationName", value);
  190. rssFeed.TransformationName = value;
  191. }
  192. }
  193. #endregion
  194. #region "Datasource properties"
  195. /// <summary>
  196. /// Gets or sets the web service URL.
  197. /// </summary>
  198. public string SiteName
  199. {
  200. get
  201. {
  202. return DataHelper.GetNotEmpty(this.GetValue("SiteName"), CMSContext.CurrentSiteName);
  203. }
  204. set
  205. {
  206. this.SetValue("SiteName", value);
  207. srcElem.SiteName = value;
  208. }
  209. }
  210. /// <summary>
  211. /// Gets or sets forum name for which blog posts should be obtained.
  212. /// </summary>
  213. public string ForumName
  214. {
  215. get
  216. {
  217. return ValidationHelper.GetString(this.GetValue("ForumName"), "");
  218. }
  219. set
  220. {
  221. this.SetValue("ForumName", value);
  222. srcElem.ForumName = value;
  223. }
  224. }
  225. /// <summary>
  226. /// Gets or sets Select only approved property.
  227. /// </summary>
  228. public bool SelectOnlyApproved
  229. {
  230. get
  231. {
  232. return ValidationHelper.GetBoolean(this.GetValue("SelectOnlyApproved"), true);
  233. }
  234. set
  235. {
  236. this.SetValue("SelectOnlyApproved", value);
  237. srcElem.SelectOnlyApproved = value;
  238. }
  239. }
  240. /// <summary>
  241. /// Gets or sets Check permissions property.
  242. /// </summary>
  243. public bool CheckPermissions
  244. {
  245. get
  246. {
  247. return ValidationHelper.GetBoolean(this.GetValue("CheckPermissions"), true);
  248. }
  249. set
  250. {
  251. this.SetValue("CheckPermissions", value);
  252. srcElem.CheckPermissions = value;
  253. }
  254. }
  255. /// <summary>
  256. /// Gets or sets the ORDER BY clause.
  257. /// </summary>
  258. public string OrderBy
  259. {
  260. get
  261. {
  262. return ValidationHelper.GetString(this.GetValue("OrderBy"), "");
  263. }
  264. set
  265. {
  266. this.SetValue("OrderBy", value);
  267. this.srcElem.OrderBy = value;
  268. }
  269. }
  270. /// <summary>
  271. /// Gets or sets the WHERE condition.
  272. /// </summary>
  273. public string WhereCondition
  274. {
  275. get
  276. {
  277. return ValidationHelper.GetString(this.GetValue("WhereCondition"), "");
  278. }
  279. set
  280. {
  281. this.SetValue("WhereCondition", value);
  282. this.srcElem.WhereCondition = value;
  283. }
  284. }
  285. /// <summary>
  286. /// Gets or sets the number which indicates how many documents should be displayed.
  287. /// </summary>
  288. public int SelectTopN
  289. {
  290. get
  291. {
  292. return ValidationHelper.GetInteger(this.GetValue("SelectTopN"), 0);
  293. }
  294. set
  295. {
  296. this.SetValue("SelectTopN", value);
  297. this.srcElem.TopN = value;
  298. }
  299. }
  300. /// <summary>
  301. /// Gets or sets the source filter name.
  302. /// </summary>
  303. public string FilterName
  304. {
  305. get
  306. {
  307. return ValidationHelper.GetString(this.GetValue("FilterName"), "");
  308. }
  309. set
  310. {
  311. this.SetValue("FilterName", value);
  312. srcElem.SourceFilterName = value;
  313. }
  314. }
  315. /// <summary>
  316. /// Gest or sets selected columns.
  317. /// </summary>
  318. public string Columns
  319. {
  320. get
  321. {
  322. return ValidationHelper.GetString(this.GetValue("Columns"), "");
  323. }
  324. set
  325. {
  326. this.SetValue("Columns", value);
  327. srcElem.SelectedColumns = value;
  328. }
  329. }
  330. /// <summary>
  331. /// Indicates if group posts should be included.
  332. /// </summary>
  333. public bool ShowGroupPosts
  334. {
  335. get
  336. {
  337. return ValidationHelper.GetBoolean(this.GetValue("ShowGroupPosts"), false);
  338. }
  339. set
  340. {
  341. this.SetValue("ShowGroupPosts", value);
  342. srcElem.ShowGroupPosts = value;
  343. }
  344. }
  345. #endregion
  346. #region "Cache properties"
  347. /// <summary>
  348. /// Gest or sets the cache item name.
  349. /// </summary>
  350. public override string CacheItemName
  351. {
  352. get
  353. {
  354. return base.CacheItemName;
  355. }
  356. set
  357. {
  358. base.CacheItemName = value;
  359. this.srcElem.CacheItemName = value;
  360. this.rssFeed.CacheItemName = value;
  361. }
  362. }
  363. /// <summary>
  364. /// Cache dependencies, each cache dependency on a new line.
  365. /// </summary>
  366. public override string CacheDependencies
  367. {
  368. get
  369. {
  370. return ValidationHelper.GetString(base.CacheDependencies, this.srcElem.CacheDependencies);
  371. }
  372. set
  373. {
  374. base.CacheDependencies = value;
  375. this.srcElem.CacheDependencies = value;
  376. this.rssFeed.CacheDependencies = value;
  377. }
  378. }
  379. /// <summary>
  380. /// Gets or sets the cache minutes.
  381. /// </summary>
  382. public override int CacheMinutes
  383. {
  384. get
  385. {
  386. return base.CacheMinutes;
  387. }
  388. set
  389. {
  390. base.CacheMinutes = value;
  391. this.srcElem.CacheMinutes = value;
  392. this.rssFeed.CacheMinutes = value;
  393. }
  394. }
  395. #endregion
  396. #region "Stop processing"
  397. /// <summary>
  398. /// Returns true if the control processing should be stopped.
  399. /// </summary>
  400. public override bool StopProcessing
  401. {
  402. get
  403. {
  404. return base.StopProcessing;
  405. }
  406. set
  407. {
  408. base.StopProcessing = value;
  409. rssFeed.StopProcessing = value;
  410. srcElem.StopProcessing = value;
  411. }
  412. }
  413. #endregion
  414. #region "Overidden methods"
  415. /// <summary>
  416. /// Content loaded event handler.
  417. /// </summary>
  418. public override void OnContentLoaded()
  419. {
  420. base.OnContentLoaded();
  421. SetupControl();
  422. }
  423. /// <summary>
  424. /// Reloads data.
  425. /// </summary>
  426. public override void ReloadData()
  427. {
  428. base.ReloadData();
  429. SetupControl();
  430. }
  431. #endregion
  432. #region "Setup control"
  433. /// <summary>
  434. /// Initializes the control properties.
  435. /// </summary>
  436. protected void SetupControl()
  437. {
  438. if (StopProcessing)
  439. {
  440. rssFeed.StopProcessing = true;
  441. srcElem.StopProcessing = true;
  442. }
  443. else
  444. {
  445. string feedCodeName = URLHelper.GetSafeUrlPart(FeedName, SiteName);
  446. // RSS feed properties
  447. rssFeed.FeedName = feedCodeName;
  448. rssFeed.FeedLink = URLHelper.GetAbsoluteUrl(URLHelper.AddParameterToUrl(URLHelper.CurrentURL, QueryStringKey, feedCodeName));
  449. rssFeed.LinkText = LinkText;
  450. rssFeed.LinkIcon = LinkIcon;
  451. rssFeed.FeedTitle = FeedTitle;
  452. rssFeed.FeedDescription = FeedDescription;
  453. rssFeed.FeedLanguage = FeedLanguage;
  454. rssFeed.EnableAutodiscovery = EnableRSSAutodiscovery;
  455. rssFeed.QueryStringKey = QueryStringKey;
  456. rssFeed.HeaderXML = HeaderXML;
  457. rssFeed.FooterXML = FooterXML;
  458. // Datasource properties
  459. srcElem.FilterName = ValidationHelper.GetString(this.GetValue("WebPartControlID"), this.ClientID);
  460. srcElem.SiteName = SiteName;
  461. srcElem.ForumName = ForumName;
  462. srcElem.OrderBy = OrderBy;
  463. srcElem.WhereCondition = WhereCondition;
  464. srcElem.TopN = SelectTopN;
  465. srcElem.SourceFilterName = FilterName;
  466. srcElem.SelectOnlyApproved = SelectOnlyApproved;
  467. srcElem.CheckPermissions = CheckPermissions;
  468. srcElem.SelectedColumns = Columns;
  469. srcElem.ShowGroupPosts = ShowGroupPosts;
  470. // Cache properties
  471. rssFeed.CacheItemName = CacheItemName;
  472. rssFeed.CacheDependencies = CacheDependencies;
  473. rssFeed.CacheMinutes = CacheMinutes;
  474. srcElem.CacheItemName = CacheItemName;
  475. srcElem.CacheDependencies = CacheDependencies;
  476. srcElem.CacheMinutes = CacheMinutes;
  477. // Transformation properties
  478. rssFeed.TransformationName = TransformationName;
  479. // Set datasource
  480. rssFeed.DataSourceControl = srcElem;
  481. }
  482. }
  483. #endregion
  484. }