⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 articlelistbase.ascx.vb

📁 Module articles for Dot Net Nuke 3.x.x , 4.x.x
💻 VB
字号:
Imports Microsoft.VisualBasic
Imports System.Collections
Imports System.Data
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports DotNetNuke.Security
Imports DotNetNuke.Services.Localization

Namespace EfficionConsulting.Articles
Public MustInherit Class ArticleListBase
	Inherits DotNetNuke.Entities.Modules.PortalModuleBase

#Region "Controls"
	Protected WithEvents lblMessage As System.Web.UI.WebControls.Label
	Protected WithEvents lstArticles As System.Web.UI.WebControls.DataList
	Public WithEvents ctlPagingControl As DotNetNuke.UI.WebControls.PagingControl
#End Region

#Region "Private Members"
	Protected MaxImageWidth as String = "200"
	Protected ImagePosition As String = "Left"
	
	Protected bAllowComments As Boolean = False
	Protected bShowCategories As Boolean
	Protected bShowReadMore As Boolean = True
	Protected bMoreArticles As Boolean = False
	Protected nImageAlignment As Integer
	
	Protected CategoryList as String = ""
	Protected FilterByCategory As Boolean = False
	Protected SiteWide As Boolean = False
	Protected Featured As Boolean = False
	Protected SortField As String = ""
	Protected ArticlesPerPage As Integer = 10
	Protected DateRange As Integer = -1
	Protected PublishDate As DateTime
	Protected ExpireDate As DateTime
	Protected IgnoreExpired As Boolean = False

	Protected SearchTerm As String = String.Empty
	Protected AutoBind As Boolean = True

	Protected CustomSelect As String = ""
	Protected bShowAuthOnly As Boolean = True
	Protected bRequireApproval As Boolean = True
	'Protected bShowCategory As Boolean = False
	Protected bShowImage As Boolean = True
	Protected bShowDescription As Boolean = True

	Private CurrentPage As Integer
	Private TotalArticles As Integer
	
#End Region
	
	Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		try
			'TODO: 3.3- Improve the integration of Categories. Consider using LoadControl to load the Edit page to enable adding categories from Articles.
			'TODO: 3.3- Add option to display article details on separate page (no other controls) or same page.
			'TODO: 3.3- Consider Details Page Templates
			'TODO: 3.3- Look at using URLTracking and the URL Control
			'TODO: 3.3- Make both searches search the Details field.
			'TODO: Add option for, "Display Description on Details page".
			'TODO: Consider additional Meta-Tags (description, title) and put in separate section
			'TODO: Only let admins or creators edit an article
			'TODO: Add Import Announcements feature
			'TODO: Consider making search go to an individual item (details) rather than page with list
			'TODO: Make Categories optional rather than required
			'TODO: Improve Approval mechanism: add reject, e-mail notification, and a filter for viewing Articles awaiting approval.
			'TODO: Make it possible to view a list of categories and when a user clicks on a Category it will show all articles in that category.

			'if settings have been initialized use them, otherwise the defaults will be used
			if not Settings("ArticlesPerPage") = 0 then
				FilterByCategory = Settings("FilterByCategory") = "True"
				if FilterByCategory then
					CategoryList = Settings("CategoryID")
				End If

				ctlPagingControl.Visible = (Settings("HidePaging") <> "True")
				CustomSelect = Settings("CustomSelect")
				SiteWide = Settings("SiteWide")
				Featured = Settings("Featured")
				If Convert.ToString(Settings("SortField")) = "" Then
					SortField = "CreatedDate"
				Else
					SortField = Settings("SortField")
				End If
				bRequireApproval = Settings("RequireApproval")
				ArticlesPerPage = Settings("ArticlesPerPage")
				DateRange = Settings("DateRange")

				If (not bRequireApproval) OR (PortalSecurity.IsInRoles(PortalSettings.AdministratorRoleId.ToString) = True Or PortalSecurity.IsInRoles(PortalSettings.ActiveTab.AdministratorRoles.ToString) = True) Then
					bShowAuthOnly = False
				End If

			End If

			SearchTerm = Request("SearchTerm")

			If (Request("ShowAll") = "True") Then
				CategoryList = ""
				SiteWide = "True"
				Featured = "False"
				DateRange = "-1"
				IgnoreExpired = True
			End if

			If (Request("CategoryID") <> "") Then
				CategoryList = Int32.Parse(Request("CategoryID"))
				Me.ModuleConfiguration.ModuleTitle = "Viewing  Category"
			End If

			CurrentPage = 1
			If Request.QueryString("CurrentPage") <> "" then
				CurrentPage = CType(Request.QueryString("CurrentPage"), Integer)
			End If
			
			If SearchTerm <> "" Then
				ctlPagingControl.QuerystringParams = "&SearchTerm=" & SearchTerm
			End If
			ctlPagingControl.PageSize = ArticlesPerPage
			ctlPagingControl.CurrentPage = CurrentPage
			ctlPagingControl.TabID = TabId

			Dim ds as ArrayList = GetDataPage()
			lstArticles.DataSource = ds
			lstArticles.DataBind()

		Catch exc as Exception
			ProcessModuleLoadException("Error Loading the Article List:", me, exc, true)
		End Try

	End Sub

	Private Function GetDataPage() As ArrayList
		'Returns a subset of the data based on page size and current page
		
		'TODO: consider storing the list in cache or ViewState
		Dim objArticleList as ArrayList = GetData()

		TotalArticles = objArticleList.Count
		
		ctlPagingControl.TotalRecords  = TotalArticles

		If TotalArticles > ArticlesPerPage Then
			Dim FromRecord, ToRecord As Integer
			FromRecord = (CurrentPage - 1) * ArticlesPerPage
			ToRecord = (CurrentPage * ArticlesPerPage) -1	
			
			If ToRecord > (objArticleList.Count - 1) Then
				ToRecord = objArticleList.Count - 1 
			End If
			Dim counter As Integer = FromRecord
			Dim articleSubset as new ArrayList
			While counter <= ToRecord
				articleSubset.Add(objArticleList(counter))
				counter += 1
			End While
	
			Return articleSubset
		Else
			ctlPagingControl.Visible = False
			Return objArticleList
		End If
	End Function

	Private Function GetData() As ArrayList		
		
		Try
			Dim objArticles As New ArticleController()
			Dim arArticles As Arraylist
			Dim IgnorePublishDate as Boolean = IsEditable()
			If CustomSelect <> "" Then
				arArticles = objArticles.GetArticles(CustomSelect)
			Else
				If SearchTerm <> "" then
					'NOTE: Search is always SiteWide
					arArticles = objArticles.SearchArticles(PortalId, SearchTerm, SortField)
				Else
					If SiteWide Then
						'Passing -1 as the ModuleID will cause the SP to ignore ModuleID
						arArticles = objArticles.GetArticles(PortalId, -1, CategoryList, ArticlesPerPage, DateRange, bShowAuthOnly, Featured, IgnorePublishDate, IgnoreExpired, SortField)
					Else
						arArticles = objArticles.GetArticles(PortalId, ModuleId, CategoryList, ArticlesPerPage, DateRange, bShowAuthOnly, Featured, IgnorePublishDate, IgnoreExpired, SortField)
					End If
				End If
			End If

			Return arArticles
		Catch ex As Exception
			ProcessModuleLoadException(Localization.GetString("ArticleBindingError.Text", LocalResourceFile), me, ex, true)
		End Try
		
	End Function
	
	Protected Sub Item_Bound(sender As Object, e As DataListItemEventArgs)
		
		' item or alternate item
		If e.Item.ItemType = System.Web.UI.WebControls.ListItemType.Item or e.Item.ItemType = System.Web.UI.WebControls.ListItemType.AlternatingItem Then
			ShowArticles(e)		
			ShowComments(e)
		End If 
		
		' footer
		If e.Item.ItemType = System.Web.UI.WebControls.ListItemType.Footer Then
			ShowPagination(e)
			ShowMoreArticles(e)
		End If
	
	End Sub

	Private Sub ShowArticles(e As DatalistItemEventArgs)
		'Set the ReadMore and Title Links
		Dim hypReadMore As Hyperlink = CType(e.Item.FindControl("lnkReadMore"), System.Web.UI.WebControls.Hyperlink)
		'for templates that don't include hypReadMore
		If hypReadMore Is Nothing Then
			hypReadMore = new HyperLink
		End If
		Dim hypTitle as Hyperlink = CType(e.Item.FindControl("titleLink"), Hyperlink)
		'for templates that don't include hypTitle
		If hypTitle Is Nothing Then
			hypTitle = new HyperLink
		End If

		Dim article as String = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "article"))
		If article = "" Or article = "nolink:" Then
			'do nothing
		ElseIf article.StartsWith("external:")
			hypReadMore.NavigateUrl = article.Substring(9)
			hypReadMore.Target = "_new"
			hypTitle.NavigateUrl = article.Substring(9)
			hypTitle.Target = "_new"
			hypReadMore.Visible = bShowReadMore
		ElseIf article.StartsWith("internal:")
			hypReadMore.NavigateUrl = NavigateURL(CType(article.Substring(9), Integer))
			hypTitle.NavigateUrl = NavigateURL(CType(article.Substring(9), Integer))
			hypReadMore.Visible = bShowReadMore
		Else 'HTML
			'TODO: this is showing the details in the admin skin rather than the user skin
			hypReadMore.Visible = bShowReadMore
			hypReadMore.NavigateUrl = EditUrl("ItemID", Convert.ToString(DataBinder.Eval(e.Item.DataItem, "ItemID")), "Details")
			hypTitle.NavigateUrl = EditUrl("ItemID", Convert.ToString(DataBinder.Eval(e.Item.DataItem, "ItemID")), "Details")
		End If
		
		If bShowCategories Then 
			Dim lblCategories As Label = CType(e.Item.FindControl("lblCategories"), Label)
			If Not lblCategories is nothing Then
				Dim Articles As New ArticleController()
				lblCategories.Text = Articles.GetCategoryList(Convert.toInt32(DataBinder.Eval(e.Item.DataItem, "ItemId")))
			End If
		End if

		Dim ArticleImage as Image = CType(e.Item.FindControl("imgArticleImage"), System.Web.UI.WebControls.Image)
		If not ArticleImage is nothing Then 
			ArticleImage.ImageUrl = GetImage(Convert.ToString(DataBinder.Eval(e.Item.DataItem, "ImageFile")))
			If ArticleImage.ImageUrl = "" Then ArticleImage.Visible = False
			If nImageAlignment = -1 Then
				If e.Item.ItemType = ListItemType.AlternatingItem Then
					ArticleImage.ImageAlign = 2
				Else
					ArticleImage.ImageAlign = 1
				End If
			Else
				ArticleImage.ImageAlign = nImageAlignment
			End If
		End If
		
	End Sub
	
	Private Sub ShowComments(e As DataListItemEventArgs)
		' comments	
		if bAllowComments = "True" then
			try
				Dim Articles As New ArticleController()
				Dim comments As ArrayList = Articles.GetComments(Convert.toInt32(DataBinder.Eval(e.Item.DataItem, "ItemId")))
				Dim lnkComments As HyperLink = CType(e.Item.FindControl("lnkComments"), System.Web.UI.WebControls.HyperLink)
				lnkComments.Text = Localization.GetString("Comments.Text", LocalResourceFile) & " (" & comments.Count() & ")"
				lnkComments.NavigateUrl = EditUrl("ItemID", Convert.ToString(DataBinder.Eval(e.Item.DataItem, "ItemID")), "Details")
					
			Catch ex As exception
				ProcessModuleLoadException("Error: Unable to load Comments:", me, ex, True)
			End Try
		End if
	End Sub
	
	Private Sub ShowMoreArticles(e As DataListItemEventArgs)
		' more articles link
		Dim lnkMoreArticles As HyperLink = CType(e.Item.FindControl("lnkMoreArticles"), System.Web.UI.WebControls.HyperLink)
		If bMoreArticles = "True" Then
			lnkMoreArticles.Visible = True
			lnkMoreArticles.NavigateUrl = DotNetNuke.Common.NavigateUrl(ctype(Settings("MoreArticlesPage"), integer))
		Else
			lnkMoreArticles.Visible = False
		End If
		
	End Sub
	
	Private Sub ShowPagination(e As DataListItemEventArgs)

		If (Settings("HidePaging") <> "True") Then
			Dim SearchString As String = ""
			If  Request.QueryString("SearchTerm") <> "" Then
				SearchString = "&SearchTerm=" & Request.QueryString("SearchTerm")
			End If

		End If
	End Sub
	
	Private Function GetImage(ByVal ImageFile As String) As String
		Try
			If Not ImageFile = "" Then
				Dim fc As New dotnetnuke.Services.FileSystem.FileController
				Dim fi As DotNetNuke.Services.FileSystem.FileInfo

				If ImageFile.StartsWith("FileID=") Then
					fi = fc.GetFileById(ImageFile.Substring(7), PortalID)
				Else
					fi = fc.GetFile(ImageFile, PortalID, "")
				End If
				if not fi is nothing then
					Return "~/DesktopModules/Articles/MakeThumbnail.aspx?Image=" & Server.UrlEncode(PortalSettings.HomeDirectory & fi.Folder & fi.FileName) & "&w=" & MaxImageWidth
				Else
					Return ""
				End if
			End If
		Catch exc As Exception			 'Module failed to load
			ProcessModuleLoadException(Me, exc)
		End Try
	End Function

#Region "Web Form Designer Generated Code"

	'This call is required by the Web Form Designer.
	<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

	End Sub

	Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
		'CODEGEN: This method call is required by the Web Form Designer
		'Do not modify it using the code editor.
		InitializeComponent()
		bShowCategories = (Settings("ShowCategory") = "True") 'Defaults to False
		bShowReadMore = (Settings("ShowReadMore") <> "False")
		bAllowComments = (Settings("AllowComments") = "True")
		bMoreArticles = Settings("MoreArticles")
		
		LocalResourceFile = Localization.GetResourceFile(me, "ArticleList.ascx")
		'LocalResourceFile = "DesktopModules/Articles/App_LocalResources/ArticleList.ascx." & Localization.GetCurrentCulture & ".resx"

		If IsNumeric(Settings("ImageWidth")) Then
			MaxImageWidth = Settings("ImageWidth")
		End If
		
		If Settings("ImageAlignment") = "" Then
			nImageAlignment = 1
		ElseIf Settings("ImageAlignment") = "Alternate"
			nImageAlignment = -1
		Else
			nImageAlignment = Convert.ToInt32(Settings("ImageAlignment"))
		End If
	End Sub

#End Region

End Class
End Namespace



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -