Overview

Namespaces

  • MatthiasMullie
    • Minify
      • Exceptions
    • PathConverter
  • None
  • ReCaptcha
    • RequestMethod
  • TOTP

Classes

  • apc_cache
  • apcu_cache
  • ApprovePost_Notify_Background
  • ApproveReply_Notify_Background
  • Attachments
  • Birthday_Notify_Background
  • browser_detector
  • Buddy_Notify_Background
  • cache_api
  • CreateAttachment_Notify_Background
  • CreatePost_Notify_Background
  • curl_fetch_web_data
  • custom_search
  • EventNew_Notify_Background
  • ftp_connection
  • fulltext_search
  • gif_color_table
  • gif_file
  • gif_file_header
  • gif_image
  • gif_image_header
  • gif_lzw_compression
  • GroupAct_Notify_Background
  • GroupReq_Notify_Background
  • Likes
  • Likes_Notify_Background
  • MatthiasMullie\Minify\CSS
  • MatthiasMullie\Minify\JS
  • MatthiasMullie\Minify\Minify
  • MatthiasMullie\PathConverter\Converter
  • MemberReport_Notify_Background
  • MemberReportReply_Notify_Background
  • memcache_cache
  • memcached_cache
  • Mentions
  • MsgReport_Notify_Background
  • MsgReportReply_Notify_Background
  • paypal_display
  • paypal_payment
  • postgres_cache
  • ProxyServer
  • Punycode
  • ReCaptcha\ReCaptcha
  • ReCaptcha\RequestMethod\Curl
  • ReCaptcha\RequestMethod\CurlPost
  • ReCaptcha\RequestMethod\Post
  • ReCaptcha\RequestMethod\Socket
  • ReCaptcha\RequestMethod\SocketPost
  • ReCaptcha\RequestParameters
  • ReCaptcha\Response
  • Register_Notify_Background
  • search_api
  • SMF_BackgroundTask
  • smf_cache
  • sqlite_cache
  • standard_search
  • TOTP\Auth
  • TypeError
  • Update_TLD_Regex
  • xcache_cache
  • xmlArray
  • zend_cache

Interfaces

  • cache_api_interface
  • ReCaptcha\RequestMethod
  • search_api_interface

Exceptions

  • Error
  • MatthiasMullie\Minify\Exception
  • MatthiasMullie\Minify\Exceptions\BasicException
  • MatthiasMullie\Minify\Exceptions\FileImportException
  • MatthiasMullie\Minify\Exceptions\IOException

Functions

  • _safe_serialize
  • _safe_unserialize
  • account
  • Activate
  • activateAccount
  • add_integration_function
  • addData
  • addInlineCss
  • addInlineJavaScript
  • addJavaScriptVar
  • AddLanguage
  • AddMailQueue
  • AddMembergroup
  • addMembersToGroup
  • addSeparator
  • AddSmiley
  • addSubscription
  • addTriggers
  • AdminAccount
  • AdminApprove
  • AdminBoardRecount
  • AdminEndSession
  • AdminHome
  • adminLogin
  • adminLogin_outputPostVars
  • AdminLogs
  • AdminMain
  • adminNotify
  • AdminRegister
  • AdminSearch
  • AdminSearchInternal
  • AdminSearchMember
  • AdminSearchOM
  • alert_configuration
  • alert_count
  • alert_delete
  • alert_mark
  • alert_markread
  • alert_notifications_boards
  • alert_notifications_topics
  • alert_purge
  • alerts_popup
  • AlignURLsWithSSLSetting
  • allowedTo
  • AnnouncementSelectMembergroup
  • AnnouncementSend
  • AnnounceTopic
  • ApplyRules
  • approveAllData
  • ApproveAttach
  • ApproveAttachments
  • ApproveMessage
  • approveMessages
  • approvePosts
  • approveTopics
  • array_column
  • array_length
  • assignAttachments
  • attachDirStatus
  • attachmentChecks
  • attachments_init_dir
  • automanage_attachments_by_space
  • automanage_attachments_check_directory
  • automanage_attachments_create_directory
  • AutoSuggest_Search_Member
  • AutoSuggest_Search_MemberGroups
  • AutoSuggest_Search_SMFVersions
  • AutoSuggestHandler
  • AutoTask
  • BackupDatabase
  • backupTable
  • Ban
  • BanBrowseTriggers
  • BanEdit
  • banEdit2
  • BanEditTrigger
  • BanList
  • banLoadAdditionalIPs
  • banLoadAdditionalIPsError
  • banLoadAdditionalIPsMember
  • BanLog
  • banPermissions
  • bbc_to_html
  • BoardIndex
  • BoardNotify
  • BoardPermissionsReport
  • BoardReport
  • boardsAllowedTo
  • BoardurlMatch
  • BookOfUnknown
  • BrowseFiles
  • BrowseMailQueue
  • BuddyListToggle
  • build_query_board
  • build_regex
  • buildEventDatetimes
  • cache_get_data
  • cache_getLastPosts
  • cache_getMembergroupList
  • cache_getOffsetIndependentEvents
  • cache_getRecentEvents
  • cache_put_data
  • cache_quick_get
  • CalculateNextTrigger
  • CalendarMain
  • CalendarPost
  • call_helper
  • call_integration_hook
  • canLinkEvent
  • canPickTheme
  • cdata_parse
  • censorText
  • check_cron
  • checkActivation
  • checkChange
  • checkConfirm
  • checkExistingTriggerIP
  • CheckFilesWritable
  • checkGD
  • checkImageContents
  • checkImagick
  • checkLogin
  • checkMagickWand
  • checkSession
  • checkSubmitOnce
  • clean_cache
  • cleanLangString
  • cleanRequest
  • cleanRequest_cron
  • cleanTokens
  • cleanXml
  • ClearMailQueue
  • cli_scheduled_fetchSMfiles
  • clock
  • cmdStep0
  • comma_format
  • compareVersions
  • ComposeMailing
  • consolidateSpiderStats
  • construct_query_string
  • constructPageIndex
  • ConvertEntities
  • ConvertMsgBody
  • convertSettingstoOptions
  • convertSettingsToTheme
  • ConvertUtf8
  • CoppaForm
  • CopyTemplate
  • copytree
  • countReports
  • create_button
  • create_chmod_control
  • create_control_richedit
  • create_control_verification
  • createAttachment
  • createBoard
  • createCategory
  • createList
  • createMenu
  • CreateMessageIndex
  • createPost
  • createSalvageArea
  • createThumbnail
  • createToken
  • createWaveFile
  • Credits
  • custFieldsMaxOrder
  • custMinify
  • DatabaseChanges
  • DatabasePopulation
  • DatabaseSettings
  • db_extend
  • db_extra_init
  • db_fix_prefix
  • db_packages_init
  • db_search_init
  • db_version_check
  • debugPrint
  • deleteAccount
  • deleteAccount2
  • deleteAllMinified
  • deleteBoards
  • deleteCategories
  • DeleteDraft
  • deleteErrors
  • DeleteInstall
  • DeleteMembergroup
  • deleteMembergroups
  • deleteMembers
  • DeleteMessage
  • deleteMessages
  • deleteModComment
  • deleteNotifyPrefs
  • DeleteUpgrade
  • deltree
  • Destroy
  • destroyMenu
  • detectBrowser
  • detectFulltextIndex
  • determineActions
  • Display
  • display_db_error
  • display_loadavg_error
  • display_maintenance_message
  • DisplayAdminFile
  • displayDebug
  • DisplayStats
  • DoLogin
  • Download
  • downloadAvatar
  • DownloadLanguage
  • dumpTags
  • EditAgreement
  • EditBoard
  • EditBoard2
  • EditBoardSettings
  • editBuddies
  • editBuddyIgnoreLists
  • EditCategory
  • EditCategory2
  • EditComment
  • EditCustomProfiles
  • EditHoliday
  • editIgnoreList
  • EditMembergroup
  • EditMessageIcons
  • editModComment
  • EditNews
  • EditPermissionProfiles
  • EditPoll
  • EditPoll2
  • EditSearchMethod
  • EditSearchSettings
  • EditSmileyOrder
  • EditSmileys
  • EditSmileySets
  • EditSmileySettings
  • EditSpider
  • EditTask
  • EditTheme
  • EditWeights
  • emailAdmins
  • EnableTheme
  • entity_fix__callback
  • escapestring__recursive
  • ExamineFile
  • expandIPv6
  • fatal_error
  • fatal_lang_error
  • fetch_alerts
  • fetch_task
  • fetch_web_data
  • fetchPerms__recursive
  • fetchTagAttributes
  • find_gpg
  • find_signed_off
  • find_signed_off_parents
  • findForumErrors
  • findMembers
  • findSearchAPI
  • finishTables
  • fix_possible_url
  • fix_serialized_data
  • fixchar__callback
  • fixchardb__callback
  • fixChildren
  • fixModSecurity
  • fixRelativePath
  • fixTag
  • fixTags
  • forum_time
  • forumProfile
  • ForumSettings
  • frameOptionsHeader
  • GeneralPermissionSettings
  • generateSubscriptionError
  • generateValidationCode
  • get_all_themes
  • get_current_settings
  • get_date_or_time_format
  • get_directory_tree_elements
  • get_file_listing
  • get_files_recursive
  • get_gravatar_url
  • get_hook_info_from_raw
  • get_installed_themes
  • get_integration_hooks
  • get_integration_hooks_count
  • get_integration_hooks_data
  • get_proxied_url
  • get_single_theme
  • get_theme_info
  • getAttachmentFilename
  • getAttachMsgInfo
  • getAvatars
  • getBirthdayRange
  • getBoardIndex
  • getBoardList
  • getBoardModeratorGroups
  • getBoardModerators
  • getBoardParents
  • getBoardTree
  • getCalendarGrid
  • getCalendarList
  • getCalendarWeek
  • getCommentModDetails
  • getCustFieldsMList
  • getDailyStats
  • getEventPoster
  • getEventProperties
  • getEventRange
  • getFileVersions
  • getHolidayRange
  • GetJumpTo
  • getLanguages
  • getLastPost
  • getLastPosts
  • GetMemberActivationCounts
  • getMemberData
  • getMemberGroups
  • getMembersOnlineStats
  • getMessageIcons
  • getMsgMemberID
  • getNewEventDatetimes
  • getNotifyPrefs
  • getPackageInfo
  • getRawAttachInfo
  • getReportComments
  • getReportDetails
  • getReports
  • getServerVersions
  • getTodayInfo
  • getTopic
  • getTreeOrder
  • getUserTimezone
  • getXmlMembers
  • getXmlNews
  • getXmlProfile
  • getXmlRecent
  • gif_outputAsPng
  • GroupList
  • groupMembership
  • groupMembership2
  • GroupPermissionsReport
  • GroupRequests
  • Groups
  • groupsAllowedTo
  • HandleComment
  • HandleReport
  • hash_benchmark
  • hash_length
  • hash_password
  • hash_salt
  • hash_verify_password
  • HelpIndex
  • HelpRules
  • highlight
  • highlight_php_code
  • host_from_ip
  • html_to_bbc
  • htmlspecialchars__recursive
  • htmltrim__recursive
  • https_redirect_active
  • httpsOn
  • iCalDownload
  • ignoreboards
  • imagecopyresamplebicubic
  • imagecreatefrombmp
  • imageMemoryCheck
  • ImportSmileys
  • inet_dtop
  • inet_ptod
  • initialize_inputs
  • InMaintenance
  • insertBanGroup
  • insertEvent
  • InstallCopy
  • InstallDir
  • installer_updateSettingsFile
  • installExit
  • InstallFile
  • InstallSmileySet
  • ip2range
  • iri_to_url
  • is_not_banned
  • is_not_guest
  • isAccessiblePM
  • isAllowedTo
  • isBannedEmail
  • isBrowser
  • isChildOf
  • isReservedName
  • issueWarning
  • isValidIP
  • isValidIPv6
  • JavaScriptEscape
  • JavaScriptModify
  • jeffsdatediff
  • JSMembers
  • KickGuest
  • legalise_bbc
  • list_getAttachDirs
  • list_getAttachments
  • list_getBanItems
  • list_getBanLogEntries
  • list_getBans
  • list_getBanTriggers
  • list_getBaseDirs
  • list_getBoardNotifications
  • list_getFiles
  • list_getGroupRequestCount
  • list_getGroupRequests
  • list_getGroupRequestsCount
  • list_getHolidays
  • list_getIPMessageCount
  • list_getIPMessages
  • list_getLanguages
  • list_getLanguagesList
  • list_getLoginCount
  • list_getLogins
  • list_getMailQueue
  • list_getMailQueueSize
  • list_getMembergroups
  • list_getMembers
  • list_getMessageIcons
  • list_getModLogEntries
  • list_getModLogEntryCount
  • list_getNews
  • list_getNumAttachments
  • list_getNumBanItems
  • list_getNumBanLogEntries
  • list_getNumBans
  • list_getNumBanTriggers
  • list_getNumFiles
  • list_getNumHolidays
  • list_getNumLanguages
  • list_getNumMembers
  • list_getNumSmileys
  • list_getNumSmileySets
  • list_getNumSpiderLogs
  • list_getNumSpiders
  • list_getNumSpiderStats
  • list_getNumTaskLogEntries
  • list_getNumUnapprovedAttachments
  • list_getNumUnwatched
  • list_getPackages
  • list_getProfileEditCount
  • list_getProfileEdits
  • list_getProfileFields
  • list_getProfileFieldSize
  • list_getScheduledTasks
  • list_getSmileys
  • list_getSmileySets
  • list_getSpiderLogs
  • list_getSpiders
  • list_getSpiderStats
  • list_getSubscribedUserCount
  • list_getSubscribedUsers
  • list_getTaskLogEntries
  • list_getTopicNotificationCount
  • list_getTopicNotifications
  • list_getUnapprovedAttachments
  • list_getUnwatched
  • list_getUserErrorCount
  • list_getUserErrors
  • list_getUserWarningCount
  • list_getUserWarnings
  • list_getWarningCount
  • list_getWarnings
  • list_getWarningTemplateCount
  • list_getWarningTemplates
  • list_getWatchedUserCount
  • list_getWatchedUserPosts
  • list_getWatchedUserPostsCount
  • list_getWatchedUsers
  • list_integration_hooks
  • listMembergroupMembers_Href
  • ListMessageIcons
  • listtree
  • load_database
  • load_file
  • load_lang_file
  • loadAttachmentContext
  • loadBoard
  • loadCacheAccelerator
  • loadCacheAPIs
  • loadCSSFile
  • loadCustomFields
  • loadDatabase
  • loadDatePair
  • loadDatePicker
  • loadEmailTemplate
  • loadEssentialData
  • loadEssentialThemeData
  • loadForumTests
  • loadGeneralSettingParameters
  • loadIllegalBBCHtmlGroups
  • loadIllegalGuestPermissions
  • loadIllegalPermissions
  • loadInstalledPackages
  • loadJavaScriptFile
  • loadLanguage
  • loadLocale
  • loadMemberContext
  • loadMemberCustomFields
  • loadMemberData
  • loadPaymentGateways
  • loadPermissionProfiles
  • loadPermissions
  • loadProfileFields
  • LoadRules
  • loadSearchAPIs
  • loadSession
  • loadSubscriptions
  • loadSubTemplate
  • loadTemplate
  • loadTheme
  • loadThemeOptions
  • loadTimePicker
  • loadUserSettings
  • LockTopic
  • LockVoting
  • log_ban
  • log_error
  • log_error_online
  • logAction
  • logActions
  • Login
  • Login2
  • LoginTFA
  • logLastDatabaseError
  • Logout
  • logSpider
  • logTriggersUpdates
  • MaintainCleanCache
  • MaintainDatabase
  • MaintainEmptyUnimportantLogs
  • MaintainFiles
  • MaintainFindFixErrors
  • MaintainMassMoveTopics
  • MaintainMembers
  • MaintainPurgeInactiveMembers
  • MaintainReattributePosts
  • MaintainRecountPosts
  • MaintainRemoveOldDrafts
  • MaintainRemoveOldPosts
  • MaintainRoutine
  • MaintainTopics
  • makeCustomFieldChanges
  • makeFilesWritable
  • makeNotificationChanges
  • makeThemeChanges
  • ManageAttachmentPaths
  • ManageAttachments
  • ManageAttachmentSettings
  • ManageAvatarSettings
  • ManageBoards
  • ManageBoardsMain
  • ManageCalendar
  • ManageLabels
  • ManageLanguages
  • ManageMail
  • ManageMaintenance
  • ManageNews
  • ManagePaidSubscriptions
  • ManagePostSettings
  • ManageRules
  • ManageScheduledTasks
  • ManageSearch
  • ManageSearchEngineSettings
  • ManageSmileys
  • markBoardsRead
  • markMessages
  • MarkRead
  • matchHighestPackageVersion
  • matchIPtoCIDR
  • matchPackageVersion
  • md5_hmac
  • MembergroupIndex
  • MembergroupMembers
  • MemberGroupsReport
  • Memberlist
  • membersAllowedTo
  • MembersAwaitingActivation
  • memoryReturnBytes
  • MergeDone
  • MergeExecute
  • MergeIndex
  • mergePosts
  • MergeTopics
  • MessageActionsApply
  • MessageDrafts
  • MessageFolder
  • MessageIndex
  • messageIndexBar
  • MessageKillAll
  • MessageMain
  • MessagePopup
  • MessagePost
  • MessagePost2
  • messagePostError
  • MessagePrune
  • MessageSearch
  • MessageSearch2
  • MessageSettings
  • mimespecialchars
  • mktree
  • MLAll
  • MLSearch
  • ModBlockGroupRequests
  • ModBlockNotes
  • ModBlockReportedMembers
  • ModBlockReportedPosts
  • ModBlockWatchedUsers
  • ModEndSession
  • ModerateGroups
  • ModerationHome
  • ModerationMain
  • ModerationSettings
  • ModifyAlertsSettings
  • ModifyAntispamSettings
  • ModifyBasicSettings
  • ModifyBBCSettings
  • modifyBoard
  • ModifyCacheSettings
  • ModifyCalendarSettings
  • ModifyCat
  • modifyCategory
  • ModifyCookieSettings
  • ModifyDatabaseSettings
  • ModifyDraftSettings
  • modifyEvent
  • ModifyFeatureSettings
  • ModifyGeneralModSettings
  • ModifyGeneralSecuritySettings
  • ModifyGeneralSettings
  • ModifyHolidays
  • ModifyLanguage
  • ModifyLanguages
  • ModifyLanguageSettings
  • ModifyLayoutSettings
  • ModifyLikesSettings
  • ModifyLoadBalancingSettings
  • ModifyLogSettings
  • ModifyMailSettings
  • ModifyMembergroup
  • ModifyMembergroup2
  • ModifyMembergroups
  • ModifyMembergroupsettings
  • ModifyMentionsSettings
  • ModifyModSettings
  • ModifyNewsSettings
  • ModifyPermissions
  • modifyPost
  • ModifyPostModeration
  • ModifyPostSettings
  • ModifyProfile
  • ModifyRegistrationSettings
  • ModifySettings
  • ModifySignatureSettings
  • ModifySubscription
  • ModifySubscriptionSettings
  • ModifyTopicSettings
  • ModifyUserSubscription
  • ModifyWarningSettings
  • ModifyWarningTemplate
  • MoveTopic
  • MoveTopic2
  • moveTopicConcurrence
  • moveTopics
  • MySQLConvertOldIp
  • newsletterpreview
  • newspreview
  • newTable
  • next_time
  • nextSubstep
  • notification
  • ob_sessrewrite
  • obExit
  • obExit_cron
  • OptimizeTables
  • package_chmod
  • package_create_backup
  • package_crypt
  • package_flush_cache
  • package_get_contents
  • package_put_contents
  • PackageBrowse
  • PackageDownload
  • PackageFTPTest
  • PackageGBrowse
  • PackageGet
  • PackageInstall
  • PackageInstallTest
  • PackageList
  • PackageOptions
  • PackagePermissions
  • PackagePermissionsAction
  • PackageRemove
  • packageRequireFTP
  • Packages
  • PackageServerAdd
  • PackageServerRemove
  • PackageServers
  • PackageUpload
  • parse_bbc
  • parse_path
  • parse_sql
  • parseAttachBBC
  • parseBoardMod
  • parseModification
  • parsePackageInfo
  • parsesmileys
  • password_get_info
  • password_hash
  • password_needs_rehash
  • password_verify
  • pauseAttachmentMaintenance
  • pauseMailQueueClear
  • pauseRepairProcess
  • pauseSignatureApplySettings
  • perform_task
  • PermissionByBoard
  • PermissionIndex
  • permute
  • php_version_check
  • phpBB3_password_check
  • PickTheme
  • PlushSearch1
  • PlushSearch2
  • populateDuplicateMembers
  • Post
  • Post2
  • PostModerationMain
  • prepareAttachsByMsg
  • prepareCLIhandler
  • prepareDBSettingContext
  • prepareDisplayContext
  • prepareLikesContext
  • prepareMailingForPreview
  • prepareMessageContext
  • prepareSearchContext
  • prepareServerSettingsContext
  • preparsecode
  • print_error
  • printMemberListRows
  • PrintTopic
  • processAttachments
  • profile_popup
  • profileLoadAvatarData
  • profileLoadGroups
  • profileLoadLanguages
  • profileLoadSignatureData
  • profileReloadUser
  • profileSaveAvatarData
  • profileSaveGroups
  • profileSendActivation
  • profileValidateEmail
  • profileValidateSignature
  • protected_alter
  • quickFileWritable
  • QuickInTopicModeration
  • QuickModeration
  • QuoteFast
  • random_bytes
  • random_int
  • RandomCompat_intval
  • RandomCompat_strlen
  • RandomCompat_substr
  • range2ip
  • read_tgz_data
  • read_tgz_file
  • read_zip_data
  • read_zip_file
  • ReadDraft
  • reapplySubscriptions
  • reattributePosts
  • rebuildModCache
  • recacheSpiderNames
  • RecentPosts
  • recountOpenReports
  • recursiveBoards
  • redirectexit
  • redirectLocation
  • ReduceMailQueue
  • reencodeImage
  • RegCenter
  • Register
  • Register2
  • RegisterCheckUsername
  • registerMember
  • registerSMStats
  • reloadSettings
  • RemindMe
  • RemindPick
  • remove_dir
  • remove_integration_function
  • remove_theme
  • RemoveAllAttachments
  • RemoveAttachment
  • RemoveAttachmentByAge
  • RemoveAttachmentBySize
  • removeBanGroups
  • removeBanLogs
  • removeBanTriggers
  • removeDeleteConcurrence
  • removeEvent
  • removeHolidays
  • removeIllegalBBCHtmlPermission
  • removeMembersFromGroups
  • removeMessage
  • removeMessages
  • RemoveOldTopics2
  • RemovePoll
  • removeSubscription
  • RemoveTheme
  • RemoveTopic2
  • removeTopics
  • reorderBoards
  • RepairAttachments
  • RepairBoards
  • replaceEntities__callback
  • ReportDetails
  • ReportedContent
  • ReportedMembers
  • ReportMessage
  • reportPost
  • ReportsMain
  • ReportToModerator
  • ReportToModerator2
  • reportUser
  • RequestMembers
  • resetPassword
  • resizeImage
  • resizeImageFile
  • RestoreTopic
  • RetrievePreview
  • safe_file_write
  • safe_serialize
  • safe_unserialize
  • sanitize_iri
  • sanitizeMSCutPaste
  • saveDBSettings
  • SaveDraft
  • saveModComment
  • SavePMDraft
  • saveProfileChanges
  • saveProfileFields
  • saveSettings
  • saveTriggers
  • scheduled_birthdayemails
  • scheduled_daily_digest
  • scheduled_daily_maintenance
  • scheduled_fetchSMfiles
  • scheduled_paid_subscriptions
  • scheduled_remove_old_drafts
  • scheduled_remove_temp_attachments
  • scheduled_remove_topic_redirect
  • scheduled_weekly_digest
  • scheduled_weekly_maintenance
  • ScheduledTasks
  • SearchEngines
  • SearchMembers
  • searchSort
  • SecretAnswer2
  • SecretAnswerInput
  • secureDirectory
  • SelectMailingMembers
  • send_http_status
  • SendActivation
  • sendmail
  • SendMailing
  • sendNotifications
  • sendpm
  • sentence_list
  • serialize_to_json
  • sessionClose
  • sessionDestroy
  • sessionGC
  • sessionOpen
  • sessionRead
  • sessionWrite
  • set_alert_icon
  • set_avatar_data
  • set_fatal_error_headers
  • set_tld_regex
  • SetCensor
  • setEventStartEnd
  • SetJavaScript
  • setKeys
  • setLoginCookie
  • setMemoryLimit
  • setNotifyPrefs
  • setPassword
  • setPassword2
  • SetQuickGroups
  • SetReserved
  • setSqlMode
  • setTFACookie
  • SetThemeOptions
  • SetThemeSettings
  • setup_fatal_error_context
  • setupMenuContext
  • setupProfileContext
  • setupThemeContext
  • sha1_core
  • sha1_ft
  • sha1_kt
  • sha1_raw
  • sha1_rol
  • sha1_smf
  • shorten_subject
  • ShowAdminHelp
  • showAlerts
  • showAttachment
  • showAttachments
  • ShowClosedReports
  • showCodeImage
  • ShowCustomProfiles
  • ShowDrafts
  • ShowHelp
  • showLetterImage
  • ShowNotice
  • showPermissions
  • ShowPHPinfoSettings
  • showPMDrafts
  • showPosts
  • showProfileDrafts
  • ShowReports
  • showUnwatched
  • ShowXmlFeed
  • sig_preview
  • smf_chmod
  • smf_crc32
  • smf_db_add_column
  • smf_db_add_index
  • smf_db_affected_rows
  • smf_db_allow_persistent
  • smf_db_backup_table
  • smf_db_calculate_type
  • smf_db_change_column
  • smf_db_create_query_column
  • smf_db_create_table
  • smf_db_create_word_search
  • smf_db_cte_support
  • smf_db_custom_order
  • smf_db_drop_table
  • smf_db_error
  • smf_db_error_backtrace
  • smf_db_error_insert
  • smf_db_escape_string
  • smf_db_escape_wildcard_string
  • smf_db_fetch_all
  • smf_db_get_server_info
  • smf_db_get_vendor
  • smf_db_get_version
  • smf_db_initiate
  • smf_db_insert
  • smf_db_insert_id
  • smf_db_list_columns
  • smf_db_list_indexes
  • smf_db_list_tables
  • smf_db_native_replace
  • smf_db_optimize_table
  • smf_db_query
  • smf_db_quote
  • smf_db_remove_column
  • smf_db_remove_index
  • smf_db_replacement__callback
  • smf_db_search_language
  • smf_db_search_query
  • smf_db_search_support
  • smf_db_select
  • smf_db_select_db
  • smf_db_table_sql
  • smf_db_table_structure
  • smf_db_transaction
  • smf_db_version
  • smf_error_handler
  • smf_error_handler_cron
  • smf_is_resource
  • smf_json_decode
  • smf_list_timezones
  • smf_main
  • smf_mysql_fetch_assoc
  • smf_mysql_fetch_row
  • smf_mysql_free_result
  • smf_mysql_insert_id
  • smf_mysql_num_rows
  • smf_mysql_real_escape_string
  • smf_seed_generator
  • smf_serverResponse
  • smf_setcookie
  • smf_strtolower
  • smf_var_export
  • SMStats
  • sortBoards
  • sortCategories
  • spamProtection
  • spell_check
  • spell_init
  • spell_suggest
  • SpellCheck
  • SpiderCheck
  • SpiderLogs
  • SpiderStats
  • SplitExecute
  • SplitIndex
  • SplitSelectionExecute
  • SplitSelectTopics
  • splitTopic
  • SplitTopics
  • ssi_boardNews
  • ssi_boardStats
  • ssi_checkPassword
  • ssi_copyright
  • ssi_fetchGroupMembers
  • ssi_fetchMember
  • ssi_fetchPosts
  • ssi_full_version
  • ssi_latestMember
  • ssi_login
  • ssi_logOnline
  • ssi_logout
  • ssi_menubar
  • ssi_news
  • ssi_pollVote
  • ssi_queryMembers
  • ssi_queryPosts
  • ssi_quickSearch
  • ssi_randomMember
  • ssi_recentAttachments
  • ssi_recentEvents
  • ssi_recentPoll
  • ssi_recentPosts
  • ssi_recentTopics
  • ssi_showPoll
  • ssi_shutdown
  • ssi_software_year
  • ssi_todaysBirthdays
  • ssi_todaysCalendar
  • ssi_todaysEvents
  • ssi_todaysHolidays
  • ssi_topBoards
  • ssi_topPoll
  • ssi_topPoster
  • ssi_topTopics
  • ssi_topTopicsReplies
  • ssi_topTopicsViews
  • ssi_version
  • ssi_welcome
  • ssi_whosOnline
  • ssl_cert_found
  • StaffReport
  • statPanel
  • Sticky
  • strip_php_comments
  • stripslashes__recursive
  • subscriptions
  • summary
  • TaskLog
  • TaskSettings
  • template_action_permissions
  • template_add_edit_group_boards_list
  • template_add_language
  • template_add_rule
  • template_additional_rows
  • template_addsmiley
  • template_admin
  • template_admin_account
  • template_admin_browse
  • template_admin_login
  • template_admin_quick_search
  • template_admin_register
  • template_admin_search_results
  • template_after
  • template_alert_configuration
  • template_alert_notifications_boards
  • template_alert_notifications_topics
  • template_alerts_all_read
  • template_alerts_popup
  • template_announce
  • template_announcement_send
  • template_ask
  • template_ask_delete
  • template_attachment_errors
  • template_attachment_paths
  • template_attachment_repair
  • template_avatar_settings_above
  • template_avatar_settings_below
  • template_backup_database
  • template_backup_xml
  • template_ban_edit
  • template_ban_edit_trigger
  • template_bcd
  • template_bi_board_children
  • template_bi_board_icon
  • template_bi_board_info
  • template_bi_board_lastpost
  • template_bi_board_stats
  • template_bi_redirect_icon
  • template_bi_redirect_stats
  • template_boardindex_outer_above
  • template_boardindex_outer_below
  • template_body_above
  • template_body_below
  • template_browse
  • template_button_strip
  • template_by_board
  • template_calendar_top
  • template_callback_question_answer_list
  • template_check_username
  • template_chmod
  • template_chmod_files
  • template_choose_payment
  • template_clean_cache_button_above
  • template_clean_cache_button_below
  • template_confirm_board_delete
  • template_confirm_category_delete
  • template_control_chmod
  • template_control_richedit
  • template_control_richedit_buttons
  • template_control_verification
  • template_convert_entities
  • template_convert_msgbody
  • template_convert_utf8
  • template_convert_xml
  • template_coppa
  • template_coppa_form
  • template_copy_template
  • template_create_index
  • template_create_index_done
  • template_create_index_progress
  • template_create_list_menu
  • template_credits
  • template_css
  • template_database_changes
  • template_database_settings
  • template_database_xml
  • template_delete_install
  • template_delete_subscription
  • template_deleteAccount
  • template_download_language
  • template_downloaded
  • template_edit_agreement
  • template_edit_browse
  • template_edit_censored
  • template_edit_comment
  • template_edit_file
  • template_edit_group
  • template_edit_holiday
  • template_edit_list
  • template_edit_options
  • template_edit_profile_field
  • template_edit_profiles
  • template_edit_reserved_words
  • template_edit_scheduled_tasks
  • template_edit_style
  • template_edit_template
  • template_editBuddies
  • template_editicon
  • template_editicons
  • template_editIgnoreList
  • template_editsets
  • template_email_members
  • template_email_members_compose
  • template_email_members_send
  • template_error_log
  • template_error_message
  • template_event_post
  • template_examine
  • template_extract_package
  • template_fatal_error
  • template_file_permissions
  • template_find_members
  • template_folder
  • template_footer
  • template_forum_settings
  • template_ftp_required
  • template_generic
  • template_generic_menu
  • template_generic_menu_dropdown_above
  • template_generic_menu_dropdown_below
  • template_generic_menu_tabs
  • template_generic_xml
  • template_generic_xml_recursive
  • template_group_members
  • template_group_request_reason
  • template_group_requests_block
  • template_groupMembership
  • template_header
  • template_hms
  • template_homepage_sample1
  • template_homepage_sample1_html
  • template_homepage_sample1_php
  • template_html_above
  • template_html_below
  • template_ic_block_calendar
  • template_ic_block_online
  • template_ic_block_recent
  • template_ic_block_stats
  • template_ignoreboards
  • template_include
  • template_info_center
  • template_init
  • template_inline_permissions
  • template_install_above
  • template_install_below
  • template_install_options
  • template_installed
  • template_issueWarning
  • template_javascript
  • template_jump_to
  • template_kick_guest
  • template_labels
  • template_like
  • template_list
  • template_list_themes
  • template_load_warning_variables
  • template_login
  • template_login_tfa
  • template_mailtest
  • template_main
  • template_maint_warning_above
  • template_maint_warning_below
  • template_maintain_database
  • template_maintain_members
  • template_maintain_routine
  • template_maintain_topics
  • template_maintenance
  • template_manual
  • template_max_size
  • template_menu
  • template_merge
  • template_merge_done
  • template_merge_extra_options
  • template_message_icons
  • template_moderation_center
  • template_moderation_settings
  • template_modify_board
  • template_modify_category
  • template_modify_group
  • template_modify_group_display
  • template_modify_language_entries
  • template_modify_subscription
  • template_modify_user_subscription
  • template_modify_weights
  • template_modifydone
  • template_modifyfast
  • template_modifyset
  • template_modifysmiley
  • template_modifytopicdone
  • template_move
  • template_new_group
  • template_news_lists
  • template_newsfader
  • template_not_done
  • template_notes
  • template_notify_board
  • template_omfg
  • template_optimize
  • template_options
  • template_package_confirm
  • template_package_list
  • template_paid_done
  • template_permission_index
  • template_permission_show_contents
  • template_php_info
  • template_pick
  • template_pm
  • template_pm_above
  • template_pm_below
  • template_pm_popup
  • template_populate_database
  • template_popup
  • template_post
  • template_post_header
  • template_postmod_permissions
  • template_print
  • template_print_above
  • template_print_below
  • template_print_options
  • template_profile_above
  • template_profile_avatar_select
  • template_profile_below
  • template_profile_birthdate
  • template_profile_group_manage
  • template_profile_pm_settings
  • template_profile_popup
  • template_profile_save
  • template_profile_signature_modify
  • template_profile_smiley_pick
  • template_profile_tfa
  • template_profile_theme_pick
  • template_profile_theme_settings
  • template_profile_timeformat_modify
  • template_prune
  • template_quickbuttons
  • template_quickreply
  • template_quotefast
  • template_recent
  • template_redirect_options
  • template_registration_agreement
  • template_registration_form
  • template_reminder_pick
  • template_repair_boards
  • template_replies
  • template_report_message
  • template_report_message_complete
  • template_report_type
  • template_reported_members
  • template_reported_members_block
  • template_reported_posts
  • template_reported_posts_block
  • template_reported_users_block
  • template_resend
  • template_reset_list
  • template_results
  • template_retry_activate
  • template_rules
  • template_search
  • template_search_members
  • template_search_results
  • template_select
  • template_select_search_method
  • template_send
  • template_sendbody
  • template_sent
  • template_serialize_json
  • template_serialize_json_xml
  • template_servers
  • template_set_options
  • template_set_password
  • template_set_settings
  • template_setorder
  • template_settings
  • template_show_backtrace
  • template_show_custom_profile
  • template_show_file
  • template_show_list
  • template_show_month_grid
  • template_show_notice
  • template_show_settings
  • template_show_spider_logs
  • template_show_spider_stats
  • template_show_upcoming_list
  • template_show_week_grid
  • template_showAlerts
  • template_showDrafts
  • template_showPermissions
  • template_showPMDrafts
  • template_showPosts
  • template_single_pm
  • template_single_post
  • template_spellcheck
  • template_spider_edit
  • template_split
  • template_ssi_above
  • template_ssi_below
  • template_statPanel
  • template_stats
  • template_subject_list
  • template_summary
  • template_terms
  • template_tfadisable
  • template_tfasetup
  • template_tfasetup_backup
  • template_thetime
  • template_topic_legend
  • template_trackActivity
  • template_trackIP
  • template_unapproved_posts
  • template_unread
  • template_upgrade_above
  • template_upgrade_below
  • template_upgrade_complete
  • template_upgrade_options
  • template_user_subscription
  • template_user_watch_post_callback
  • template_verification_sound
  • template_view_operations
  • template_view_package
  • template_view_scheduled_tasks
  • template_view_versions
  • template_viewmemberreport
  • template_viewmodreport
  • template_viewWarning
  • template_warn_template
  • template_warning
  • template_warning_divs
  • template_watched_users
  • template_welcome_message
  • template_xml_above
  • template_xml_below
  • TestMailSend
  • text2words
  • textfield_alter
  • tfadisable
  • tfasetup
  • theme
  • theme_copyright
  • theme_inline_permissions
  • theme_install
  • theme_linktree
  • ThemeAdmin
  • ThemeInstall
  • ThemeList
  • ThemesMain
  • throw_error
  • time_since
  • timeformat
  • TopicNotify
  • trackActivity
  • trackEdits
  • trackGroupReq
  • tracking
  • TrackIP
  • TrackLogins
  • trackStats
  • trackStatsUsersOnline
  • TransferAttachments
  • truncate_array
  • un_htmlspecialchars
  • un_preparsecode
  • UnapprovedAttachments
  • UnapprovedPosts
  • unescapestring__recursive
  • UnreadTopics
  • updateAdminPreferences
  • updateBanGroup
  • updateBanMembers
  • updateBoardManagers
  • updateChildPermissions
  • updateDbLastError
  • updateLastMessages
  • updateMemberData
  • updateReport
  • updateSettings
  • updateSettingsFile
  • updateStats
  • updateTriggers
  • upgrade_clean_cache
  • upgrade_query
  • upgradeExit
  • upgradeGetColumnInfo
  • UpgradeOptions
  • url_exists
  • url_image_size
  • url_parts
  • url_to_iri
  • urldecode__recursive
  • user_info_callback
  • utf8_strtolower
  • utf8_strtoupper
  • validate_iri
  • validateEventPost
  • validatePassword
  • validatePasswordFlood
  • validateSession
  • validateToken
  • validateTriggers
  • validateUsername
  • VerificationCode
  • VersionDetail
  • ViewBacktrace
  • ViewErrorLog
  • ViewFile
  • ViewMemberlist
  • ViewMembers
  • ViewModlog
  • ViewOperations
  • ViewQuery
  • ViewSpiders
  • ViewSubscribedUsers
  • ViewSubscriptions
  • viewWarning
  • ViewWarningLog
  • ViewWarnings
  • ViewWarningTemplates
  • ViewWatchedUsers
  • Vote
  • warning_preview
  • Welcome
  • WelcomeLogin
  • Who
  • WrapAction
  • writeLog
  • XmlDraft
  • XMLhttpMain
  • Overview
  • Namespace
  • Class
   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:  802:  803:  804:  805:  806:  807:  808:  809:  810:  811:  812:  813:  814:  815:  816:  817:  818:  819:  820:  821:  822:  823:  824:  825:  826:  827:  828:  829:  830:  831:  832:  833:  834:  835:  836:  837:  838:  839:  840:  841:  842:  843:  844:  845:  846:  847:  848:  849:  850:  851:  852:  853:  854:  855:  856:  857:  858:  859:  860:  861:  862:  863:  864:  865:  866:  867:  868:  869:  870:  871:  872:  873:  874:  875:  876:  877:  878:  879:  880:  881:  882:  883:  884:  885:  886:  887:  888:  889:  890:  891:  892:  893:  894:  895:  896:  897:  898:  899:  900:  901:  902:  903:  904:  905:  906:  907:  908:  909:  910:  911:  912:  913:  914:  915:  916:  917:  918:  919:  920:  921:  922:  923:  924:  925:  926:  927:  928:  929:  930:  931:  932:  933:  934:  935:  936:  937:  938:  939:  940:  941:  942:  943:  944:  945:  946:  947:  948:  949:  950:  951:  952:  953:  954:  955:  956:  957:  958:  959:  960:  961:  962:  963:  964:  965:  966:  967:  968:  969:  970:  971:  972:  973:  974:  975:  976:  977:  978:  979:  980:  981:  982:  983:  984:  985:  986:  987:  988:  989:  990:  991:  992:  993:  994:  995:  996:  997:  998:  999: 1000: 1001: 1002: 1003: 1004: 1005: 1006: 1007: 1008: 1009: 1010: 1011: 1012: 1013: 1014: 1015: 1016: 1017: 1018: 1019: 1020: 1021: 1022: 1023: 1024: 1025: 1026: 1027: 1028: 1029: 1030: 1031: 1032: 1033: 1034: 1035: 1036: 1037: 1038: 1039: 1040: 1041: 1042: 1043: 1044: 1045: 1046: 1047: 1048: 1049: 1050: 1051: 1052: 1053: 1054: 1055: 1056: 1057: 1058: 1059: 1060: 1061: 1062: 1063: 1064: 1065: 1066: 1067: 1068: 1069: 1070: 1071: 1072: 1073: 1074: 1075: 1076: 1077: 1078: 1079: 1080: 1081: 1082: 1083: 1084: 1085: 1086: 1087: 1088: 1089: 1090: 1091: 1092: 1093: 1094: 1095: 1096: 1097: 1098: 1099: 1100: 1101: 1102: 1103: 1104: 1105: 1106: 1107: 1108: 1109: 1110: 1111: 1112: 1113: 1114: 1115: 1116: 1117: 1118: 1119: 1120: 1121: 1122: 1123: 1124: 1125: 1126: 1127: 1128: 1129: 1130: 1131: 1132: 1133: 1134: 1135: 1136: 1137: 1138: 1139: 1140: 1141: 1142: 1143: 1144: 1145: 1146: 1147: 1148: 1149: 1150: 1151: 1152: 1153: 1154: 1155: 1156: 1157: 1158: 1159: 1160: 1161: 1162: 1163: 1164: 1165: 1166: 1167: 1168: 1169: 1170: 1171: 1172: 1173: 1174: 1175: 1176: 1177: 1178: 1179: 1180: 1181: 1182: 1183: 1184: 1185: 1186: 1187: 1188: 1189: 1190: 1191: 1192: 1193: 1194: 1195: 1196: 1197: 1198: 1199: 1200: 1201: 1202: 1203: 1204: 1205: 1206: 1207: 1208: 1209: 1210: 1211: 1212: 1213: 1214: 1215: 1216: 1217: 1218: 1219: 1220: 1221: 1222: 1223: 1224: 1225: 1226: 1227: 1228: 1229: 1230: 1231: 1232: 1233: 1234: 1235: 1236: 1237: 1238: 1239: 1240: 1241: 1242: 1243: 1244: 1245: 1246: 1247: 1248: 1249: 1250: 1251: 1252: 1253: 1254: 1255: 1256: 1257: 1258: 1259: 1260: 1261: 1262: 1263: 1264: 1265: 1266: 1267: 1268: 1269: 1270: 1271: 1272: 1273: 1274: 1275: 1276: 1277: 1278: 1279: 1280: 1281: 1282: 1283: 1284: 1285: 1286: 1287: 1288: 1289: 1290: 1291: 1292: 1293: 1294: 1295: 1296: 1297: 1298: 1299: 1300: 1301: 1302: 1303: 1304: 1305: 1306: 1307: 1308: 1309: 1310: 1311: 1312: 1313: 1314: 1315: 1316: 1317: 1318: 1319: 1320: 1321: 1322: 1323: 1324: 1325: 1326: 1327: 1328: 1329: 1330: 1331: 1332: 1333: 1334: 1335: 1336: 1337: 1338: 1339: 1340: 1341: 1342: 1343: 1344: 1345: 1346: 1347: 1348: 1349: 1350: 1351: 1352: 1353: 1354: 1355: 1356: 1357: 1358: 1359: 1360: 1361: 1362: 1363: 1364: 1365: 1366: 1367: 1368: 1369: 1370: 1371: 1372: 1373: 1374: 1375: 1376: 1377: 1378: 1379: 1380: 1381: 1382: 1383: 1384: 1385: 1386: 1387: 1388: 1389: 1390: 1391: 1392: 1393: 1394: 1395: 1396: 1397: 1398: 1399: 1400: 1401: 1402: 1403: 1404: 1405: 1406: 1407: 1408: 1409: 1410: 1411: 1412: 1413: 1414: 1415: 1416: 1417: 1418: 1419: 1420: 1421: 1422: 1423: 1424: 1425: 1426: 1427: 1428: 1429: 1430: 1431: 1432: 1433: 1434: 1435: 1436: 1437: 1438: 1439: 1440: 1441: 1442: 1443: 1444: 1445: 1446: 1447: 1448: 1449: 1450: 1451: 1452: 1453: 1454: 1455: 1456: 1457: 1458: 1459: 1460: 1461: 1462: 1463: 1464: 1465: 1466: 1467: 1468: 1469: 1470: 1471: 1472: 1473: 1474: 1475: 1476: 1477: 1478: 1479: 1480: 1481: 1482: 1483: 1484: 1485: 1486: 1487: 1488: 1489: 1490: 1491: 1492: 1493: 1494: 1495: 1496: 1497: 1498: 1499: 1500: 1501: 1502: 1503: 1504: 1505: 1506: 1507: 1508: 1509: 1510: 1511: 1512: 1513: 1514: 1515: 1516: 1517: 1518: 1519: 1520: 1521: 1522: 1523: 1524: 1525: 1526: 1527: 1528: 1529: 1530: 1531: 1532: 1533: 1534: 1535: 1536: 1537: 1538: 1539: 1540: 1541: 1542: 1543: 1544: 1545: 1546: 1547: 1548: 1549: 1550: 1551: 1552: 1553: 1554: 1555: 1556: 1557: 1558: 1559: 1560: 1561: 1562: 1563: 1564: 1565: 1566: 1567: 1568: 1569: 1570: 1571: 1572: 1573: 1574: 1575: 1576: 1577: 1578: 1579: 1580: 1581: 1582: 1583: 1584: 1585: 1586: 1587: 1588: 1589: 1590: 1591: 1592: 1593: 1594: 1595: 1596: 1597: 1598: 1599: 1600: 1601: 1602: 1603: 1604: 1605: 1606: 1607: 1608: 1609: 1610: 1611: 1612: 1613: 1614: 1615: 1616: 1617: 1618: 1619: 1620: 1621: 1622: 1623: 1624: 1625: 1626: 1627: 1628: 1629: 1630: 1631: 1632: 1633: 1634: 1635: 1636: 1637: 1638: 1639: 1640: 1641: 1642: 1643: 1644: 1645: 1646: 1647: 1648: 1649: 1650: 1651: 1652: 1653: 1654: 1655: 1656: 1657: 1658: 1659: 1660: 1661: 1662: 1663: 1664: 1665: 1666: 1667: 1668: 1669: 1670: 1671: 1672: 1673: 1674: 1675: 1676: 1677: 1678: 1679: 1680: 1681: 1682: 1683: 1684: 1685: 1686: 1687: 1688: 1689: 1690: 1691: 1692: 1693: 1694: 1695: 1696: 1697: 1698: 1699: 1700: 1701: 1702: 1703: 1704: 1705: 1706: 1707: 1708: 1709: 1710: 1711: 1712: 1713: 1714: 1715: 1716: 1717: 1718: 1719: 1720: 1721: 1722: 1723: 1724: 1725: 1726: 1727: 1728: 1729: 1730: 1731: 1732: 1733: 1734: 1735: 1736: 1737: 1738: 1739: 1740: 1741: 1742: 1743: 1744: 1745: 1746: 1747: 1748: 1749: 1750: 1751: 1752: 1753: 1754: 1755: 1756: 1757: 1758: 1759: 1760: 1761: 1762: 1763: 1764: 1765: 1766: 1767: 1768: 1769: 1770: 1771: 1772: 1773: 1774: 1775: 1776: 1777: 1778: 1779: 1780: 1781: 1782: 1783: 1784: 1785: 1786: 1787: 1788: 1789: 1790: 1791: 1792: 1793: 1794: 1795: 1796: 1797: 1798: 1799: 1800: 1801: 1802: 1803: 1804: 1805: 1806: 1807: 1808: 1809: 1810: 1811: 1812: 1813: 1814: 1815: 1816: 1817: 1818: 1819: 1820: 1821: 1822: 1823: 1824: 1825: 1826: 1827: 1828: 1829: 1830: 1831: 1832: 1833: 1834: 1835: 1836: 1837: 1838: 1839: 1840: 1841: 1842: 1843: 1844: 1845: 1846: 1847: 1848: 1849: 1850: 1851: 1852: 1853: 1854: 1855: 1856: 1857: 1858: 1859: 1860: 1861: 1862: 1863: 1864: 1865: 1866: 1867: 1868: 1869: 1870: 1871: 1872: 1873: 1874: 1875: 1876: 1877: 1878: 1879: 1880: 1881: 1882: 1883: 1884: 1885: 1886: 1887: 1888: 1889: 1890: 1891: 1892: 1893: 1894: 1895: 1896: 1897: 1898: 1899: 1900: 1901: 1902: 1903: 1904: 1905: 1906: 1907: 1908: 1909: 1910: 1911: 1912: 1913: 1914: 1915: 1916: 1917: 1918: 1919: 1920: 1921: 1922: 1923: 1924: 1925: 1926: 1927: 1928: 1929: 1930: 1931: 1932: 1933: 1934: 1935: 1936: 1937: 1938: 1939: 1940: 1941: 1942: 1943: 1944: 1945: 1946: 1947: 1948: 1949: 1950: 1951: 1952: 1953: 1954: 1955: 1956: 1957: 1958: 1959: 1960: 1961: 1962: 1963: 1964: 1965: 1966: 1967: 1968: 1969: 1970: 1971: 1972: 1973: 1974: 1975: 1976: 1977: 1978: 1979: 1980: 1981: 1982: 1983: 1984: 1985: 1986: 1987: 1988: 1989: 1990: 1991: 1992: 1993: 1994: 1995: 1996: 1997: 1998: 1999: 2000: 2001: 2002: 2003: 2004: 2005: 2006: 2007: 2008: 2009: 2010: 2011: 2012: 2013: 2014: 2015: 2016: 2017: 2018: 2019: 2020: 2021: 2022: 2023: 2024: 2025: 2026: 2027: 2028: 2029: 2030: 2031: 2032: 2033: 2034: 2035: 2036: 2037: 2038: 2039: 2040: 2041: 2042: 2043: 2044: 2045: 2046: 2047: 2048: 2049: 2050: 2051: 2052: 2053: 2054: 2055: 2056: 2057: 2058: 2059: 2060: 2061: 2062: 2063: 2064: 2065: 2066: 2067: 2068: 2069: 2070: 2071: 2072: 2073: 2074: 2075: 2076: 2077: 2078: 2079: 2080: 2081: 2082: 2083: 2084: 2085: 2086: 2087: 2088: 2089: 2090: 2091: 2092: 2093: 2094: 2095: 2096: 2097: 2098: 2099: 2100: 2101: 2102: 2103: 2104: 2105: 2106: 2107: 2108: 2109: 2110: 2111: 2112: 2113: 2114: 2115: 2116: 2117: 2118: 2119: 2120: 2121: 2122: 2123: 2124: 2125: 2126: 2127: 2128: 2129: 2130: 2131: 2132: 2133: 2134: 2135: 2136: 2137: 2138: 2139: 2140: 2141: 2142: 2143: 2144: 2145: 2146: 2147: 2148: 2149: 2150: 2151: 2152: 2153: 2154: 2155: 2156: 2157: 2158: 2159: 2160: 2161: 2162: 2163: 2164: 2165: 2166: 2167: 2168: 2169: 2170: 2171: 2172: 2173: 2174: 2175: 2176: 2177: 2178: 2179: 2180: 2181: 2182: 2183: 2184: 2185: 2186: 2187: 2188: 2189: 2190: 2191: 2192: 2193: 2194: 2195: 2196: 2197: 2198: 2199: 2200: 2201: 2202: 2203: 2204: 2205: 2206: 2207: 2208: 2209: 2210: 2211: 2212: 2213: 2214: 2215: 2216: 2217: 2218: 2219: 2220: 2221: 2222: 2223: 2224: 2225: 2226: 2227: 2228: 2229: 2230: 2231: 2232: 2233: 2234: 2235: 2236: 2237: 2238: 2239: 2240: 2241: 2242: 2243: 2244: 2245: 2246: 2247: 2248: 2249: 2250: 2251: 2252: 2253: 2254: 2255: 2256: 2257: 2258: 2259: 2260: 2261: 2262: 2263: 2264: 2265: 2266: 2267: 2268: 2269: 2270: 2271: 2272: 2273: 2274: 2275: 2276: 2277: 2278: 2279: 2280: 2281: 2282: 2283: 2284: 2285: 2286: 2287: 2288: 2289: 2290: 2291: 2292: 2293: 2294: 2295: 2296: 2297: 2298: 2299: 2300: 2301: 2302: 2303: 2304: 2305: 2306: 2307: 2308: 2309: 2310: 2311: 2312: 2313: 2314: 2315: 2316: 2317: 2318: 2319: 2320: 2321: 2322: 2323: 2324: 2325: 2326: 2327: 2328: 2329: 2330: 2331: 2332: 2333: 2334: 2335: 2336: 2337: 2338: 2339: 2340: 2341: 2342: 2343: 2344: 2345: 2346: 2347: 2348: 2349: 2350: 2351: 2352: 2353: 2354: 2355: 2356: 2357: 2358: 2359: 2360: 2361: 2362: 2363: 2364: 2365: 2366: 2367: 2368: 2369: 2370: 2371: 2372: 2373: 2374: 2375: 2376: 2377: 2378: 2379: 2380: 2381: 2382: 2383: 2384: 2385: 2386: 2387: 2388: 2389: 2390: 2391: 2392: 2393: 2394: 2395: 2396: 2397: 2398: 2399: 2400: 2401: 2402: 2403: 2404: 2405: 2406: 2407: 2408: 2409: 2410: 2411: 2412: 2413: 2414: 2415: 2416: 2417: 2418: 2419: 2420: 2421: 2422: 2423: 2424: 2425: 2426: 2427: 2428: 2429: 2430: 2431: 2432: 2433: 2434: 2435: 2436: 2437: 2438: 2439: 2440: 2441: 2442: 2443: 2444: 2445: 2446: 2447: 2448: 2449: 2450: 2451: 2452: 2453: 2454: 2455: 2456: 2457: 2458: 2459: 2460: 2461: 2462: 2463: 2464: 2465: 2466: 2467: 2468: 2469: 2470: 2471: 2472: 2473: 2474: 2475: 2476: 2477: 2478: 2479: 2480: 2481: 2482: 2483: 2484: 2485: 2486: 2487: 2488: 2489: 2490: 2491: 2492: 2493: 2494: 2495: 2496: 2497: 2498: 2499: 2500: 2501: 2502: 2503: 2504: 2505: 2506: 2507: 2508: 2509: 2510: 2511: 2512: 2513: 2514: 2515: 2516: 2517: 2518: 2519: 2520: 2521: 2522: 2523: 2524: 2525: 2526: 2527: 2528: 2529: 2530: 2531: 2532: 2533: 2534: 2535: 2536: 2537: 2538: 2539: 2540: 2541: 2542: 2543: 2544: 2545: 2546: 2547: 2548: 2549: 2550: 2551: 2552: 2553: 2554: 2555: 2556: 2557: 2558: 2559: 2560: 2561: 2562: 2563: 2564: 2565: 2566: 2567: 2568: 2569: 2570: 2571: 2572: 2573: 2574: 2575: 2576: 2577: 2578: 2579: 2580: 2581: 2582: 2583: 2584: 2585: 2586: 2587: 2588: 2589: 2590: 2591: 2592: 2593: 2594: 2595: 2596: 2597: 2598: 2599: 2600: 2601: 2602: 2603: 2604: 2605: 2606: 2607: 2608: 2609: 2610: 2611: 2612: 2613: 2614: 2615: 2616: 2617: 2618: 2619: 2620: 2621: 2622: 2623: 2624: 2625: 2626: 2627: 2628: 2629: 2630: 2631: 2632: 2633: 2634: 2635: 2636: 2637: 2638: 2639: 2640: 2641: 2642: 2643: 2644: 2645: 2646: 2647: 2648: 2649: 2650: 2651: 2652: 2653: 2654: 2655: 2656: 2657: 2658: 2659: 2660: 2661: 2662: 2663: 2664: 2665: 2666: 2667: 2668: 2669: 2670: 2671: 2672: 2673: 2674: 2675: 2676: 2677: 2678: 2679: 2680: 2681: 2682: 2683: 2684: 2685: 2686: 2687: 2688: 2689: 2690: 2691: 2692: 2693: 2694: 2695: 2696: 2697: 2698: 2699: 2700: 2701: 2702: 2703: 2704: 2705: 2706: 2707: 2708: 2709: 2710: 2711: 2712: 2713: 2714: 2715: 2716: 2717: 2718: 2719: 2720: 2721: 2722: 2723: 2724: 2725: 2726: 2727: 2728: 2729: 2730: 2731: 2732: 2733: 2734: 2735: 2736: 2737: 2738: 2739: 2740: 2741: 2742: 2743: 2744: 2745: 2746: 2747: 2748: 2749: 2750: 2751: 2752: 2753: 2754: 2755: 2756: 2757: 2758: 2759: 2760: 2761: 2762: 2763: 2764: 2765: 2766: 2767: 2768: 2769: 2770: 2771: 2772: 2773: 2774: 2775: 2776: 2777: 2778: 2779: 2780: 2781: 2782: 2783: 2784: 2785: 2786: 2787: 2788: 2789: 2790: 2791: 2792: 2793: 2794: 2795: 2796: 2797: 2798: 2799: 2800: 2801: 2802: 2803: 2804: 2805: 2806: 2807: 2808: 2809: 2810: 2811: 2812: 2813: 2814: 2815: 2816: 2817: 2818: 2819: 2820: 2821: 2822: 2823: 2824: 2825: 2826: 2827: 2828: 2829: 2830: 2831: 2832: 2833: 2834: 2835: 2836: 2837: 2838: 2839: 2840: 2841: 2842: 2843: 2844: 2845: 2846: 2847: 2848: 2849: 2850: 2851: 2852: 2853: 2854: 2855: 2856: 2857: 2858: 2859: 2860: 2861: 2862: 2863: 2864: 2865: 2866: 2867: 2868: 2869: 2870: 2871: 2872: 2873: 2874: 2875: 2876: 2877: 2878: 2879: 2880: 2881: 2882: 2883: 2884: 2885: 2886: 2887: 2888: 2889: 2890: 2891: 2892: 2893: 2894: 2895: 2896: 2897: 2898: 2899: 2900: 2901: 2902: 2903: 2904: 2905: 2906: 2907: 2908: 2909: 2910: 2911: 2912: 2913: 2914: 2915: 2916: 2917: 2918: 2919: 2920: 2921: 2922: 2923: 2924: 2925: 2926: 2927: 2928: 2929: 2930: 2931: 2932: 2933: 2934: 2935: 2936: 2937: 2938: 2939: 2940: 2941: 2942: 2943: 2944: 2945: 2946: 2947: 2948: 2949: 2950: 2951: 2952: 2953: 2954: 2955: 2956: 2957: 2958: 2959: 2960: 2961: 2962: 2963: 2964: 2965: 2966: 2967: 2968: 2969: 2970: 2971: 2972: 2973: 2974: 2975: 2976: 2977: 2978: 2979: 2980: 2981: 2982: 2983: 2984: 2985: 2986: 2987: 2988: 2989: 2990: 2991: 2992: 2993: 2994: 2995: 2996: 2997: 2998: 2999: 3000: 3001: 3002: 3003: 3004: 3005: 3006: 3007: 3008: 3009: 3010: 3011: 3012: 3013: 3014: 3015: 3016: 3017: 3018: 3019: 3020: 3021: 3022: 3023: 3024: 3025: 3026: 3027: 3028: 3029: 3030: 3031: 3032: 3033: 3034: 3035: 3036: 3037: 3038: 3039: 3040: 3041: 3042: 3043: 3044: 3045: 3046: 3047: 3048: 3049: 3050: 3051: 3052: 3053: 3054: 3055: 3056: 3057: 3058: 3059: 3060: 3061: 3062: 3063: 3064: 3065: 3066: 3067: 3068: 3069: 3070: 3071: 3072: 3073: 3074: 3075: 3076: 3077: 3078: 3079: 3080: 3081: 3082: 3083: 3084: 3085: 3086: 3087: 3088: 3089: 3090: 3091: 3092: 3093: 3094: 3095: 3096: 3097: 3098: 3099: 3100: 3101: 3102: 3103: 3104: 3105: 3106: 3107: 3108: 3109: 3110: 3111: 3112: 3113: 3114: 3115: 3116: 3117: 3118: 3119: 3120: 3121: 3122: 3123: 3124: 3125: 3126: 3127: 3128: 3129: 3130: 3131: 3132: 3133: 3134: 3135: 3136: 3137: 3138: 3139: 3140: 3141: 3142: 3143: 3144: 3145: 3146: 3147: 3148: 3149: 3150: 3151: 3152: 3153: 3154: 3155: 3156: 3157: 3158: 3159: 3160: 3161: 3162: 3163: 3164: 3165: 3166: 3167: 3168: 3169: 3170: 3171: 3172: 3173: 3174: 3175: 3176: 3177: 3178: 3179: 3180: 3181: 3182: 3183: 3184: 3185: 3186: 3187: 3188: 3189: 3190: 3191: 3192: 3193: 3194: 3195: 3196: 3197: 3198: 3199: 3200: 3201: 3202: 3203: 3204: 3205: 3206: 3207: 3208: 3209: 3210: 3211: 3212: 3213: 3214: 3215: 3216: 3217: 3218: 3219: 3220: 3221: 3222: 3223: 3224: 3225: 3226: 3227: 3228: 3229: 3230: 3231: 3232: 3233: 3234: 3235: 3236: 3237: 3238: 3239: 3240: 3241: 3242: 3243: 3244: 3245: 3246: 3247: 3248: 3249: 3250: 3251: 3252: 3253: 3254: 3255: 3256: 3257: 3258: 3259: 3260: 3261: 3262: 3263: 3264: 3265: 3266: 3267: 3268: 3269: 3270: 3271: 3272: 3273: 3274: 3275: 3276: 3277: 3278: 3279: 3280: 3281: 3282: 3283: 3284: 3285: 3286: 3287: 3288: 3289: 3290: 3291: 3292: 3293: 3294: 3295: 3296: 3297: 3298: 3299: 3300: 3301: 3302: 3303: 3304: 3305: 3306: 3307: 3308: 3309: 3310: 3311: 3312: 3313: 3314: 3315: 3316: 3317: 3318: 3319: 3320: 3321: 3322: 3323: 3324: 3325: 3326: 3327: 3328: 3329: 3330: 3331: 3332: 3333: 3334: 3335: 3336: 3337: 3338: 3339: 3340: 3341: 3342: 3343: 3344: 3345: 3346: 3347: 3348: 3349: 3350: 3351: 3352: 3353: 3354: 3355: 3356: 3357: 3358: 3359: 3360: 3361: 3362: 3363: 3364: 3365: 3366: 3367: 3368: 3369: 3370: 3371: 3372: 3373: 3374: 3375: 3376: 3377: 3378: 3379: 3380: 3381: 3382: 3383: 3384: 3385: 3386: 3387: 3388: 3389: 3390: 3391: 3392: 3393: 3394: 3395: 3396: 3397: 3398: 3399: 3400: 3401: 3402: 3403: 3404: 3405: 3406: 3407: 3408: 3409: 3410: 3411: 3412: 3413: 3414: 3415: 3416: 3417: 3418: 3419: 3420: 3421: 3422: 3423: 3424: 3425: 3426: 3427: 3428: 3429: 3430: 3431: 3432: 3433: 3434: 3435: 3436: 3437: 3438: 3439: 3440: 3441: 3442: 3443: 3444: 3445: 3446: 3447: 3448: 3449: 3450: 3451: 3452: 3453: 3454: 3455: 3456: 3457: 3458: 3459: 3460: 3461: 3462: 3463: 3464: 3465: 3466: 3467: 3468: 3469: 3470: 3471: 3472: 3473: 3474: 3475: 3476: 3477: 3478: 3479: 3480: 3481: 3482: 3483: 3484: 3485: 3486: 3487: 3488: 3489: 3490: 
<?php

/**
 * Simple Machines Forum (SMF)
 *
 * @package SMF
 * @author Simple Machines https://www.simplemachines.org
 * @copyright 2020 Simple Machines and individual contributors
 * @license https://www.simplemachines.org/about/smf/license.php BSD
 *
 * @version 2.1 RC2
 */

if (!defined('SMF'))
    die('No direct access...');

/**
 * View a summary.
 *
 * @param int $memID The ID of the member
 */
function summary($memID)
{
    global $context, $memberContext, $txt, $modSettings, $user_profile, $sourcedir, $scripturl, $smcFunc;

    // Attempt to load the member's profile data.
    if (!loadMemberContext($memID) || !isset($memberContext[$memID]))
        fatal_lang_error('not_a_user', false, 404);

    // Set up the stuff and load the user.
    $context += array(
        'page_title' => sprintf($txt['profile_of_username'], $memberContext[$memID]['name']),
        'can_send_pm' => allowedTo('pm_send'),
        'can_have_buddy' => allowedTo('profile_extra_own') && !empty($modSettings['enable_buddylist']),
        'can_issue_warning' => allowedTo('issue_warning') && $modSettings['warning_settings'][0] == 1,
        'can_view_warning' => (allowedTo('moderate_forum') || allowedTo('issue_warning') || allowedTo('view_warning_any') || ($context['user']['is_owner'] && allowedTo('view_warning_own')) && $modSettings['warning_settings'][0] === 1)
    );
    $context['member'] = &$memberContext[$memID];

    // Set a canonical URL for this page.
    $context['canonical_url'] = $scripturl . '?action=profile;u=' . $memID;

    // Are there things we don't show?
    $context['disabled_fields'] = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array();
    // Menu tab
    $context[$context['profile_menu_name']]['tab_data'] = array(
        'title' => $txt['summary'],
        'icon' => 'profile_hd.png'
    );

    // See if they have broken any warning levels...
    list ($modSettings['warning_enable'], $modSettings['user_limit']) = explode(',', $modSettings['warning_settings']);
    if (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $context['member']['warning'])
        $context['warning_status'] = $txt['profile_warning_is_muted'];
    elseif (!empty($modSettings['warning_moderate']) && $modSettings['warning_moderate'] <= $context['member']['warning'])
        $context['warning_status'] = $txt['profile_warning_is_moderation'];
    elseif (!empty($modSettings['warning_watch']) && $modSettings['warning_watch'] <= $context['member']['warning'])
        $context['warning_status'] = $txt['profile_warning_is_watch'];

    // They haven't even been registered for a full day!?
    $days_registered = (int) ((time() - $user_profile[$memID]['date_registered']) / (3600 * 24));
    if (empty($user_profile[$memID]['date_registered']) || $days_registered < 1)
        $context['member']['posts_per_day'] = $txt['not_applicable'];
    else
        $context['member']['posts_per_day'] = comma_format($context['member']['real_posts'] / $days_registered, 3);

    // Set the age...
    if (empty($context['member']['birth_date']) || substr($context['member']['birth_date'], 0, 4) < 1002)
    {
        $context['member'] += array(
            'age' => $txt['not_applicable'],
            'today_is_birthday' => false
        );
    }
    else
    {
        list ($birth_year, $birth_month, $birth_day) = sscanf($context['member']['birth_date'], '%d-%d-%d');
        $datearray = getdate(forum_time());
        $context['member'] += array(
            'age' => $birth_year <= 1004 ? $txt['not_applicable'] : $datearray['year'] - $birth_year - (($datearray['mon'] > $birth_month || ($datearray['mon'] == $birth_month && $datearray['mday'] >= $birth_day)) ? 0 : 1),
            'today_is_birthday' => $datearray['mon'] == $birth_month && $datearray['mday'] == $birth_day && $birth_year > 1004
        );
    }

    if (allowedTo('moderate_forum'))
    {
        // Make sure it's a valid ip address; otherwise, don't bother...
        if (preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $memberContext[$memID]['ip']) == 1 && empty($modSettings['disableHostnameLookup']))
            $context['member']['hostname'] = host_from_ip($memberContext[$memID]['ip']);
        else
            $context['member']['hostname'] = '';

        $context['can_see_ip'] = true;
    }
    else
        $context['can_see_ip'] = false;

    // Are they hidden?
    $context['member']['is_hidden'] = empty($user_profile[$memID]['show_online']);
    $context['member']['show_last_login'] = allowedTo('admin_forum') || !$context['member']['is_hidden'];

    if (!empty($modSettings['who_enabled']) && $context['member']['show_last_login'])
    {
        include_once($sourcedir . '/Who.php');
        $action = determineActions($user_profile[$memID]['url']);

        if ($action !== false)
            $context['member']['action'] = $action;
    }

    // If the user is awaiting activation, and the viewer has permission - setup some activation context messages.
    if ($context['member']['is_activated'] % 10 != 1 && allowedTo('moderate_forum'))
    {
        $context['activate_type'] = $context['member']['is_activated'];
        // What should the link text be?
        $context['activate_link_text'] = in_array($context['member']['is_activated'], array(3, 4, 5, 13, 14, 15)) ? $txt['account_approve'] : $txt['account_activate'];

        // Should we show a custom message?
        $context['activate_message'] = isset($txt['account_activate_method_' . $context['member']['is_activated'] % 10]) ? $txt['account_activate_method_' . $context['member']['is_activated'] % 10] : $txt['account_not_activated'];

        // If they can be approved, we need to set up a token for them.
        $context['token_check'] = 'profile-aa' . $memID;
        createToken($context['token_check'], 'get');

        // Puerile comment
        $context['activate_link'] = $scripturl . '?action=admin;area=viewmembers;sa=browse;type=approve;' . $context['session_var'] . '=' . $context['session_id'] . ';' . $context[$context['token_check'] . '_token_var'] . '=' . $context[$context['token_check'] . '_token'];
    }

    // Is the signature even enabled on this forum?
    $context['signature_enabled'] = substr($modSettings['signature_settings'], 0, 1) == 1;

    // Prevent signature images from going outside the box.
    if ($context['signature_enabled'])
    {
        list ($sig_limits, $sig_bbc) = explode(':', $modSettings['signature_settings']);
        $sig_limits = explode(',', $sig_limits);

        if (!empty($sig_limits[5]) || !empty($sig_limits[6]))
            addInlineCss('
    .signature img { ' . (!empty($sig_limits[5]) ? 'max-width: ' . (int) $sig_limits[5] . 'px; ' : '') . (!empty($sig_limits[6]) ? 'max-height: ' . (int) $sig_limits[6] . 'px; ' : '') . '}');
    }

    // How about, are they banned?
    $context['member']['bans'] = array();
    if (allowedTo('moderate_forum'))
    {
        // Can they edit the ban?
        $context['can_edit_ban'] = allowedTo('manage_bans');

        $ban_query = array();
        $ban_query_vars = array(
            'time' => time(),
        );
        $ban_query[] = 'id_member = ' . $context['member']['id'];
        $ban_query[] = ' {inet:ip} BETWEEN bi.ip_low and bi.ip_high';
        $ban_query_vars['ip'] = $memberContext[$memID]['ip'];
        // Do we have a hostname already?
        if (!empty($context['member']['hostname']))
        {
            $ban_query[] = '({string:hostname} LIKE hostname)';
            $ban_query_vars['hostname'] = $context['member']['hostname'];
        }
        // Check their email as well...
        if (strlen($context['member']['email']) != 0)
        {
            $ban_query[] = '({string:email} LIKE bi.email_address)';
            $ban_query_vars['email'] = $context['member']['email'];
        }

        // So... are they banned?  Dying to know!
        $request = $smcFunc['db_query']('', '
            SELECT bg.id_ban_group, bg.name, bg.cannot_access, bg.cannot_post,
                bg.cannot_login, bg.reason
            FROM {db_prefix}ban_items AS bi
                INNER JOIN {db_prefix}ban_groups AS bg ON (bg.id_ban_group = bi.id_ban_group AND (bg.expire_time IS NULL OR bg.expire_time > {int:time}))
            WHERE (' . implode(' OR ', $ban_query) . ')',
            $ban_query_vars
        );
        while ($row = $smcFunc['db_fetch_assoc']($request))
        {
            // Work out what restrictions we actually have.
            $ban_restrictions = array();
            foreach (array('access', 'login', 'post') as $type)
                if ($row['cannot_' . $type])
                    $ban_restrictions[] = $txt['ban_type_' . $type];

            // No actual ban in place?
            if (empty($ban_restrictions))
                continue;

            // Prepare the link for context.
            $ban_explanation = sprintf($txt['user_cannot_due_to'], implode(', ', $ban_restrictions), '<a href="' . $scripturl . '?action=admin;area=ban;sa=edit;bg=' . $row['id_ban_group'] . '">' . $row['name'] . '</a>');

            $context['member']['bans'][$row['id_ban_group']] = array(
                'reason' => empty($row['reason']) ? '' : '<br><br><strong>' . $txt['ban_reason'] . ':</strong> ' . $row['reason'],
                'cannot' => array(
                    'access' => !empty($row['cannot_access']),
                    'post' => !empty($row['cannot_post']),
                    'login' => !empty($row['cannot_login']),
                ),
                'explanation' => $ban_explanation,
            );
        }
        $smcFunc['db_free_result']($request);
    }
    loadCustomFields($memID);

    $context['print_custom_fields'] = array();

    // Any custom profile fields?
    if (!empty($context['custom_fields']))
        foreach ($context['custom_fields'] as $custom)
            $context['print_custom_fields'][$context['cust_profile_fields_placement'][$custom['placement']]][] = $custom;

}

/**
 * Fetch the alerts a member currently has.
 *
 * @param int $memID The ID of the member.
 * @param mixed $to_fetch Alerts to fetch: true/false for all/unread, or a list of one or more IDs.
 * @param array $limit Maximum number of alerts to fetch (0 for no limit).
 * @param array $offset Number of alerts to skip for pagination. Ignored if $to_fetch is a list of IDs.
 * @param bool $with_avatar Whether to load the avatar of the alert sender.
 * @param bool $show_links Whether to show links in the constituent parts of the alert meessage.
 * @return array An array of information about the fetched alerts.
 */
function fetch_alerts($memID, $to_fetch = false, $limit = 0, $offset = 0, $with_avatar = false, $show_links = false)
{
    global $smcFunc, $txt, $scripturl, $user_info, $user_profile, $modSettings, $context;

    // Are we being asked for some specific alerts?
    $alertIDs = is_bool($to_fetch) ? array() : array_filter(array_map('intval', (array) $to_fetch));

    // Basic sanitation.
    $memID = (int) $memID;
    $unread = $to_fetch === false;
    $limit = max(0, (int) $limit);
    $offset = !empty($alertIDs) ? 0 : max(0, (int) $offset);
    $with_avatar = !empty($with_avatar);
    $show_links = !empty($show_links);

    // Arrays we'll need.
    $alerts = array();
    $senders = array();
    $profiles = array();
    $profile_alerts = array();
    $possible_msgs = array();
    $possible_topics = array();

    // Get the basic alert info.
    $request = $smcFunc['db_query']('', '
        SELECT a.id_alert, a.alert_time, a.is_read, a.extra,
            a.content_type, a.content_id, a.content_action,
            mem.id_member AS sender_id, COALESCE(mem.real_name, a.member_name) AS sender_name' . ($with_avatar ? ',
            mem.email_address AS sender_email, mem.avatar AS sender_avatar, f.filename AS sender_filename' : '') . '
        FROM {db_prefix}user_alerts AS a
            LEFT JOIN {db_prefix}members AS mem ON (a.id_member_started = mem.id_member)' . ($with_avatar ? '
            LEFT JOIN {db_prefix}attachments AS f ON (mem.id_member = f.id_member)' : '') . '
        WHERE a.id_member = {int:id_member}' . ($unread ? '
            AND a.is_read = 0' : '') . (!empty($alertIDs) ? '
            AND a.id_alert IN ({array_int:alertIDs})' : '') . '
        ORDER BY id_alert DESC' . (!empty($limit) ? '
        LIMIT {int:limit}' : '') . (!empty($offset) ?'
        OFFSET {int:offset}' : ''),
        array(
            'id_member' => $memID,
            'alertIDs' => $alertIDs,
            'limit' => $limit,
            'offset' => $offset,
        )
    );
    while ($row = $smcFunc['db_fetch_assoc']($request))
    {
        $id_alert = array_shift($row);
        $row['time'] = timeformat($row['alert_time']);
        $row['extra'] = !empty($row['extra']) ? $smcFunc['json_decode']($row['extra'], true) : array();
        $alerts[$id_alert] = $row;

        if (!empty($row['sender_email']))
        {
            $senders[$row['sender_id']] = array(
                'email' => $row['sender_email'],
                'avatar' => $row['sender_avatar'],
                'filename' => $row['sender_filename'],
            );
        }

        if ($row['content_type'] == 'profile')
        {
            $profiles[] = $row['content_id'];
            $profile_alerts[] = $id_alert;
        }

        // For these types, we need to check whether they can actually see the content.
        if ($row['content_type'] == 'msg')
        {
            $alerts[$id_alert]['visible'] = false;
            $possible_msgs[$id_alert] = $row['content_id'];
        }
        elseif (in_array($row['content_type'], array('topic', 'board')))
        {
            $alerts[$id_alert]['visible'] = false;
            $possible_topics[$id_alert] = $row['content_id'];
        }
        // For the rest, they can always see it.
        else
            $alerts[$id_alert]['visible'] = true;

        // Are we showing multiple links or one big main link ?
        $alerts[$id_alert]['show_links'] = $show_links || (isset($row['extra']['show_links']) && $row['extra']['show_links']);

        // Set an appropriate icon.
        $alerts[$id_alert]['icon'] = set_alert_icon($alerts[$id_alert]);
    }
    $smcFunc['db_free_result']($request);

    // Look up member info of anyone we need it for.
    if (!empty($profiles))
        loadMemberData($profiles, 'minimal');

    // Get the senders' avatars.
    if ($with_avatar)
    {
        foreach ($senders as $sender_id => $sender)
            $senders[$sender_id]['avatar'] = set_avatar_data($sender);

        $context['avatar_url'] = $modSettings['avatar_url'];
    }

    // Now go through and actually make with the text.
    loadLanguage('Alerts');

    // Some sprintf formats for generating links/strings.
    // 'required' is an array of keys in $alert['extra'] that should be used to generate the message, ordered to match the sprintf formats.
    // 'link' and 'text' are the sprintf formats that will be used when $alert['show_links'] is true or false, respectively.
    $formats['msg_msg'] = array(
        'required' => array('content_subject', 'topic', 'msg'),
        'link' => '<a href="{scripturl}?topic=%2$d.msg%3$d#msg%3$d">%1$s</a>',
        'text' => '<strong>%1$s</strong>',
    );
    $formats['topic_msg'] = array(
        'required' => array('content_subject', 'topic', 'topic_suffix'),
        'link' => '<a href="{scripturl}?topic=%2$d.%3$s">%1$s</a>',
        'text' => '<strong>%1$s</strong>',
    );
    $formats['board_msg'] = array(
        'required' => array('board_name', 'board'),
        'link' => '<a href="{scripturl}?board=%2$d.0">%1$s</a>',
        'text' => '<strong>%1$s</strong>',
    );
    $formats['profile_msg'] = array(
        'required' => array('user_name', 'user_id'),
        'link' => '<a href="{scripturl}?action=profile;u=%2$d">%1$s</a>',
        'text' => '<strong>%1$s</strong>',
    );

    // Hooks might want to do something snazzy around their own content types - including enforcing permissions if appropriate.
    call_integration_hook('integrate_fetch_alerts', array(&$alerts, &$formats));

    // Substitute $scripturl into the link formats. (Done here to make life easier for hooked mods.)
    foreach ($formats as &$format_type)
        $format_type = str_replace('{scripturl}', $scripturl, $format_type);

    // If we need to check board access, use the correct board access filter for the member in question.
    if ((!isset($user_info['query_see_board']) || $user_info['id'] != $memID) && (!empty($possible_msgs) || !empty($possible_topics)))
        $qb = build_query_board($memID);
    else
        $qb['query_see_board'] = '{query_see_board}';

    // For anything that needs more info and/or wants us to check board or topic access, let's do that.
    if (!empty($possible_msgs))
    {
        $flipped_msgs = array();
        foreach ($possible_msgs as $id_alert => $id_msg)
        {
            if (!isset($flipped_msgs[$id_msg]))
                $flipped_msgs[$id_msg] = array();

            $flipped_msgs[$id_msg][] = $id_alert;
        }

        $request = $smcFunc['db_query']('', '
            SELECT m.id_msg, m.id_topic, m.subject, b.id_board, b.name AS board_name
            FROM {db_prefix}messages AS m
                INNER JOIN {db_prefix}boards AS b ON (m.id_board = b.id_board)
            WHERE ' . $qb['query_see_board'] . '
                AND m.id_msg IN ({array_int:msgs})
            ORDER BY m.id_msg',
            array(
                'msgs' => $possible_msgs,
            )
        );
        while ($row = $smcFunc['db_fetch_assoc']($request))
        {
            foreach ($flipped_msgs[$row['id_msg']] as $id_alert)
            {
                $alerts[$id_alert]['content_data'] = $row;
                $alerts[$id_alert]['visible'] = true;
            }
        }
        $smcFunc['db_free_result']($request);
    }
    if (!empty($possible_topics))
    {
        $flipped_topics = array();
        foreach ($possible_topics as $id_alert => $id_topic)
        {
            if (!isset($flipped_topics[$id_topic]))
                $flipped_topics[$id_topic] = array();

            $flipped_topics[$id_topic][] = $id_alert;
        }

        $request = $smcFunc['db_query']('', '
            SELECT m.id_msg, t.id_topic, m.subject, b.id_board, b.name AS board_name
            FROM {db_prefix}topics AS t
                INNER JOIN {db_prefix}messages AS m ON (t.id_first_msg = m.id_msg)
                INNER JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board)
            WHERE ' . $qb['query_see_board'] . '
                AND t.id_topic IN ({array_int:topics})',
            array(
                'topics' => $possible_topics,
            )
        );
        while ($row = $smcFunc['db_fetch_assoc']($request))
        {
            foreach ($flipped_topics[$row['id_topic']] as $id_alert)
            {
                $alerts[$id_alert]['content_data'] = $row;
                $alerts[$id_alert]['visible'] = true;
            }
        }
        $smcFunc['db_free_result']($request);
    }

    // Now to go back through the alerts, reattach this extra information and then try to build the string out of it (if a hook didn't already)
    foreach ($alerts as $id_alert => $dummy)
    {
        // There's no point showing alerts for inaccessible content.
        if (!$alerts[$id_alert]['visible'])
        {
            unset($alerts[$id_alert]);
            continue;
        }
        else
            unset($alerts[$id_alert]['visible']);

        // Did a mod already take care of this one?
        if (!empty($alerts[$id_alert]['text']))
            continue;

        // For developer convenience.
        $alert = &$alerts[$id_alert];

        // The info in extra might outdated if the topic was moved, the message's subject was changed, etc.
        if (!empty($alert['content_data']))
        {
            $data = $alert['content_data'];

            // Make sure msg, topic, and board info are correct.
            $patterns = array();
            $replacements = array();
            foreach (array('msg', 'topic', 'board') as $item)
            {
                if (isset($data['id_' . $item]))
                {
                    $separator = $item == 'msg' ? '=?' : '=';

                    if (isset($alert['extra']['content_link']) && strpos($alert['extra']['content_link'], $item . $separator) !== false && strpos($alert['extra']['content_link'], $item . $separator . $data['id_' . $item]) === false)
                    {
                        $patterns[] = '/\b' . $item . $separator . '\d+/';
                        $replacements[] = $item . $separator . $data['id_' . $item];
                    }

                    $alert['extra'][$item] = $data['id_' . $item];
                }
            }
            if (!empty($patterns))
                $alert['extra']['content_link'] = preg_replace($patterns, $replacements, $alert['extra']['content_link']);

            // Make sure the subject is correct.
            if (isset($data['subject']))
                $alert['extra']['content_subject'] = $data['subject'];

            // Keep track of this so we can use it below.
            if (isset($data['board_name']))
                $alert['extra']['board_name'] = $data['board_name'];

            unset($alert['content_data']);
        }

        // Do we want to link to the topic in general or the new messages specifically?
        if (isset($possible_topics[$id_alert]) && in_array($alert['content_action'], array('reply', 'topic', 'unapproved_reply')))
                $alert['extra']['topic_suffix'] = 'new;topicseen#new';
        elseif (isset($alert['extra']['topic']))
            $alert['extra']['topic_suffix'] = '0';

        // Make sure profile alerts have what they need.
        if (in_array($id_alert, $profile_alerts))
        {
            if (empty($alert['extra']['user_id']))
                $alert['extra']['user_id'] = $alert['content_id'];

            if (isset($user_profile[$alert['extra']['user_id']]))
                $alert['extra']['user_name'] = $user_profile[$alert['extra']['user_id']]['real_name'];
        }

        // If we loaded the sender's profile, we may as well use it.
        $sender_id = !empty($alert['sender_id']) ? $alert['sender_id'] : 0;
        if (isset($user_profile[$sender_id]))
            $alert['sender_name'] = $user_profile[$sender_id]['real_name'];

        // If requested, include the sender's avatar data.
        if ($with_avatar && !empty($senders[$sender_id]))
            $alert['sender'] = $senders[$sender_id];

        // Next, build the message strings.
        foreach ($formats as $msg_type => $format_info)
        {
            // Get the values to use in the formatted string, in the right order.
            $msg_values = array_replace(
                array_fill_keys($format_info['required'], ''),
                array_intersect_key($alert['extra'], array_flip($format_info['required']))
            );

            // Assuming all required values are present, build the message.
            if (!in_array('', $msg_values))
                $alert['extra'][$msg_type] = vsprintf($formats[$msg_type][$alert['show_links'] ? 'link' : 'text'], $msg_values);

            elseif (in_array($msg_type, array('msg_msg', 'topic_msg', 'board_msg')))
                $alert['extra'][$msg_type] = $txt[$msg_type == 'board_msg' ? 'board_na' : 'topic_na'];
            else
                $alert['extra'][$msg_type] = '(' . $txt['not_applicable'] . ')';
        }

        // Show the formatted time in alerts about subscriptions.
        if ($alert['content_type'] == 'paidsubs' && isset($alert['extra']['end_time']))
        {
            // If the subscription already expired, say so.
            if ($alert['extra']['end_time'] < time())
                $alert['content_action'] = 'expired';

            // Present a nicely formatted date.
            $alert['extra']['end_time'] = timeformat($alert['extra']['end_time']);
        }

        // Now set the main URL that this alert should take the user to.
        $alert['target_href'] = '';

        // Priority goes to explicitly specified links.
        if (isset($alert['extra']['content_link']))
            $alert['target_href'] = $alert['extra']['content_link'];

        elseif (isset($alert['extra']['report_link']))
            $alert['target_href'] = $scripturl . $alert['extra']['report_link'];

        // Next, try determining the link based on the content action.
        if (empty($alert['target_href']) && in_array($alert['content_action'], array('register_approval', 'group_request', 'buddy_request')))
        {
            switch ($alert['content_action'])
            {
                case 'register_approval':
                    $alert['target_href'] = $scripturl . '?action=admin;area=viewmembers;sa=browse;type=approve';
                    break;

                case 'group_request':
                    $alert['target_href'] = $scripturl . '?action=moderate;area=groups;sa=requests';
                    break;

                case 'buddy_request':
                    if (!empty($alert['id_member_started']))
                        $alert['target_href'] = $scripturl . '?action=profile;u=' . $alert['id_member_started'];
                    break;

                default:
                    break;
            }
        }

        // Or maybe we can determine the link based on the content type.
        if (empty($alert['target_href']) && in_array($alert['content_type'], array('msg', 'member', 'event')))
        {
            switch ($alert['content_type'])
            {
                case 'msg':
                    if (!empty($alert['content_id']))
                        $alert['target_href'] = $scripturl . '?msg=' . $alert['content_id'];
                    break;

                case 'member':
                    if (!empty($alert['id_member_started']))
                        $alert['target_href'] = $scripturl . '?action=profile;u=' . $alert['id_member_started'];
                    break;

                case 'event':
                    if (!empty($alert['extra']['event_id']))
                        $alert['target_href'] = $scripturl . '?action=calendar;event=' . $alert['extra']['event_id'];
                    break;

                default:
                    break;
            }

        }

        // Finally, set this alert's text string.
        $string = 'alert_' . $alert['content_type'] . '_' . $alert['content_action'];

        // This kludge exists because the alert content_types prior to 2.1 RC3 were a bit haphazard.
        // This can be removed once all the translated language files have been updated.
        if (!isset($txt[$string]))
        {
            if (strpos($alert['content_action'], 'unapproved_') === 0)
                $string = 'alert_' . $alert['content_action'];

            if ($alert['content_type'] === 'member' && in_array($alert['content_action'], array('report', 'report_reply')))
                $string = 'alert_profile_' . $alert['content_action'];

            if ($alert['content_type'] === 'member' && $alert['content_action'] === 'buddy_request')
                $string = 'alert_buddy_' . $alert['content_action'];
        }

        if (isset($txt[$string]))
        {
            $substitutions = array(
                '{scripturl}' => $scripturl,
                '{member_link}' => !empty($sender_id) && $alert['show_links'] ? '<a href="' . $scripturl . '?action=profile;u=' . $sender_id . '">' . $alert['sender_name'] . '</a>' : '<strong>' . $alert['sender_name'] . '</strong>',
            );

            if (is_array($alert['extra']))
            {
                foreach ($alert['extra'] as $k => $v)
                    $substitutions['{' . $k . '}'] = $v;
            }

            $alert['text'] = strtr($txt[$string], $substitutions);
        }

        // Unset the reference variable to avoid any surprises in subsequent loops.
        unset($alert);
    }

    return $alerts;
}

/**
 * Shows all alerts for a member
 *
 * @param int $memID The ID of the member
 */
function showAlerts($memID)
{
    global $context, $smcFunc, $txt, $sourcedir, $scripturl, $options;

    require_once($sourcedir . '/Profile-Modify.php');

    // Are we opening a specific alert? (i.e.: ?action=profile;area=showalerts;alert=12345)
    if (!empty($_REQUEST['alert']))
    {
        $alert_id = (int) $_REQUEST['alert'];
        $alerts = fetch_alerts($memID, $alert_id);
        $alert = array_pop($alerts);

        /* 
         * MOD AUTHORS: 
         * To control this redirect, use the 'integrate_fetch_alerts' hook to
         * set the value of $alert['extra']['content_link'], which will become
         * the value for $alert['target_href'].
         */
        
        // In case it failed to determine this alert's link
        if (empty($alert['target_href']))
            redirectexit('action=profile;area=showalerts');

        // Mark the alert as read while we're at it.
        alert_mark($memID, $alert_id, 1);

        // Take the user to the content
        redirectexit($alert['target_href']);
    }

    // Prepare the pagination vars.
    $maxIndex = 10;
    $context['start'] = (int) isset($_REQUEST['start']) ? $_REQUEST['start'] : 0;
    $count = alert_count($memID);

    // Fix invalid 'start' offsets.
    if ($context['start'] > $count)
        $context['start'] = $count - ($count % $maxIndex);
    else
        $context['start'] = $context['start'] - ($context['start'] % $maxIndex);

    // Get the alerts.
    $context['alerts'] = fetch_alerts($memID, true, $maxIndex, $context['start'], true, true);
    $toMark = false;
    $action = '';

    //  Are we using checkboxes?
    $context['showCheckboxes'] = !empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1;

    // Create the pagination.
    $context['pagination'] = constructPageIndex($scripturl . '?action=profile;area=showalerts;u=' . $memID, $context['start'], $count, $maxIndex, false);

    // Set some JavaScript for checking all alerts at once.
    if ($context['showCheckboxes'])
        addInlineJavaScript('
        $(function(){
            $(\'#select_all\').on(\'change\', function() {
                var checkboxes = $(\'ul.quickbuttons\').find(\':checkbox\');
                if($(this).prop(\'checked\')) {
                    checkboxes.prop(\'checked\', true);
                }
                else {
                    checkboxes.prop(\'checked\', false);
                }
            });
        });', true);

    // The quickbuttons
    foreach ($context['alerts'] as $id => $alert)
    {
        $context['alerts'][$id]['quickbuttons'] = array(
            'delete' => array(
                'label' => $txt['delete'],
                'href' => $scripturl . '?action=profile;u=' . $context['id_member'] . ';area=showalerts;do=remove;aid=' . $id . ';' . $context['session_var'] . '=' . $context['session_id'] . (!empty($context['start']) ? ';start=' . $context['start'] : ''),
                'javascript' => 'class="you_sure"',
                'icon' => 'remove_button'
            ),
            'mark' => array(
                'label' => $alert['is_read'] != 0 ? $txt['mark_unread'] : $txt['mark_read_short'],
                'href' => $scripturl . '?action=profile;u=' . $context['id_member'] . ';area=showalerts;do=' . ($alert['is_read'] != 0 ? 'unread' : 'read') . ';aid=' . $id . ';' . $context['session_var'] . '=' . $context['session_id'] . (!empty($context['start']) ? ';start=' . $context['start'] : ''),
                'icon' => $alert['is_read'] != 0 ? 'unread_button' : 'read_button',
            ),
            'view' => array(
                'label' => $txt['view'],
                'href' => $alert['target_href'],
                'icon' => 'move',
            ),
            'quickmod' => array(
                'content' => '<input type="checkbox" name="mark[' . $id . ']" value="' . $id . '">',
                'show' => $context['showCheckboxes']
            )
        );
    }

    // The Delete all unread link.
    $context['alert_purge_link'] = $scripturl . '?action=profile;u=' . $context['id_member'] . ';area=showalerts;do=purge;' . $context['session_var'] . '=' . $context['session_id'] . (!empty($context['start']) ? ';start=' . $context['start'] : '');

    // Set a nice message.
    if (!empty($_SESSION['update_message']))
    {
        $context['update_message'] = $txt['profile_updated_own'];
        unset($_SESSION['update_message']);
    }

    // Saving multiple changes?
    if (isset($_GET['save']) && !empty($_POST['mark']))
    {
        // Get the values.
        $toMark = array_map('intval', (array) $_POST['mark']);

        // Which action?
        $action = !empty($_POST['mark_as']) ? $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($_POST['mark_as'])) : '';
    }

    // A single change.
    if (!empty($_GET['do']) && !empty($_GET['aid']))
    {
        $toMark = (int) $_GET['aid'];
        $action = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($_GET['do']));
    }
    // Delete all read alerts.
    elseif (!empty($_GET['do']) && $_GET['do'] === 'purge')
        $action = 'purge';

    // Save the changes.
    if (!empty($action) && (!empty($toMark) || $action === 'purge'))
    {
        checkSession('request');

        // Call it!
        if ($action == 'remove')
            alert_delete($toMark, $memID);

        elseif ($action == 'purge')
            alert_purge($memID);

        else
            alert_mark($memID, $toMark, $action == 'read' ? 1 : 0);

        // Set a nice update message.
        $_SESSION['update_message'] = true;

        // Redirect.
        redirectexit('action=profile;area=showalerts;u=' . $memID . (!empty($context['start']) ? ';start=' . $context['start'] : ''));
    }
}

/**
 * Show all posts by a member
 *
 * @todo This function needs to be split up properly.
 *
 * @param int $memID The ID of the member
 */
function showPosts($memID)
{
    global $txt, $user_info, $scripturl, $modSettings, $options;
    global $context, $user_profile, $sourcedir, $smcFunc, $board;

    // Some initial context.
    $context['start'] = (int) $_REQUEST['start'];
    $context['current_member'] = $memID;

    // Create the tabs for the template.
    $context[$context['profile_menu_name']]['tab_data'] = array(
        'title' => $txt['showPosts'],
        'description' => $txt['showPosts_help'],
        'icon' => 'profile_hd.png',
        'tabs' => array(
            'messages' => array(
            ),
            'topics' => array(
            ),
            'unwatchedtopics' => array(
            ),
            'attach' => array(
            ),
        ),
    );

    // Shortcut used to determine which $txt['show*'] string to use for the title, based on the SA
    $title = array(
        'attach' => 'Attachments',
        'unwatchedtopics' => 'Unwatched',
        'topics' => 'Topics'
    );

    // Set the page title
    if (isset($_GET['sa']) && array_key_exists($_GET['sa'], $title))
        $context['page_title'] = $txt['show' . $title[$_GET['sa']]];
    else
        $context['page_title'] = $txt['showPosts'];

    $context['page_title'] .= ' - ' . $user_profile[$memID]['real_name'];

    // Is the load average too high to allow searching just now?
    if (!empty($context['load_average']) && !empty($modSettings['loadavg_show_posts']) && $context['load_average'] >= $modSettings['loadavg_show_posts'])
        fatal_lang_error('loadavg_show_posts_disabled', false);

    // If we're specifically dealing with attachments use that function!
    if (isset($_GET['sa']) && $_GET['sa'] == 'attach')
        return showAttachments($memID);
    // Instead, if we're dealing with unwatched topics (and the feature is enabled) use that other function.
    elseif (isset($_GET['sa']) && $_GET['sa'] == 'unwatchedtopics')
        return showUnwatched($memID);

    // Are we just viewing topics?
    $context['is_topics'] = isset($_GET['sa']) && $_GET['sa'] == 'topics' ? true : false;

    // If just deleting a message, do it and then redirect back.
    if (isset($_GET['delete']) && !$context['is_topics'])
    {
        checkSession('get');

        // We need msg info for logging.
        $request = $smcFunc['db_query']('', '
            SELECT subject, id_member, id_topic, id_board
            FROM {db_prefix}messages
            WHERE id_msg = {int:id_msg}',
            array(
                'id_msg' => (int) $_GET['delete'],
            )
        );
        $info = $smcFunc['db_fetch_row']($request);
        $smcFunc['db_free_result']($request);

        // Trying to remove a message that doesn't exist.
        if (empty($info))
            redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);

        // We can be lazy, since removeMessage() will check the permissions for us.
        require_once($sourcedir . '/RemoveTopic.php');
        removeMessage((int) $_GET['delete']);

        // Add it to the mod log.
        if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id']))
            logAction('delete', array('topic' => $info[2], 'subject' => $info[0], 'member' => $info[1], 'board' => $info[3]));

        // Back to... where we are now ;).
        redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
    }

    // Default to 10.
    if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount']))
        $_REQUEST['viewscount'] = '10';

    if ($context['is_topics'])
        $request = $smcFunc['db_query']('', '
            SELECT COUNT(*)
            FROM {db_prefix}topics AS t' . '
            WHERE {query_see_topic_board}
                AND t.id_member_started = {int:current_member}' . (!empty($board) ? '
                AND t.id_board = {int:board}' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
                AND t.approved = {int:is_approved}'),
            array(
                'current_member' => $memID,
                'is_approved' => 1,
                'board' => $board,
            )
        );
    else
        $request = $smcFunc['db_query']('', '
            SELECT COUNT(id_msg)
            FROM {db_prefix}messages AS m
            WHERE {query_see_message_board} AND m.id_member = {int:current_member}' . (!empty($board) ? '
                AND m.id_board = {int:board}' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
                AND m.approved = {int:is_approved}'),
            array(
                'current_member' => $memID,
                'is_approved' => 1,
                'board' => $board,
            )
        );
    list ($msgCount) = $smcFunc['db_fetch_row']($request);
    $smcFunc['db_free_result']($request);

    $request = $smcFunc['db_query']('', '
        SELECT MIN(id_msg), MAX(id_msg)
        FROM {db_prefix}messages AS m
        WHERE m.id_member = {int:current_member}' . (!empty($board) ? '
            AND m.id_board = {int:board}' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
            AND m.approved = {int:is_approved}'),
        array(
            'current_member' => $memID,
            'is_approved' => 1,
            'board' => $board,
        )
    );
    list ($min_msg_member, $max_msg_member) = $smcFunc['db_fetch_row']($request);
    $smcFunc['db_free_result']($request);

    $range_limit = '';

    if ($context['is_topics'])
        $maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics'];
    else
        $maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];

    $maxIndex = $maxPerPage;

    // Make sure the starting place makes sense and construct our friend the page index.
    $context['page_index'] = constructPageIndex($scripturl . '?action=profile;u=' . $memID . ';area=showposts' . ($context['is_topics'] ? ';sa=topics' : '') . (!empty($board) ? ';board=' . $board : ''), $context['start'], $msgCount, $maxIndex);
    $context['current_page'] = $context['start'] / $maxIndex;

    // Reverse the query if we're past 50% of the pages for better performance.
    $start = $context['start'];
    $reverse = $_REQUEST['start'] > $msgCount / 2;
    if ($reverse)
    {
        $maxIndex = $msgCount < $context['start'] + $maxPerPage + 1 && $msgCount > $context['start'] ? $msgCount - $context['start'] : $maxPerPage;
        $start = $msgCount < $context['start'] + $maxPerPage + 1 || $msgCount < $context['start'] + $maxPerPage ? 0 : $msgCount - $context['start'] - $maxPerPage;
    }

    // Guess the range of messages to be shown.
    if ($msgCount > 1000)
    {
        $margin = floor(($max_msg_member - $min_msg_member) * (($start + $maxPerPage) / $msgCount) + .1 * ($max_msg_member - $min_msg_member));
        // Make a bigger margin for topics only.
        if ($context['is_topics'])
        {
            $margin *= 5;
            $range_limit = $reverse ? 't.id_first_msg < ' . ($min_msg_member + $margin) : 't.id_first_msg > ' . ($max_msg_member - $margin);
        }
        else
            $range_limit = $reverse ? 'm.id_msg < ' . ($min_msg_member + $margin) : 'm.id_msg > ' . ($max_msg_member - $margin);
    }

    // Find this user's posts.  The left join on categories somehow makes this faster, weird as it looks.
    $looped = false;
    while (true)
    {
        if ($context['is_topics'])
        {
            $request = $smcFunc['db_query']('', '
                SELECT
                    b.id_board, b.name AS bname, c.id_cat, c.name AS cname, t.id_member_started, t.id_first_msg, t.id_last_msg,
                    t.approved, m.body, m.smileys_enabled, m.subject, m.poster_time, m.id_topic, m.id_msg
                FROM {db_prefix}topics AS t
                    INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
                    LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
                    INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
                WHERE t.id_member_started = {int:current_member}' . (!empty($board) ? '
                    AND t.id_board = {int:board}' : '') . (empty($range_limit) ? '' : '
                    AND ' . $range_limit) . '
                    AND {query_see_board}' . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
                    AND t.approved = {int:is_approved} AND m.approved = {int:is_approved}') . '
                ORDER BY t.id_first_msg ' . ($reverse ? 'ASC' : 'DESC') . '
                LIMIT {int:start}, {int:max}',
                array(
                    'current_member' => $memID,
                    'is_approved' => 1,
                    'board' => $board,
                    'start' => $start,
                    'max' => $maxIndex,
                )
            );
        }
        else
        {
            $request = $smcFunc['db_query']('', '
                SELECT
                    b.id_board, b.name AS bname, c.id_cat, c.name AS cname, m.id_topic, m.id_msg,
                    t.id_member_started, t.id_first_msg, t.id_last_msg, m.body, m.smileys_enabled,
                    m.subject, m.poster_time, m.approved
                FROM {db_prefix}messages AS m
                    INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
                    INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
                    LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
                WHERE m.id_member = {int:current_member}' . (!empty($board) ? '
                    AND b.id_board = {int:board}' : '') . (empty($range_limit) ? '' : '
                    AND ' . $range_limit) . '
                    AND {query_see_board}' . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
                    AND t.approved = {int:is_approved} AND m.approved = {int:is_approved}') . '
                ORDER BY m.id_msg ' . ($reverse ? 'ASC' : 'DESC') . '
                LIMIT {int:start}, {int:max}',
                array(
                    'current_member' => $memID,
                    'is_approved' => 1,
                    'board' => $board,
                    'start' => $start,
                    'max' => $maxIndex,
                )
            );
        }

        // Make sure we quit this loop.
        if ($smcFunc['db_num_rows']($request) === $maxIndex || $looped || $range_limit == '')
            break;
        $looped = true;
        $range_limit = '';
    }

    // Start counting at the number of the first message displayed.
    $counter = $reverse ? $context['start'] + $maxIndex + 1 : $context['start'];
    $context['posts'] = array();
    $board_ids = array('own' => array(), 'any' => array());
    while ($row = $smcFunc['db_fetch_assoc']($request))
    {
        // Censor....
        censorText($row['body']);
        censorText($row['subject']);

        // Do the code.
        $row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);

        // And the array...
        $context['posts'][$counter += $reverse ? -1 : 1] = array(
            'body' => $row['body'],
            'counter' => $counter,
            'category' => array(
                'name' => $row['cname'],
                'id' => $row['id_cat']
            ),
            'board' => array(
                'name' => $row['bname'],
                'id' => $row['id_board']
            ),
            'topic' => $row['id_topic'],
            'subject' => $row['subject'],
            'start' => 'msg' . $row['id_msg'],
            'time' => timeformat($row['poster_time']),
            'timestamp' => forum_time(true, $row['poster_time']),
            'id' => $row['id_msg'],
            'can_reply' => false,
            'can_mark_notify' => !$context['user']['is_guest'],
            'can_delete' => false,
            'delete_possible' => ($row['id_first_msg'] != $row['id_msg'] || $row['id_last_msg'] == $row['id_msg']) && (empty($modSettings['edit_disable_time']) || $row['poster_time'] + $modSettings['edit_disable_time'] * 60 >= time()),
            'approved' => $row['approved'],
            'css_class' => $row['approved'] ? 'windowbg' : 'approvebg',
        );

        if ($user_info['id'] == $row['id_member_started'])
            $board_ids['own'][$row['id_board']][] = $counter;
        $board_ids['any'][$row['id_board']][] = $counter;
    }
    $smcFunc['db_free_result']($request);

    // All posts were retrieved in reverse order, get them right again.
    if ($reverse)
        $context['posts'] = array_reverse($context['posts'], true);

    // These are all the permissions that are different from board to board..
    if ($context['is_topics'])
        $permissions = array(
            'own' => array(
                'post_reply_own' => 'can_reply',
            ),
            'any' => array(
                'post_reply_any' => 'can_reply',
            )
        );
    else
        $permissions = array(
            'own' => array(
                'post_reply_own' => 'can_reply',
                'delete_own' => 'can_delete',
            ),
            'any' => array(
                'post_reply_any' => 'can_reply',
                'delete_any' => 'can_delete',
            )
        );

    // Create an array for the permissions.
    $boards_can = boardsAllowedTo(array_keys(iterator_to_array(
        new RecursiveIteratorIterator(new RecursiveArrayIterator($permissions)))
    ), true, false);

    // For every permission in the own/any lists...
    foreach ($permissions as $type => $list)
    {
        foreach ($list as $permission => $allowed)
        {
            // Get the boards they can do this on...
            $boards = $boards_can[$permission];

            // Hmm, they can do it on all boards, can they?
            if (!empty($boards) && $boards[0] == 0)
                $boards = array_keys($board_ids[$type]);

            // Now go through each board they can do the permission on.
            foreach ($boards as $board_id)
            {
                // There aren't any posts displayed from this board.
                if (!isset($board_ids[$type][$board_id]))
                    continue;

                // Set the permission to true ;).
                foreach ($board_ids[$type][$board_id] as $counter)
                    $context['posts'][$counter][$allowed] = true;
            }
        }
    }

    // Clean up after posts that cannot be deleted and quoted.
    $quote_enabled = empty($modSettings['disabledBBC']) || !in_array('quote', explode(',', $modSettings['disabledBBC']));
    foreach ($context['posts'] as $counter => $dummy)
    {
        $context['posts'][$counter]['can_delete'] &= $context['posts'][$counter]['delete_possible'];
        $context['posts'][$counter]['can_quote'] = $context['posts'][$counter]['can_reply'] && $quote_enabled;
    }

    // Allow last minute changes.
    call_integration_hook('integrate_profile_showPosts');

    foreach ($context['posts'] as $key => $post)
    {
        $context['posts'][$key]['quickbuttons'] = array(
            'reply' => array(
                'label' => $txt['reply'],
                'href' => $scripturl.'?action=post;topic='.$post['topic'].'.'.$post['start'],
                'icon' => 'reply_button',
                'show' => $post['can_reply']
            ),
            'quote' => array(
                'label' => $txt['quote_action'],
                'href' => $scripturl.'?action=post;topic='.$post['topic'].'.'.$post['start'].';quote='.$post['id'],
                'icon' => 'quote',
                'show' => $post['can_quote']
            ),
            'remove' => array(
                'label' => $txt['remove'],
                'href' => $scripturl.'?action=deletemsg;msg='.$post['id'].';topic='.$post['topic'].';profile;u='.$context['member']['id'].';start='.$context['start'].';'.$context['session_var'].'='.$context['session_id'],
                'javascript' => 'data-confirm="'.$txt['remove_message'].'" class="you_sure"',
                'icon' => 'remove_button',
                'show' => $post['can_delete']
            )
        );
    }
}

/**
 * Show all the attachments belonging to a member.
 *
 * @param int $memID The ID of the member
 */
function showAttachments($memID)
{
    global $txt, $scripturl, $modSettings;
    global $sourcedir;

    // OBEY permissions!
    $boardsAllowed = boardsAllowedTo('view_attachments');

    // Make sure we can't actually see anything...
    if (empty($boardsAllowed))
        $boardsAllowed = array(-1);

    require_once($sourcedir . '/Subs-List.php');

    // This is all the information required to list attachments.
    $listOptions = array(
        'id' => 'attachments',
        'width' => '100%',
        'items_per_page' => $modSettings['defaultMaxListItems'],
        'no_items_label' => $txt['show_attachments_none'],
        'base_href' => $scripturl . '?action=profile;area=showposts;sa=attach;u=' . $memID,
        'default_sort_col' => 'filename',
        'get_items' => array(
            'function' => 'list_getAttachments',
            'params' => array(
                $boardsAllowed,
                $memID,
            ),
        ),
        'get_count' => array(
            'function' => 'list_getNumAttachments',
            'params' => array(
                $boardsAllowed,
                $memID,
            ),
        ),
        'data_check' => array(
            'class' => function($data)
            {
                return $data['approved'] ? '' : 'approvebg';
            }
        ),
        'columns' => array(
            'filename' => array(
                'header' => array(
                    'value' => $txt['show_attach_filename'],
                    'class' => 'lefttext',
                    'style' => 'width: 25%;',
                ),
                'data' => array(
                    'sprintf' => array(
                        'format' => '<a href="' . $scripturl . '?action=dlattach;topic=%1$d.0;attach=%2$d">%3$s</a>',
                        'params' => array(
                            'topic' => true,
                            'id' => true,
                            'filename' => false,
                        ),
                    ),
                ),
                'sort' => array(
                    'default' => 'a.filename',
                    'reverse' => 'a.filename DESC',
                ),
            ),
            'downloads' => array(
                'header' => array(
                    'value' => $txt['show_attach_downloads'],
                    'style' => 'width: 12%;',
                ),
                'data' => array(
                    'db' => 'downloads',
                    'comma_format' => true,
                ),
                'sort' => array(
                    'default' => 'a.downloads',
                    'reverse' => 'a.downloads DESC',
                ),
            ),
            'subject' => array(
                'header' => array(
                    'value' => $txt['message'],
                    'class' => 'lefttext',
                    'style' => 'width: 30%;',
                ),
                'data' => array(
                    'sprintf' => array(
                        'format' => '<a href="' . $scripturl . '?msg=%1$d">%2$s</a>',
                        'params' => array(
                            'msg' => true,
                            'subject' => false,
                        ),
                    ),
                ),
                'sort' => array(
                    'default' => 'm.subject',
                    'reverse' => 'm.subject DESC',
                ),
            ),
            'posted' => array(
                'header' => array(
                    'value' => $txt['show_attach_posted'],
                    'class' => 'lefttext',
                ),
                'data' => array(
                    'db' => 'posted',
                    'timeformat' => true,
                ),
                'sort' => array(
                    'default' => 'm.poster_time',
                    'reverse' => 'm.poster_time DESC',
                ),
            ),
        ),
    );

    // Create the request list.
    createList($listOptions);
}

/**
 * Get a list of attachments for a member. Callback for the list in showAttachments()
 *
 * @param int $start Which item to start with (for pagination purposes)
 * @param int $items_per_page How many items to show on each page
 * @param string $sort A string indicating how to sort the results
 * @param array $boardsAllowed An array containing the IDs of the boards they can see
 * @param int $memID The ID of the member
 * @return array An array of information about the attachments
 */
function list_getAttachments($start, $items_per_page, $sort, $boardsAllowed, $memID)
{
    global $smcFunc, $board, $modSettings, $context;

    // Retrieve some attachments.
    $request = $smcFunc['db_query']('', '
        SELECT a.id_attach, a.id_msg, a.filename, a.downloads, a.approved, m.id_msg, m.id_topic,
            m.id_board, m.poster_time, m.subject, b.name
        FROM {db_prefix}attachments AS a
            INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_msg)
            INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})
        WHERE a.attachment_type = {int:attachment_type}
            AND a.id_msg != {int:no_message}
            AND m.id_member = {int:current_member}' . (!empty($board) ? '
            AND b.id_board = {int:board}' : '') . (!in_array(0, $boardsAllowed) ? '
            AND b.id_board IN ({array_int:boards_list})' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
            AND m.approved = {int:is_approved}') . '
        ORDER BY {raw:sort}
        LIMIT {int:offset}, {int:limit}',
        array(
            'boards_list' => $boardsAllowed,
            'attachment_type' => 0,
            'no_message' => 0,
            'current_member' => $memID,
            'is_approved' => 1,
            'board' => $board,
            'sort' => $sort,
            'offset' => $start,
            'limit' => $items_per_page,
        )
    );
    $attachments = array();
    while ($row = $smcFunc['db_fetch_assoc']($request))
        $attachments[] = array(
            'id' => $row['id_attach'],
            'filename' => $row['filename'],
            'downloads' => $row['downloads'],
            'subject' => censorText($row['subject']),
            'posted' => $row['poster_time'],
            'msg' => $row['id_msg'],
            'topic' => $row['id_topic'],
            'board' => $row['id_board'],
            'board_name' => $row['name'],
            'approved' => $row['approved'],
        );

    $smcFunc['db_free_result']($request);

    return $attachments;
}

/**
 * Gets the total number of attachments for a member
 *
 * @param array $boardsAllowed An array of the IDs of the boards they can see
 * @param int $memID The ID of the member
 * @return int The number of attachments
 */
function list_getNumAttachments($boardsAllowed, $memID)
{
    global $board, $smcFunc, $modSettings, $context;

    // Get the total number of attachments they have posted.
    $request = $smcFunc['db_query']('', '
        SELECT COUNT(*)
        FROM {db_prefix}attachments AS a
            INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_msg)
            INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})
        WHERE a.attachment_type = {int:attachment_type}
            AND a.id_msg != {int:no_message}
            AND m.id_member = {int:current_member}' . (!empty($board) ? '
            AND b.id_board = {int:board}' : '') . (!in_array(0, $boardsAllowed) ? '
            AND b.id_board IN ({array_int:boards_list})' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
            AND m.approved = {int:is_approved}'),
        array(
            'boards_list' => $boardsAllowed,
            'attachment_type' => 0,
            'no_message' => 0,
            'current_member' => $memID,
            'is_approved' => 1,
            'board' => $board,
        )
    );
    list ($attachCount) = $smcFunc['db_fetch_row']($request);
    $smcFunc['db_free_result']($request);

    return $attachCount;
}

/**
 * Show all the unwatched topics.
 *
 * @param int $memID The ID of the member
 */
function showUnwatched($memID)
{
    global $txt, $user_info, $scripturl, $modSettings, $context, $options, $sourcedir;

    // Only the owner can see the list (if the function is enabled of course)
    if ($user_info['id'] != $memID)
        return;

    require_once($sourcedir . '/Subs-List.php');

    // And here they are: the topics you don't like
    $listOptions = array(
        'id' => 'unwatched_topics',
        'width' => '100%',
        'items_per_page' => (empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page'])) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics'],
        'no_items_label' => $txt['unwatched_topics_none'],
        'base_href' => $scripturl . '?action=profile;area=showposts;sa=unwatchedtopics;u=' . $memID,
        'default_sort_col' => 'started_on',
        'get_items' => array(
            'function' => 'list_getUnwatched',
            'params' => array(
                $memID,
            ),
        ),
        'get_count' => array(
            'function' => 'list_getNumUnwatched',
            'params' => array(
                $memID,
            ),
        ),
        'columns' => array(
            'subject' => array(
                'header' => array(
                    'value' => $txt['subject'],
                    'class' => 'lefttext',
                    'style' => 'width: 30%;',
                ),
                'data' => array(
                    'sprintf' => array(
                        'format' => '<a href="' . $scripturl . '?topic=%1$d.0">%2$s</a>',
                        'params' => array(
                            'id_topic' => false,
                            'subject' => false,
                        ),
                    ),
                ),
                'sort' => array(
                    'default' => 'm.subject',
                    'reverse' => 'm.subject DESC',
                ),
            ),
            'started_by' => array(
                'header' => array(
                    'value' => $txt['started_by'],
                    'style' => 'width: 15%;',
                ),
                'data' => array(
                    'db' => 'started_by',
                ),
                'sort' => array(
                    'default' => 'mem.real_name',
                    'reverse' => 'mem.real_name DESC',
                ),
            ),
            'started_on' => array(
                'header' => array(
                    'value' => $txt['on'],
                    'class' => 'lefttext',
                    'style' => 'width: 20%;',
                ),
                'data' => array(
                    'db' => 'started_on',
                    'timeformat' => true,
                ),
                'sort' => array(
                    'default' => 'm.poster_time',
                    'reverse' => 'm.poster_time DESC',
                ),
            ),
            'last_post_by' => array(
                'header' => array(
                    'value' => $txt['last_post'],
                    'style' => 'width: 15%;',
                ),
                'data' => array(
                    'db' => 'last_post_by',
                ),
                'sort' => array(
                    'default' => 'mem.real_name',
                    'reverse' => 'mem.real_name DESC',
                ),
            ),
            'last_post_on' => array(
                'header' => array(
                    'value' => $txt['on'],
                    'class' => 'lefttext',
                    'style' => 'width: 20%;',
                ),
                'data' => array(
                    'db' => 'last_post_on',
                    'timeformat' => true,
                ),
                'sort' => array(
                    'default' => 'm.poster_time',
                    'reverse' => 'm.poster_time DESC',
                ),
            ),
        ),
    );

    // Create the request list.
    createList($listOptions);

    $context['sub_template'] = 'show_list';
    $context['default_list'] = 'unwatched_topics';
}

/**
 * Gets information about unwatched (disregarded) topics. Callback for the list in show_unwatched
 *
 * @param int $start The item to start with (for pagination purposes)
 * @param int $items_per_page How many items to show on each page
 * @param string $sort A string indicating how to sort the results
 * @param int $memID The ID of the member
 * @return array An array of information about the unwatched topics
 */
function list_getUnwatched($start, $items_per_page, $sort, $memID)
{
    global $smcFunc;

    // Get the list of topics we can see
    $request = $smcFunc['db_query']('', '
        SELECT lt.id_topic
        FROM {db_prefix}log_topics as lt
            LEFT JOIN {db_prefix}topics as t ON (lt.id_topic = t.id_topic)
            LEFT JOIN {db_prefix}messages as m ON (t.id_first_msg = m.id_msg)' . (in_array($sort, array('mem.real_name', 'mem.real_name DESC', 'mem.poster_time', 'mem.poster_time DESC')) ? '
            LEFT JOIN {db_prefix}members as mem ON (m.id_member = mem.id_member)' : '') . '
        WHERE lt.id_member = {int:current_member}
            AND unwatched = 1
            AND {query_see_message_board}
        ORDER BY {raw:sort}
        LIMIT {int:offset}, {int:limit}',
        array(
            'current_member' => $memID,
            'sort' => $sort,
            'offset' => $start,
            'limit' => $items_per_page,
        )
    );

    $topics = array();
    while ($row = $smcFunc['db_fetch_assoc']($request))
        $topics[] = $row['id_topic'];

    $smcFunc['db_free_result']($request);

    // Any topics found?
    $topicsInfo = array();
    if (!empty($topics))
    {
        $request = $smcFunc['db_query']('', '
            SELECT mf.subject, mf.poster_time as started_on, COALESCE(memf.real_name, mf.poster_name) as started_by, ml.poster_time as last_post_on, COALESCE(meml.real_name, ml.poster_name) as last_post_by, t.id_topic
            FROM {db_prefix}topics AS t
                INNER JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg)
                INNER JOIN {db_prefix}messages AS mf ON (mf.id_msg = t.id_first_msg)
                LEFT JOIN {db_prefix}members AS meml ON (meml.id_member = ml.id_member)
                LEFT JOIN {db_prefix}members AS memf ON (memf.id_member = mf.id_member)
            WHERE t.id_topic IN ({array_int:topics})',
            array(
                'topics' => $topics,
            )
        );
        while ($row = $smcFunc['db_fetch_assoc']($request))
            $topicsInfo[] = $row;
        $smcFunc['db_free_result']($request);
    }

    return $topicsInfo;
}

/**
 * Count the number of topics in the unwatched list
 *
 * @param int $memID The ID of the member
 * @return int The number of unwatched topics
 */
function list_getNumUnwatched($memID)
{
    global $smcFunc;

    // Get the total number of attachments they have posted.
    $request = $smcFunc['db_query']('', '
        SELECT COUNT(*)
        FROM {db_prefix}log_topics as lt
        LEFT JOIN {db_prefix}topics as t ON (lt.id_topic = t.id_topic)
        WHERE lt.id_member = {int:current_member}
            AND lt.unwatched = 1
            AND {query_see_topic_board}',
        array(
            'current_member' => $memID,
        )
    );
    list ($unwatchedCount) = $smcFunc['db_fetch_row']($request);
    $smcFunc['db_free_result']($request);

    return $unwatchedCount;
}

/**
 * Gets the user stats for display
 *
 * @param int $memID The ID of the member
 */
function statPanel($memID)
{
    global $txt, $scripturl, $context, $user_profile, $user_info, $modSettings, $smcFunc;

    $context['page_title'] = $txt['statPanel_showStats'] . ' ' . $user_profile[$memID]['real_name'];

    // Is the load average too high to allow searching just now?
    if (!empty($context['load_average']) && !empty($modSettings['loadavg_userstats']) && $context['load_average'] >= $modSettings['loadavg_userstats'])
        fatal_lang_error('loadavg_userstats_disabled', false);

    // General user statistics.
    $timeDays = floor($user_profile[$memID]['total_time_logged_in'] / 86400);
    $timeHours = floor(($user_profile[$memID]['total_time_logged_in'] % 86400) / 3600);
    $context['time_logged_in'] = ($timeDays > 0 ? $timeDays . $txt['total_time_logged_days'] : '') . ($timeHours > 0 ? $timeHours . $txt['total_time_logged_hours'] : '') . floor(($user_profile[$memID]['total_time_logged_in'] % 3600) / 60) . $txt['total_time_logged_minutes'];
    $context['num_posts'] = comma_format($user_profile[$memID]['posts']);
    // Menu tab
    $context[$context['profile_menu_name']]['tab_data'] = array(
        'title' => $txt['statPanel_generalStats'] . ' - ' . $context['member']['name'],
        'icon' => 'stats_info.png'
    );

    // Number of topics started and Number polls started
    $result = $smcFunc['db_query']('', '
        SELECT COUNT(*), COUNT( CASE WHEN id_poll != {int:no_poll} THEN 1 ELSE NULL END )
        FROM {db_prefix}topics
        WHERE id_member_started = {int:current_member}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
            AND id_board != {int:recycle_board}' : ''),
        array(
            'current_member' => $memID,
            'recycle_board' => $modSettings['recycle_board'],
            'no_poll' => 0,
        )
    );
    list ($context['num_topics'], $context['num_polls']) = $smcFunc['db_fetch_row']($result);
    $smcFunc['db_free_result']($result);

    // Number polls voted in.
    $result = $smcFunc['db_query']('distinct_poll_votes', '
        SELECT COUNT(DISTINCT id_poll)
        FROM {db_prefix}log_polls
        WHERE id_member = {int:current_member}',
        array(
            'current_member' => $memID,
        )
    );
    list ($context['num_votes']) = $smcFunc['db_fetch_row']($result);
    $smcFunc['db_free_result']($result);

    // Format the numbers...
    $context['num_topics'] = comma_format($context['num_topics']);
    $context['num_polls'] = comma_format($context['num_polls']);
    $context['num_votes'] = comma_format($context['num_votes']);

    // Grab the board this member posted in most often.
    $result = $smcFunc['db_query']('', '
        SELECT
            b.id_board, MAX(b.name) AS name, MAX(b.num_posts) AS num_posts, COUNT(*) AS message_count
        FROM {db_prefix}messages AS m
            INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
        WHERE m.id_member = {int:current_member}
            AND b.count_posts = {int:count_enabled}
            AND {query_see_board}
        GROUP BY b.id_board
        ORDER BY message_count DESC
        LIMIT 10',
        array(
            'current_member' => $memID,
            'count_enabled' => 0,
        )
    );
    $context['popular_boards'] = array();
    while ($row = $smcFunc['db_fetch_assoc']($result))
    {
        $context['popular_boards'][$row['id_board']] = array(
            'id' => $row['id_board'],
            'posts' => $row['message_count'],
            'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
            'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>',
            'posts_percent' => $user_profile[$memID]['posts'] == 0 ? 0 : ($row['message_count'] * 100) / $user_profile[$memID]['posts'],
            'total_posts' => $row['num_posts'],
            'total_posts_member' => $user_profile[$memID]['posts'],
        );
    }
    $smcFunc['db_free_result']($result);

    // Now get the 10 boards this user has most often participated in.
    $result = $smcFunc['db_query']('profile_board_stats', '
        SELECT
            b.id_board, MAX(b.name) AS name, b.num_posts, COUNT(*) AS message_count,
            CASE WHEN COUNT(*) > MAX(b.num_posts) THEN 1 ELSE COUNT(*) / MAX(b.num_posts) END * 100 AS percentage
        FROM {db_prefix}messages AS m
            INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
        WHERE m.id_member = {int:current_member}
            AND {query_see_board}
        GROUP BY b.id_board, b.num_posts
        ORDER BY percentage DESC
        LIMIT 10',
        array(
            'current_member' => $memID,
        )
    );
    $context['board_activity'] = array();
    while ($row = $smcFunc['db_fetch_assoc']($result))
    {
        $context['board_activity'][$row['id_board']] = array(
            'id' => $row['id_board'],
            'posts' => $row['message_count'],
            'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
            'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>',
            'percent' => comma_format((float) $row['percentage'], 2),
            'posts_percent' => (float) $row['percentage'],
            'total_posts' => $row['num_posts'],
        );
    }
    $smcFunc['db_free_result']($result);

    // Posting activity by time.
    $result = $smcFunc['db_query']('user_activity_by_time', '
        SELECT
            HOUR(FROM_UNIXTIME(poster_time + {int:time_offset})) AS hour,
            COUNT(*) AS post_count
        FROM {db_prefix}messages
        WHERE id_member = {int:current_member}' . ($modSettings['totalMessages'] > 100000 ? '
            AND id_topic > {int:top_ten_thousand_topics}' : '') . '
        GROUP BY hour',
        array(
            'current_member' => $memID,
            'top_ten_thousand_topics' => $modSettings['totalTopics'] - 10000,
            'time_offset' => (($user_info['time_offset'] + $modSettings['time_offset']) * 3600),
        )
    );
    $maxPosts = $realPosts = 0;
    $context['posts_by_time'] = array();
    while ($row = $smcFunc['db_fetch_assoc']($result))
    {
        // Cast as an integer to remove the leading 0.
        $row['hour'] = (int) $row['hour'];

        $maxPosts = max($row['post_count'], $maxPosts);
        $realPosts += $row['post_count'];

        $context['posts_by_time'][$row['hour']] = array(
            'hour' => $row['hour'],
            'hour_format' => stripos($user_info['time_format'], '%p') === false ? $row['hour'] : date('g a', mktime($row['hour'])),
            'posts' => $row['post_count'],
            'posts_percent' => 0,
            'is_last' => $row['hour'] == 23,
        );
    }
    $smcFunc['db_free_result']($result);

    if ($maxPosts > 0)
        for ($hour = 0; $hour < 24; $hour++)
        {
            if (!isset($context['posts_by_time'][$hour]))
                $context['posts_by_time'][$hour] = array(
                    'hour' => $hour,
                    'hour_format' => stripos($user_info['time_format'], '%p') === false ? $hour : date('g a', mktime($hour)),
                    'posts' => 0,
                    'posts_percent' => 0,
                    'relative_percent' => 0,
                    'is_last' => $hour == 23,
                );
            else
            {
                $context['posts_by_time'][$hour]['posts_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $realPosts);
                $context['posts_by_time'][$hour]['relative_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $maxPosts);
            }
        }

    // Put it in the right order.
    ksort($context['posts_by_time']);

    /**
     * Adding new entries:
     * 'key' => array(
     *      'text' => string, // The text that will be shown next to the entry.
     *      'url' => string, // OPTIONAL: The entry will be a url
     * ),
     *
     * 'key' will be used to look up the language string as $txt['statPanel_' . $key].
     * Make sure to add a new entry when writing your mod!
     */
    $context['text_stats'] = array(
        'total_time_online' => array(
            'text' => $context['time_logged_in'],
        ),
        'total_posts' => array(
            'text' => $context['num_posts'] . ' ' . $txt['statPanel_posts'],
            'url' => $scripturl . '?action=profile;area=showposts;sa=messages;u=' . $memID
        ),
        'total_topics' => array(
            'text' => $context['num_topics'] . ' ' . $txt['statPanel_topics'],
            'url' => $scripturl . '?action=profile;area=showposts;sa=topics;u=' . $memID
        ),
        'users_polls' => array(
            'text' => $context['num_polls'] . ' ' . $txt['statPanel_polls'],
        ),
        'users_votes' => array(
            'text' => $context['num_votes'] . ' ' . $txt['statPanel_votes']
        )
    );

    // Custom stats (just add a template_layer to add it to the template!)
    call_integration_hook('integrate_profile_stats', array($memID, &$context['text_stats']));
}

/**
 * Loads up the information for the "track user" section of the profile
 *
 * @param int $memID The ID of the member
 */
function tracking($memID)
{
    global $context, $txt, $modSettings, $user_profile;

    $subActions = array(
        'activity' => array('trackActivity', $txt['trackActivity'], 'moderate_forum'),
        'ip' => array('TrackIP', $txt['trackIP'], 'moderate_forum'),
        'edits' => array('trackEdits', $txt['trackEdits'], 'moderate_forum'),
        'groupreq' => array('trackGroupReq', $txt['trackGroupRequests'], 'approve_group_requests'),
        'logins' => array('TrackLogins', $txt['trackLogins'], 'moderate_forum'),
    );

    foreach ($subActions as $sa => $action)
    {
        if (!allowedTo($action[2]))
            unset($subActions[$sa]);
    }

    // Create the tabs for the template.
    $context[$context['profile_menu_name']]['tab_data'] = array(
        'title' => $txt['tracking'],
        'description' => $txt['tracking_description'],
        'icon' => 'profile_hd.png',
        'tabs' => array(
            'activity' => array(),
            'ip' => array(),
            'edits' => array(),
            'groupreq' => array(),
            'logins' => array(),
        ),
    );

    // Moderation must be on to track edits.
    if (empty($modSettings['userlog_enabled']))
        unset($context[$context['profile_menu_name']]['tab_data']['edits'], $subActions['edits']);

    // Group requests must be active to show it...
    if (empty($modSettings['show_group_membership']))
        unset($context[$context['profile_menu_name']]['tab_data']['groupreq'], $subActions['groupreq']);

    if (empty($subActions))
        fatal_lang_error('no_access', false);

    $keys = array_keys($subActions);
    $default = array_shift($keys);
    $context['tracking_area'] = isset($_GET['sa']) && isset($subActions[$_GET['sa']]) ? $_GET['sa'] : $default;

    // Set a page title.
    $context['page_title'] = $txt['trackUser'] . ' - ' . $subActions[$context['tracking_area']][1] . ' - ' . $user_profile[$memID]['real_name'];

    // Pass on to the actual function.
    $context['sub_template'] = $subActions[$context['tracking_area']][0];
    $call = call_helper($subActions[$context['tracking_area']][0], true);

    if (!empty($call))
        call_user_func($call, $memID);
}

/**
 * Handles tracking a user's activity
 *
 * @param int $memID The ID of the member
 */
function trackActivity($memID)
{
    global $scripturl, $txt, $modSettings, $sourcedir;
    global $user_profile, $context, $smcFunc;

    // Verify if the user has sufficient permissions.
    isAllowedTo('moderate_forum');

    $context['last_ip'] = $user_profile[$memID]['member_ip'];
    if ($context['last_ip'] != $user_profile[$memID]['member_ip2'])
        $context['last_ip2'] = $user_profile[$memID]['member_ip2'];
    $context['member']['name'] = $user_profile[$memID]['real_name'];

    // Set the options for the list component.
    $listOptions = array(
        'id' => 'track_user_list',
        'title' => $txt['errors_by'] . ' ' . $context['member']['name'],
        'items_per_page' => $modSettings['defaultMaxListItems'],
        'no_items_label' => $txt['no_errors_from_user'],
        'base_href' => $scripturl . '?action=profile;area=tracking;sa=user;u=' . $memID,
        'default_sort_col' => 'date',
        'get_items' => array(
            'function' => 'list_getUserErrors',
            'params' => array(
                'le.id_member = {int:current_member}',
                array('current_member' => $memID),
            ),
        ),
        'get_count' => array(
            'function' => 'list_getUserErrorCount',
            'params' => array(
                'id_member = {int:current_member}',
                array('current_member' => $memID),
            ),
        ),
        'columns' => array(
            'ip_address' => array(
                'header' => array(
                    'value' => $txt['ip_address'],
                ),
                'data' => array(
                    'sprintf' => array(
                        'format' => '<a href="' . $scripturl . '?action=profile;area=tracking;sa=ip;searchip=%1$s;u=' . $memID . '">%1$s</a>',
                        'params' => array(
                            'ip' => false,
                        ),
                    ),
                ),
                'sort' => array(
                    'default' => 'le.ip',
                    'reverse' => 'le.ip DESC',
                ),
            ),
            'message' => array(
                'header' => array(
                    'value' => $txt['message'],
                ),
                'data' => array(
                    'sprintf' => array(
                        'format' => '%1$s<br><a href="%2$s">%2$s</a>',
                        'params' => array(
                            'message' => false,
                            'url' => false,
                        ),
                    ),
                ),
            ),
            'date' => array(
                'header' => array(
                    'value' => $txt['date'],
                ),
                'data' => array(
                    'db' => 'time',
                ),
                'sort' => array(
                    'default' => 'le.id_error DESC',
                    'reverse' => 'le.id_error',
                ),
            ),
        ),
        'additional_rows' => array(
            array(
                'position' => 'after_title',
                'value' => $txt['errors_desc'],
            ),
        ),
    );

    // Create the list for viewing.
    require_once($sourcedir . '/Subs-List.php');
    createList($listOptions);

    // @todo cache this
    // If this is a big forum, or a large posting user, let's limit the search.
    if ($modSettings['totalMessages'] > 50000 && $user_profile[$memID]['posts'] > 500)
    {
        $request = $smcFunc['db_query']('', '
            SELECT MAX(id_msg)
            FROM {db_prefix}messages AS m
            WHERE m.id_member = {int:current_member}',
            array(
                'current_member' => $memID,
            )
        );
        list ($max_msg_member) = $smcFunc['db_fetch_row']($request);
        $smcFunc['db_free_result']($request);

        // There's no point worrying ourselves with messages made yonks ago, just get recent ones!
        $min_msg_member = max(0, $max_msg_member - $user_profile[$memID]['posts'] * 3);
    }

    // Default to at least the ones we know about.
    $ips = array(
        $user_profile[$memID]['member_ip'],
        $user_profile[$memID]['member_ip2'],
    );

    // @todo cache this
    // Get all IP addresses this user has used for his messages.
    $request = $smcFunc['db_query']('', '
        SELECT poster_ip
        FROM {db_prefix}messages
        WHERE id_member = {int:current_member}
        ' . (isset($min_msg_member) ? '
            AND id_msg >= {int:min_msg_member} AND id_msg <= {int:max_msg_member}' : '') . '
        GROUP BY poster_ip',
        array(
            'current_member' => $memID,
            'min_msg_member' => !empty($min_msg_member) ? $min_msg_member : 0,
            'max_msg_member' => !empty($max_msg_member) ? $max_msg_member : 0,
        )
    );
    $context['ips'] = array();
    while ($row = $smcFunc['db_fetch_assoc']($request))
    {
        $context['ips'][] = '<a href="' . $scripturl . '?action=profile;area=tracking;sa=ip;searchip=' . inet_dtop($row['poster_ip']) . ';u=' . $memID . '">' . inet_dtop($row['poster_ip']) . '</a>';
        $ips[] = inet_dtop($row['poster_ip']);
    }
    $smcFunc['db_free_result']($request);

    // Now also get the IP addresses from the error messages.
    $request = $smcFunc['db_query']('', '
        SELECT COUNT(*) AS error_count, ip
        FROM {db_prefix}log_errors
        WHERE id_member = {int:current_member}
        GROUP BY ip',
        array(
            'current_member' => $memID,
        )
    );
    $context['error_ips'] = array();
    while ($row = $smcFunc['db_fetch_assoc']($request))
    {
        $row['ip'] = inet_dtop($row['ip']);
        $context['error_ips'][] = '<a href="' . $scripturl . '?action=profile;area=tracking;sa=ip;searchip=' . $row['ip'] . ';u=' . $memID . '">' . $row['ip'] . '</a>';
        $ips[] = $row['ip'];
    }
    $smcFunc['db_free_result']($request);

    // Find other users that might use the same IP.
    $ips = array_unique($ips);
    $context['members_in_range'] = array();
    if (!empty($ips))
    {
        // Get member ID's which are in messages...
        $request = $smcFunc['db_query']('', '
            SELECT DISTINCT mem.id_member
            FROM {db_prefix}messages AS m
                INNER JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
            WHERE m.poster_ip IN ({array_inet:ip_list})
                AND mem.id_member != {int:current_member}',
            array(
                'current_member' => $memID,
                'ip_list' => $ips,
            )
        );
        $message_members = array();
        while ($row = $smcFunc['db_fetch_assoc']($request))
            $message_members[] = $row['id_member'];
        $smcFunc['db_free_result']($request);

        // Fetch their names, cause of the GROUP BY doesn't like giving us that normally.
        if (!empty($message_members))
        {
            $request = $smcFunc['db_query']('', '
                SELECT id_member, real_name
                FROM {db_prefix}members
                WHERE id_member IN ({array_int:message_members})',
                array(
                    'message_members' => $message_members,
                    'ip_list' => $ips,
                )
            );
            while ($row = $smcFunc['db_fetch_assoc']($request))
                $context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
            $smcFunc['db_free_result']($request);
        }

        $request = $smcFunc['db_query']('', '
            SELECT id_member, real_name
            FROM {db_prefix}members
            WHERE id_member != {int:current_member}
                AND member_ip IN ({array_inet:ip_list})',
            array(
                'current_member' => $memID,
                'ip_list' => $ips,
            )
        );
        while ($row = $smcFunc['db_fetch_assoc']($request))
            $context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
        $smcFunc['db_free_result']($request);
    }
}

/**
 * Get the number of user errors
 *
 * @param string $where A query to limit which errors are counted
 * @param array $where_vars The parameters for $where
 * @return int Number of user errors
 */
function list_getUserErrorCount($where, $where_vars = array())
{
    global $smcFunc;

    $request = $smcFunc['db_query']('', '
        SELECT COUNT(id_error)
        FROM {db_prefix}log_errors
        WHERE ' . $where,
        $where_vars
    );
    list ($count) = $smcFunc['db_fetch_row']($request);
    $smcFunc['db_free_result']($request);

    return (int) $count;
}

/**
 * Gets all of the errors generated by a user's actions. Callback for the list in track_activity
 *
 * @param int $start Which item to start with (for pagination purposes)
 * @param int $items_per_page How many items to show on each page
 * @param string $sort A string indicating how to sort the results
 * @param string $where A query indicating how to filter the results (eg 'id_member={int:id_member}')
 * @param array $where_vars An array of parameters for $where
 * @return array An array of information about the error messages
 */
function list_getUserErrors($start, $items_per_page, $sort, $where, $where_vars = array())
{
    global $smcFunc, $txt, $scripturl;

    // Get a list of error messages from this ip (range).
    $request = $smcFunc['db_query']('', '
        SELECT
            le.log_time, le.ip, le.url, le.message, COALESCE(mem.id_member, 0) AS id_member,
            COALESCE(mem.real_name, {string:guest_title}) AS display_name, mem.member_name
        FROM {db_prefix}log_errors AS le
            LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = le.id_member)
        WHERE ' . $where . '
        ORDER BY {raw:sort}
        LIMIT {int:start}, {int:max}',
        array_merge($where_vars, array(
            'guest_title' => $txt['guest_title'],
            'sort' => $sort,
            'start' => $start,
            'max' => $items_per_page,
        ))
    );
    $error_messages = array();
    while ($row = $smcFunc['db_fetch_assoc']($request))
        $error_messages[] = array(
            'ip' => inet_dtop($row['ip']),
            'member_link' => $row['id_member'] > 0 ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>' : $row['display_name'],
            'message' => strtr($row['message'], array('&lt;span class=&quot;remove&quot;&gt;' => '', '&lt;/span&gt;' => '')),
            'url' => $row['url'],
            'time' => timeformat($row['log_time']),
            'timestamp' => forum_time(true, $row['log_time']),
        );
    $smcFunc['db_free_result']($request);

    return $error_messages;
}

/**
 * Gets the number of posts made from a particular IP
 *
 * @param string $where A query indicating which posts to count
 * @param array $where_vars The parameters for $where
 * @return int Count of messages matching the IP
 */
function list_getIPMessageCount($where, $where_vars = array())
{
    global $smcFunc, $user_info;

    $request = $smcFunc['db_query']('', '
        SELECT COUNT(id_msg)
        FROM {db_prefix}messages AS m
        WHERE {query_see_message_board} AND ' . $where,
        $where_vars
    );
    list ($count) = $smcFunc['db_fetch_row']($request);
    $smcFunc['db_free_result']($request);

    return (int) $count;
}

/**
 * Gets all the posts made from a particular IP
 *
 * @param int $start Which item to start with (for pagination purposes)
 * @param int $items_per_page How many items to show on each page
 * @param string $sort A string indicating how to sort the results
 * @param string $where A query to filter which posts are returned
 * @param array $where_vars An array of parameters for $where
 * @return array An array containing information about the posts
 */
function list_getIPMessages($start, $items_per_page, $sort, $where, $where_vars = array())
{
    global $smcFunc, $scripturl, $user_info;

    // Get all the messages fitting this where clause.
    $request = $smcFunc['db_query']('', '
        SELECT
            m.id_msg, m.poster_ip, COALESCE(mem.real_name, m.poster_name) AS display_name, mem.id_member,
            m.subject, m.poster_time, m.id_topic, m.id_board
        FROM {db_prefix}messages AS m
            LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
        WHERE {query_see_message_board} AND ' . $where . '
        ORDER BY {raw:sort}
        LIMIT {int:start}, {int:max}',
        array_merge($where_vars, array(
            'sort' => $sort,
            'start' => $start,
            'max' => $items_per_page,
        ))
    );
    $messages = array();
    while ($row = $smcFunc['db_fetch_assoc']($request))
        $messages[] = array(
            'ip' => inet_dtop($row['poster_ip']),
            'member_link' => empty($row['id_member']) ? $row['display_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>',
            'board' => array(
                'id' => $row['id_board'],
                'href' => $scripturl . '?board=' . $row['id_board']
            ),
            'topic' => $row['id_topic'],
            'id' => $row['id_msg'],
            'subject' => $row['subject'],
            'time' => timeformat($row['poster_time']),
            'timestamp' => forum_time(true, $row['poster_time'])
        );
    $smcFunc['db_free_result']($request);

    return $messages;
}

/**
 * Handles tracking a particular IP address
 *
 * @param int $memID The ID of a member whose IP we want to track
 */
function TrackIP($memID = 0)
{
    global $user_profile, $scripturl, $txt, $user_info, $modSettings, $sourcedir;
    global $context, $options, $smcFunc;

    // Can the user do this?
    isAllowedTo('moderate_forum');

    if ($memID == 0)
    {
        $context['ip'] = ip2range($user_info['ip']);
        loadTemplate('Profile');
        loadLanguage('Profile');
        $context['sub_template'] = 'trackIP';
        $context['page_title'] = $txt['profile'];
        $context['base_url'] = $scripturl . '?action=trackip';
    }
    else
    {
        $context['ip'] = ip2range($user_profile[$memID]['member_ip']);
        $context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
    }

    // Searching?
    if (isset($_REQUEST['searchip']))
        $context['ip'] = ip2range(trim($_REQUEST['searchip']));

    if (count($context['ip']) !== 2)
        fatal_lang_error('invalid_tracking_ip', false);

    $ip_string = array('{inet:ip_address_low}', '{inet:ip_address_high}');
    $fields = array(
        'ip_address_low' => $context['ip']['low'],
        'ip_address_high' => $context['ip']['high'],
    );

    $ip_var = $context['ip'];

    if ($context['ip']['low'] !== $context['ip']['high'])
        $context['ip'] = $context['ip']['low'] . ' - ' . $context['ip']['high'];
    else
        $context['ip'] = $context['ip']['low'];

    if (empty($context['tracking_area']))
        $context['page_title'] = $txt['trackIP'] . ' - ' . $context['ip'];

    $request = $smcFunc['db_query']('', '
        SELECT id_member, real_name AS display_name, member_ip
        FROM {db_prefix}members
        WHERE member_ip >= ' . $ip_string[0] . ' and member_ip <= ' . $ip_string[1],
        $fields
    );
    $context['ips'] = array();
    while ($row = $smcFunc['db_fetch_assoc']($request))
        $context['ips'][inet_dtop($row['member_ip'])][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>';
    $smcFunc['db_free_result']($request);

    ksort($context['ips']);

    // For messages we use the "messages per page" option
    $maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];

    // Gonna want this for the list.
    require_once($sourcedir . '/Subs-List.php');

    // Start with the user messages.
    $listOptions = array(
        'id' => 'track_message_list',
        'title' => $txt['messages_from_ip'] . ' ' . $context['ip'],
        'start_var_name' => 'messageStart',
        'items_per_page' => $maxPerPage,
        'no_items_label' => $txt['no_messages_from_ip'],
        'base_href' => $context['base_url'] . ';searchip=' . $context['ip'],
        'default_sort_col' => 'date',
        'get_items' => array(
            'function' => 'list_getIPMessages',
            'params' => array(
                'm.poster_ip >= ' . $ip_string[0] . ' and m.poster_ip <= ' . $ip_string[1],
                $fields,
            ),
        ),
        'get_count' => array(
            'function' => 'list_getIPMessageCount',
            'params' => array(
                'm.poster_ip >= ' . $ip_string[0] . ' and m.poster_ip <= ' . $ip_string[1],
                $fields,
            ),
        ),
        'columns' => array(
            'ip_address' => array(
                'header' => array(
                    'value' => $txt['ip_address'],
                ),
                'data' => array(
                    'sprintf' => array(
                        'format' => '<a href="' . $context['base_url'] . ';searchip=%1$s">%1$s</a>',
                        'params' => array(
                            'ip' => false,
                        ),
                    ),
                ),
                'sort' => array(
                    'default' => 'm.poster_ip',
                    'reverse' => 'm.poster_ip DESC',
                ),
            ),
            'poster' => array(
                'header' => array(
                    'value' => $txt['poster'],
                ),
                'data' => array(
                    'db' => 'member_link',
                ),
            ),
            'subject' => array(
                'header' => array(
                    'value' => $txt['subject'],
                ),
                'data' => array(
                    'sprintf' => array(
                        'format' => '<a href="' . $scripturl . '?topic=%1$s.msg%2$s#msg%2$s" rel="nofollow">%3$s</a>',
                        'params' => array(
                            'topic' => false,
                            'id' => false,
                            'subject' => false,
                        ),
                    ),
                ),
            ),
            'date' => array(
                'header' => array(
                    'value' => $txt['date'],
                ),
                'data' => array(
                    'db' => 'time',
                ),
                'sort' => array(
                    'default' => 'm.id_msg DESC',
                    'reverse' => 'm.id_msg',
                ),
            ),
        ),
        'additional_rows' => array(
            array(
                'position' => 'after_title',
                'value' => $txt['messages_from_ip_desc'],
            ),
        ),
    );

    // Create the messages list.
    createList($listOptions);

    // Set the options for the error lists.
    $listOptions = array(
        'id' => 'track_user_list',
        'title' => $txt['errors_from_ip'] . ' ' . $context['ip'],
        'start_var_name' => 'errorStart',
        'items_per_page' => $modSettings['defaultMaxListItems'],
        'no_items_label' => $txt['no_errors_from_ip'],
        'base_href' => $context['base_url'] . ';searchip=' . $context['ip'],
        'default_sort_col' => 'date2',
        'get_items' => array(
            'function' => 'list_getUserErrors',
            'params' => array(
                'le.ip >= ' . $ip_string[0] . ' and le.ip <= ' . $ip_string[1],
                $fields,
            ),
        ),
        'get_count' => array(
            'function' => 'list_getUserErrorCount',
            'params' => array(
                'ip >= ' . $ip_string[0] . ' and ip <= ' . $ip_string[1],
                $fields,
            ),
        ),
        'columns' => array(
            'ip_address2' => array(
                'header' => array(
                    'value' => $txt['ip_address'],
                ),
                'data' => array(
                    'sprintf' => array(
                        'format' => '<a href="' . $context['base_url'] . ';searchip=%1$s">%1$s</a>',
                        'params' => array(
                            'ip' => false,
                        ),
                    ),
                ),
                'sort' => array(
                    'default' => 'le.ip',
                    'reverse' => 'le.ip DESC',
                ),
            ),
            'display_name' => array(
                'header' => array(
                    'value' => $txt['display_name'],
                ),
                'data' => array(
                    'db' => 'member_link',
                ),
            ),
            'message' => array(
                'header' => array(
                    'value' => $txt['message'],
                ),
                'data' => array(
                    'sprintf' => array(
                        'format' => '%1$s<br><a href="%2$s">%2$s</a>',
                        'params' => array(
                            'message' => false,
                            'url' => false,
                        ),
                    ),
                ),
            ),
            'date2' => array(
                'header' => array(
                    'value' => $txt['date'],
                ),
                'data' => array(
                    'db' => 'time',
                ),
                'sort' => array(
                    'default' => 'le.id_error DESC',
                    'reverse' => 'le.id_error',
                ),
            ),
        ),
        'additional_rows' => array(
            array(
                'position' => 'after_title',
                'value' => $txt['errors_from_ip_desc'],
            ),
        ),
    );

    // Create the error list.
    createList($listOptions);

    // Allow 3rd party integrations to add in their own lists or whatever.
    $context['additional_track_lists'] = array();
    call_integration_hook('integrate_profile_trackip', array($ip_string, $ip_var));

    $context['single_ip'] = ($ip_var['low'] === $ip_var['high']);
    if ($context['single_ip'])
    {
        $context['whois_servers'] = array(
            'apnic' => array(
                'name' => $txt['whois_apnic'],
                'url' => 'https://wq.apnic.net/apnic-bin/whois.pl?searchtext=' . $context['ip'],
            ),
            'arin' => array(
                'name' => $txt['whois_arin'],
                'url' => 'https://whois.arin.net/rest/ip/' . $context['ip'],
            ),
            'lacnic' => array(
                'name' => $txt['whois_lacnic'],
                'url' => 'https://lacnic.net/cgi-bin/lacnic/whois?query=' . $context['ip'],
            ),
            'ripe' => array(
                'name' => $txt['whois_ripe'],
                'url' => 'https://apps.db.ripe.net/search/query.html?searchtext=' . $context['ip'],
            ),
        );
    }
}

/**
 * Tracks a user's logins.
 *
 * @param int $memID The ID of the member
 */
function TrackLogins($memID = 0)
{
    global $scripturl, $txt, $sourcedir, $context;

    // Gonna want this for the list.
    require_once($sourcedir . '/Subs-List.php');

    if ($memID == 0)
        $context['base_url'] = $scripturl . '?action=trackip';
    else
        $context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;

    // Start with the user messages.
    $listOptions = array(
        'id' => 'track_logins_list',
        'title' => $txt['trackLogins'],
        'no_items_label' => $txt['trackLogins_none_found'],
        'base_href' => $context['base_url'],
        'get_items' => array(
            'function' => 'list_getLogins',
            'params' => array(
                'id_member = {int:current_member}',
                array('current_member' => $memID),
            ),
        ),
        'get_count' => array(
            'function' => 'list_getLoginCount',
            'params' => array(
                'id_member = {int:current_member}',
                array('current_member' => $memID),
            ),
        ),
        'columns' => array(
            'time' => array(
                'header' => array(
                    'value' => $txt['date'],
                ),
                'data' => array(
                    'db' => 'time',
                ),
            ),
            'ip' => array(
                'header' => array(
                    'value' => $txt['ip_address'],
                ),
                'data' => array(
                    'sprintf' => array(
                        'format' => '<a href="' . $context['base_url'] . ';searchip=%1$s">%1$s</a> (<a href="' . $context['base_url'] . ';searchip=%2$s">%2$s</a>) ',
                        'params' => array(
                            'ip' => false,
                            'ip2' => false
                        ),
                    ),
                ),
            ),
        ),
        'additional_rows' => array(
            array(
                'position' => 'after_title',
                'value' => $txt['trackLogins_desc'],
            ),
        ),
    );

    // Create the messages list.
    createList($listOptions);

    $context['sub_template'] = 'show_list';
    $context['default_list'] = 'track_logins_list';
}

/**
 * Finds the total number of tracked logins for a particular user
 *
 * @param string $where A query to limit which logins are counted
 * @param array $where_vars An array of parameters for $where
 * @return int count of messages matching the IP
 */
function list_getLoginCount($where, $where_vars = array())
{
    global $smcFunc;

    $request = $smcFunc['db_query']('', '
        SELECT COUNT(*) AS message_count
        FROM {db_prefix}member_logins
        WHERE id_member = {int:id_member}',
        array(
            'id_member' => $where_vars['current_member'],
        )
    );
    list ($count) = $smcFunc['db_fetch_row']($request);
    $smcFunc['db_free_result']($request);

    return (int) $count;
}

/**
 * Callback for the list in trackLogins.
 *
 * @param int $start Which item to start with (not used here)
 * @param int $items_per_page How many items to show on each page (not used here)
 * @param string $sort A string indicating
 * @param string $where A query to filter results (not used here)
 * @param array $where_vars An array of parameters for $where. Only 'current_member' (the ID of the member) is used here
 * @return array An array of information about user logins
 */
function list_getLogins($start, $items_per_page, $sort, $where, $where_vars = array())
{
    global $smcFunc;

    $request = $smcFunc['db_query']('', '
        SELECT time, ip, ip2
        FROM {db_prefix}member_logins
        WHERE id_member = {int:id_member}
        ORDER BY time DESC',
        array(
            'id_member' => $where_vars['current_member'],
        )
    );
    $logins = array();
    while ($row = $smcFunc['db_fetch_assoc']($request))
        $logins[] = array(
            'time' => timeformat($row['time']),
            'ip' => inet_dtop($row['ip']),
            'ip2' => inet_dtop($row['ip2']),
        );
    $smcFunc['db_free_result']($request);

    return $logins;
}

/**
 * Tracks a user's profile edits
 *
 * @param int $memID The ID of the member
 */
function trackEdits($memID)
{
    global $scripturl, $txt, $modSettings, $sourcedir, $context, $smcFunc;

    require_once($sourcedir . '/Subs-List.php');

    // Get the names of any custom fields.
    $request = $smcFunc['db_query']('', '
        SELECT col_name, field_name, bbc
        FROM {db_prefix}custom_fields',
        array(
        )
    );
    $context['custom_field_titles'] = array();
    while ($row = $smcFunc['db_fetch_assoc']($request))
        $context['custom_field_titles']['customfield_' . $row['col_name']] = array(
            'title' => $row['field_name'],
            'parse_bbc' => $row['bbc'],
        );
    $smcFunc['db_free_result']($request);

    // Set the options for the error lists.
    $listOptions = array(
        'id' => 'edit_list',
        'title' => $txt['trackEdits'],
        'items_per_page' => $modSettings['defaultMaxListItems'],
        'no_items_label' => $txt['trackEdit_no_edits'],
        'base_href' => $scripturl . '?action=profile;area=tracking;sa=edits;u=' . $memID,
        'default_sort_col' => 'time',
        'get_items' => array(
            'function' => 'list_getProfileEdits',
            'params' => array(
                $memID,
            ),
        ),
        'get_count' => array(
            'function' => 'list_getProfileEditCount',
            'params' => array(
                $memID,
            ),
        ),
        'columns' => array(
            'action' => array(
                'header' => array(
                    'value' => $txt['trackEdit_action'],
                ),
                'data' => array(
                    'db' => 'action_text',
                ),
            ),
            'before' => array(
                'header' => array(
                    'value' => $txt['trackEdit_before'],
                ),
                'data' => array(
                    'db' => 'before',
                ),
            ),
            'after' => array(
                'header' => array(
                    'value' => $txt['trackEdit_after'],
                ),
                'data' => array(
                    'db' => 'after',
                ),
            ),
            'time' => array(
                'header' => array(
                    'value' => $txt['date'],
                ),
                'data' => array(
                    'db' => 'time',
                ),
                'sort' => array(
                    'default' => 'id_action DESC',
                    'reverse' => 'id_action',
                ),
            ),
            'applicator' => array(
                'header' => array(
                    'value' => $txt['trackEdit_applicator'],
                ),
                'data' => array(
                    'db' => 'member_link',
                ),
            ),
        ),
    );

    // Create the error list.
    createList($listOptions);

    $context['sub_template'] = 'show_list';
    $context['default_list'] = 'edit_list';
}

/**
 * How many edits?
 *
 * @param int $memID The ID of the member
 * @return int The number of profile edits
 */
function list_getProfileEditCount($memID)
{
    global $smcFunc;

    $request = $smcFunc['db_query']('', '
        SELECT COUNT(*) AS edit_count
        FROM {db_prefix}log_actions
        WHERE id_log = {int:log_type}
            AND id_member = {int:owner}',
        array(
            'log_type' => 2,
            'owner' => $memID,
        )
    );
    list ($edit_count) = $smcFunc['db_fetch_row']($request);
    $smcFunc['db_free_result']($request);

    return (int) $edit_count;
}

/**
 * Loads up information about a user's profile edits. Callback for the list in trackEdits()
 *
 * @param int $start Which item to start with (for pagination purposes)
 * @param int $items_per_page How many items to show on each page
 * @param string $sort A string indicating how to sort the results
 * @param int $memID The ID of the member
 * @return array An array of information about the profile edits
 */
function list_getProfileEdits($start, $items_per_page, $sort, $memID)
{
    global $smcFunc, $txt, $scripturl, $context;

    // Get a list of error messages from this ip (range).
    $request = $smcFunc['db_query']('', '
        SELECT
            id_action, id_member, ip, log_time, action, extra
        FROM {db_prefix}log_actions
        WHERE id_log = {int:log_type}
            AND id_member = {int:owner}
        ORDER BY {raw:sort}
        LIMIT {int:start}, {int:max}',
        array(
            'log_type' => 2,
            'owner' => $memID,
            'sort' => $sort,
            'start' => $start,
            'max' => $items_per_page,
        )
    );
    $edits = array();
    $members = array();
    while ($row = $smcFunc['db_fetch_assoc']($request))
    {
        $extra = $smcFunc['json_decode']($row['extra'], true);
        if (!empty($extra['applicator']))
            $members[] = $extra['applicator'];

        // Work out what the name of the action is.
        if (isset($txt['trackEdit_action_' . $row['action']]))
            $action_text = $txt['trackEdit_action_' . $row['action']];
        elseif (isset($txt[$row['action']]))
            $action_text = $txt[$row['action']];
        // Custom field?
        elseif (isset($context['custom_field_titles'][$row['action']]))
            $action_text = $context['custom_field_titles'][$row['action']]['title'];
        else
            $action_text = $row['action'];

        // Parse BBC?
        $parse_bbc = isset($context['custom_field_titles'][$row['action']]) && $context['custom_field_titles'][$row['action']]['parse_bbc'] ? true : false;

        $edits[] = array(
            'id' => $row['id_action'],
            'ip' => inet_dtop($row['ip']),
            'id_member' => !empty($extra['applicator']) ? $extra['applicator'] : 0,
            'member_link' => $txt['trackEdit_deleted_member'],
            'action' => $row['action'],
            'action_text' => $action_text,
            'before' => !empty($extra['previous']) ? ($parse_bbc ? parse_bbc($extra['previous']) : $extra['previous']) : '',
            'after' => !empty($extra['new']) ? ($parse_bbc ? parse_bbc($extra['new']) : $extra['new']) : '',
            'time' => timeformat($row['log_time']),
        );
    }
    $smcFunc['db_free_result']($request);

    // Get any member names.
    if (!empty($members))
    {
        $request = $smcFunc['db_query']('', '
            SELECT
                id_member, real_name
            FROM {db_prefix}members
            WHERE id_member IN ({array_int:members})',
            array(
                'members' => $members,
            )
        );
        $members = array();
        while ($row = $smcFunc['db_fetch_assoc']($request))
            $members[$row['id_member']] = $row['real_name'];
        $smcFunc['db_free_result']($request);

        foreach ($edits as $key => $value)
            if (isset($members[$value['id_member']]))
                $edits[$key]['member_link'] = '<a href="' . $scripturl . '?action=profile;u=' . $value['id_member'] . '">' . $members[$value['id_member']] . '</a>';
    }

    return $edits;
}

/**
 * Display the history of group requests made by the user whose profile we are viewing.
 *
 * @param int $memID The ID of the member
 */
function trackGroupReq($memID)
{
    global $scripturl, $txt, $modSettings, $sourcedir, $context;

    require_once($sourcedir . '/Subs-List.php');

    // Set the options for the error lists.
    $listOptions = array(
        'id' => 'request_list',
        'title' => sprintf($txt['trackGroupRequests_title'], $context['member']['name']),
        'items_per_page' => $modSettings['defaultMaxListItems'],
        'no_items_label' => $txt['requested_none'],
        'base_href' => $scripturl . '?action=profile;area=tracking;sa=groupreq;u=' . $memID,
        'default_sort_col' => 'time_applied',
        'get_items' => array(
            'function' => 'list_getGroupRequests',
            'params' => array(
                $memID,
            ),
        ),
        'get_count' => array(
            'function' => 'list_getGroupRequestsCount',
            'params' => array(
                $memID,
            ),
        ),
        'columns' => array(
            'group' => array(
                'header' => array(
                    'value' => $txt['requested_group'],
                ),
                'data' => array(
                    'db' => 'group_name',
                ),
            ),
            'group_reason' => array(
                'header' => array(
                    'value' => $txt['requested_group_reason'],
                ),
                'data' => array(
                    'db' => 'group_reason',
                ),
            ),
            'time_applied' => array(
                'header' => array(
                    'value' => $txt['requested_group_time'],
                ),
                'data' => array(
                    'db' => 'time_applied',
                    'timeformat' => true,
                ),
                'sort' => array(
                    'default' => 'time_applied DESC',
                    'reverse' => 'time_applied',
                ),
            ),
            'outcome' => array(
                'header' => array(
                    'value' => $txt['requested_group_outcome'],
                ),
                'data' => array(
                    'db' => 'outcome',
                ),
            ),
        ),
    );

    // Create the error list.
    createList($listOptions);

    $context['sub_template'] = 'show_list';
    $context['default_list'] = 'request_list';
}

/**
 * How many edits?
 *
 * @param int $memID The ID of the member
 * @return int The number of profile edits
 */
function list_getGroupRequestsCount($memID)
{
    global $smcFunc, $user_info;

    $request = $smcFunc['db_query']('', '
        SELECT COUNT(*) AS req_count
        FROM {db_prefix}log_group_requests AS lgr
        WHERE id_member = {int:memID}
            AND ' . ($user_info['mod_cache']['gq'] == '1=1' ? $user_info['mod_cache']['gq'] : 'lgr.' . $user_info['mod_cache']['gq']),
        array(
            'memID' => $memID,
        )
    );
    list ($report_count) = $smcFunc['db_fetch_row']($request);
    $smcFunc['db_free_result']($request);

    return (int) $report_count;
}

/**
 * Loads up information about a user's group requests. Callback for the list in trackGroupReq()
 *
 * @param int $start Which item to start with (for pagination purposes)
 * @param int $items_per_page How many items to show on each page
 * @param string $sort A string indicating how to sort the results
 * @param int $memID The ID of the member
 * @return array An array of information about the user's group requests
 */
function list_getGroupRequests($start, $items_per_page, $sort, $memID)
{
    global $smcFunc, $txt, $scripturl, $user_info;

    $groupreq = array();

    $request = $smcFunc['db_query']('', '
        SELECT
            lgr.id_group, mg.group_name, mg.online_color, lgr.time_applied, lgr.reason, lgr.status,
            ma.id_member AS id_member_acted, COALESCE(ma.member_name, lgr.member_name_acted) AS act_name, lgr.time_acted, lgr.act_reason
        FROM {db_prefix}log_group_requests AS lgr
            LEFT JOIN {db_prefix}members AS ma ON (lgr.id_member_acted = ma.id_member)
            INNER JOIN {db_prefix}membergroups AS mg ON (lgr.id_group = mg.id_group)
        WHERE lgr.id_member = {int:memID}
            AND ' . ($user_info['mod_cache']['gq'] == '1=1' ? $user_info['mod_cache']['gq'] : 'lgr.' . $user_info['mod_cache']['gq']) . '
        ORDER BY {raw:sort}
        LIMIT {int:start}, {int:max}',
        array(
            'memID' => $memID,
            'sort' => $sort,
            'start' => $start,
            'max' => $items_per_page,
        )
    );
    while ($row = $smcFunc['db_fetch_assoc']($request))
    {
        $this_req = array(
            'group_name' => empty($row['online_color']) ? $row['group_name'] : '<span style="color:' . $row['online_color'] . '">' . $row['group_name'] . '</span>',
            'group_reason' => $row['reason'],
            'time_applied' => $row['time_applied'],
        );
        switch ($row['status'])
        {
            case 0:
                $this_req['outcome'] = $txt['outcome_pending'];
                break;
            case 1:
                $member_link = empty($row['id_member_acted']) ? $row['act_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member_acted'] . '">' . $row['act_name'] . '</a>';
                $this_req['outcome'] = sprintf($txt['outcome_approved'], $member_link, timeformat($row['time_acted']));
                break;
            case 2:
                $member_link = empty($row['id_member_acted']) ? $row['act_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member_acted'] . '">' . $row['act_name'] . '</a>';
                $this_req['outcome'] = sprintf(!empty($row['act_reason']) ? $txt['outcome_refused_reason'] : $txt['outcome_refused'], $member_link, timeformat($row['time_acted']), $row['act_reason']);
                break;
        }

        $groupreq[] = $this_req;
    }
    $smcFunc['db_free_result']($request);

    return $groupreq;
}

/**
 * Shows which permissions a user has
 *
 * @param int $memID The ID of the member
 */
function showPermissions($memID)
{
    global $txt, $board;
    global $user_profile, $context, $sourcedir, $smcFunc;

    // Verify if the user has sufficient permissions.
    isAllowedTo('manage_permissions');

    loadLanguage('ManagePermissions');
    loadLanguage('Admin');
    loadTemplate('ManageMembers');

    // Load all the permission profiles.
    require_once($sourcedir . '/ManagePermissions.php');
    loadPermissionProfiles();

    $context['member']['id'] = $memID;
    $context['member']['name'] = $user_profile[$memID]['real_name'];

    $context['page_title'] = $txt['showPermissions'];
    $board = empty($board) ? 0 : (int) $board;
    $context['board'] = $board;

    // Determine which groups this user is in.
    if (empty($user_profile[$memID]['additional_groups']))
        $curGroups = array();
    else
        $curGroups = explode(',', $user_profile[$memID]['additional_groups']);
    $curGroups[] = $user_profile[$memID]['id_group'];
    $curGroups[] = $user_profile[$memID]['id_post_group'];

    // Load a list of boards for the jump box - except the defaults.
    $request = $smcFunc['db_query']('order_by_board_order', '
        SELECT b.id_board, b.name, b.id_profile, b.member_groups, COALESCE(mods.id_member, modgs.id_group, 0) AS is_mod
        FROM {db_prefix}boards AS b
            LEFT JOIN {db_prefix}moderators AS mods ON (mods.id_board = b.id_board AND mods.id_member = {int:current_member})
            LEFT JOIN {db_prefix}moderator_groups AS modgs ON (modgs.id_board = b.id_board AND modgs.id_group IN ({array_int:current_groups}))
        WHERE {query_see_board}',
        array(
            'current_member' => $memID,
            'current_groups' => $curGroups,
        )
    );
    $context['boards'] = array();
    $context['no_access_boards'] = array();
    while ($row = $smcFunc['db_fetch_assoc']($request))
    {
        if (count(array_intersect($curGroups, explode(',', $row['member_groups']))) === 0 && !$row['is_mod'])
            $context['no_access_boards'][] = array(
                'id' => $row['id_board'],
                'name' => $row['name'],
                'is_last' => false,
            );
        elseif ($row['id_profile'] != 1 || $row['is_mod'])
            $context['boards'][$row['id_board']] = array(
                'id' => $row['id_board'],
                'name' => $row['name'],
                'selected' => $board == $row['id_board'],
                'profile' => $row['id_profile'],
                'profile_name' => $context['profiles'][$row['id_profile']]['name'],
            );
    }
    $smcFunc['db_free_result']($request);

    require_once($sourcedir . '/Subs-Boards.php');
    sortBoards($context['boards']);

    if (!empty($context['no_access_boards']))
        $context['no_access_boards'][count($context['no_access_boards']) - 1]['is_last'] = true;

    $context['member']['permissions'] = array(
        'general' => array(),
        'board' => array()
    );

    // If you're an admin we know you can do everything, we might as well leave.
    $context['member']['has_all_permissions'] = in_array(1, $curGroups);
    if ($context['member']['has_all_permissions'])
        return;

    $denied = array();

    // Get all general permissions.
    $result = $smcFunc['db_query']('', '
        SELECT p.permission, p.add_deny, mg.group_name, p.id_group
        FROM {db_prefix}permissions AS p
            LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = p.id_group)
        WHERE p.id_group IN ({array_int:group_list})
        ORDER BY p.add_deny DESC, p.permission, mg.min_posts, CASE WHEN mg.id_group < {int:newbie_group} THEN mg.id_group ELSE 4 END, mg.group_name',
        array(
            'group_list' => $curGroups,
            'newbie_group' => 4,
        )
    );
    while ($row = $smcFunc['db_fetch_assoc']($result))
    {
        // We don't know about this permission, it doesn't exist :P.
        if (!isset($txt['permissionname_' . $row['permission']]))
            continue;

        if (empty($row['add_deny']))
            $denied[] = $row['permission'];

        // Permissions that end with _own or _any consist of two parts.
        if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)]))
            $name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
        else
            $name = $txt['permissionname_' . $row['permission']];

        // Add this permission if it doesn't exist yet.
        if (!isset($context['member']['permissions']['general'][$row['permission']]))
            $context['member']['permissions']['general'][$row['permission']] = array(
                'id' => $row['permission'],
                'groups' => array(
                    'allowed' => array(),
                    'denied' => array()
                ),
                'name' => $name,
                'is_denied' => false,
                'is_global' => true,
            );

        // Add the membergroup to either the denied or the allowed groups.
        $context['member']['permissions']['general'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name'];

        // Once denied is always denied.
        $context['member']['permissions']['general'][$row['permission']]['is_denied'] |= empty($row['add_deny']);
    }
    $smcFunc['db_free_result']($result);

    $request = $smcFunc['db_query']('', '
        SELECT
            bp.add_deny, bp.permission, bp.id_group, mg.group_name' . (empty($board) ? '' : ',
            b.id_profile, CASE WHEN (mods.id_member IS NULL AND modgs.id_group IS NULL) THEN 0 ELSE 1 END AS is_moderator') . '
        FROM {db_prefix}board_permissions AS bp' . (empty($board) ? '' : '
            INNER JOIN {db_prefix}boards AS b ON (b.id_board = {int:current_board})
            LEFT JOIN {db_prefix}moderators AS mods ON (mods.id_board = b.id_board AND mods.id_member = {int:current_member})
            LEFT JOIN {db_prefix}moderator_groups AS modgs ON (modgs.id_board = b.id_board AND modgs.id_group IN ({array_int:group_list}))') . '
            LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = bp.id_group)
        WHERE bp.id_profile = {raw:current_profile}
            AND bp.id_group IN ({array_int:group_list}' . (empty($board) ? ')' : ', {int:moderator_group})
            AND (mods.id_member IS NOT NULL OR modgs.id_group IS NOT NULL OR bp.id_group != {int:moderator_group})'),
        array(
            'current_board' => $board,
            'group_list' => $curGroups,
            'current_member' => $memID,
            'current_profile' => empty($board) ? '1' : 'b.id_profile',
            'moderator_group' => 3,
        )
    );

    while ($row = $smcFunc['db_fetch_assoc']($request))
    {
        // We don't know about this permission, it doesn't exist :P.
        if (!isset($txt['permissionname_' . $row['permission']]))
            continue;

        // The name of the permission using the format 'permission name' - 'own/any topic/event/etc.'.
        if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)]))
            $name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
        else
            $name = $txt['permissionname_' . $row['permission']];

        // Create the structure for this permission.
        if (!isset($context['member']['permissions']['board'][$row['permission']]))
            $context['member']['permissions']['board'][$row['permission']] = array(
                'id' => $row['permission'],
                'groups' => array(
                    'allowed' => array(),
                    'denied' => array()
                ),
                'name' => $name,
                'is_denied' => false,
                'is_global' => empty($board),
            );

        $context['member']['permissions']['board'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][$row['id_group']] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name'];

        $context['member']['permissions']['board'][$row['permission']]['is_denied'] |= empty($row['add_deny']);
    }
    $smcFunc['db_free_result']($request);
}

/**
 * View a member's warnings
 *
 * @param int $memID The ID of the member
 */
function viewWarning($memID)
{
    global $modSettings, $context, $sourcedir, $txt, $scripturl;

    // Firstly, can we actually even be here?
    if (!($context['user']['is_owner'] && allowedTo('view_warning_own')) && !allowedTo('view_warning_any') && !allowedTo('issue_warning') && !allowedTo('moderate_forum'))
        fatal_lang_error('no_access', false);

    // Make sure things which are disabled stay disabled.
    $modSettings['warning_watch'] = !empty($modSettings['warning_watch']) ? $modSettings['warning_watch'] : 110;
    $modSettings['warning_moderate'] = !empty($modSettings['warning_moderate']) && !empty($modSettings['postmod_active']) ? $modSettings['warning_moderate'] : 110;
    $modSettings['warning_mute'] = !empty($modSettings['warning_mute']) ? $modSettings['warning_mute'] : 110;

    // Let's use a generic list to get all the current warnings, and use the issue warnings grab-a-granny thing.
    require_once($sourcedir . '/Subs-List.php');
    require_once($sourcedir . '/Profile-Actions.php');

    $listOptions = array(
        'id' => 'view_warnings',
        'title' => $txt['profile_viewwarning_previous_warnings'],
        'items_per_page' => $modSettings['defaultMaxListItems'],
        'no_items_label' => $txt['profile_viewwarning_no_warnings'],
        'base_href' => $scripturl . '?action=profile;area=viewwarning;sa=user;u=' . $memID,
        'default_sort_col' => 'log_time',
        'get_items' => array(
            'function' => 'list_getUserWarnings',
            'params' => array(
                $memID,
            ),
        ),
        'get_count' => array(
            'function' => 'list_getUserWarningCount',
            'params' => array(
                $memID,
            ),
        ),
        'columns' => array(
            'log_time' => array(
                'header' => array(
                    'value' => $txt['profile_warning_previous_time'],
                ),
                'data' => array(
                    'db' => 'time',
                ),
                'sort' => array(
                    'default' => 'lc.log_time DESC',
                    'reverse' => 'lc.log_time',
                ),
            ),
            'reason' => array(
                'header' => array(
                    'value' => $txt['profile_warning_previous_reason'],
                    'style' => 'width: 50%;',
                ),
                'data' => array(
                    'db' => 'reason',
                ),
            ),
            'level' => array(
                'header' => array(
                    'value' => $txt['profile_warning_previous_level'],
                ),
                'data' => array(
                    'db' => 'counter',
                ),
                'sort' => array(
                    'default' => 'lc.counter DESC',
                    'reverse' => 'lc.counter',
                ),
            ),
        ),
        'additional_rows' => array(
            array(
                'position' => 'after_title',
                'value' => $txt['profile_viewwarning_desc'],
                'class' => 'smalltext',
                'style' => 'padding: 2ex;',
            ),
        ),
    );

    // Create the list for viewing.
    require_once($sourcedir . '/Subs-List.php');
    createList($listOptions);

    // Create some common text bits for the template.
    $context['level_effects'] = array(
        0 => '',
        $modSettings['warning_watch'] => $txt['profile_warning_effect_own_watched'],
        $modSettings['warning_moderate'] => $txt['profile_warning_effect_own_moderated'],
        $modSettings['warning_mute'] => $txt['profile_warning_effect_own_muted'],
    );
    $context['current_level'] = 0;
    foreach ($context['level_effects'] as $limit => $dummy)
        if ($context['member']['warning'] >= $limit)
            $context['current_level'] = $limit;
}

/**
 * Sets the icon for a fetched alert.
 *
 * @param array The alert that we want to set an icon for.
 */
function set_alert_icon($alert)
{
    global $settings;

    switch ($alert['content_type'])
    {
        case 'topic':
        case 'board':
            {
                switch ($alert['content_action'])
                {
                    case 'reply':
                    case 'topic':
                        $class = 'main_icons posts';
                        break;

                    case 'move':
                        $src = $settings['images_url'] . '/post/moved.png';
                        break;

                    case 'remove':
                        $class = 'main_icons delete';
                        break;

                    case 'lock':
                    case 'unlock':
                        $class = 'main_icons lock';
                        break;

                    case 'sticky':
                    case 'unsticky':
                        $class = 'main_icons sticky';
                        break;

                    case 'split':
                        $class = 'main_icons split_button';
                        break;

                    case 'merge':
                        $class = 'main_icons merge';
                        break;

                    case 'unapproved_topic':
                    case 'unapproved_post':
                        $class = 'main_icons post_moderation_moderate';
                        break;

                    default:
                        $class = 'main_icons posts';
                        break;
                }
            }
            break;

        case 'msg':
            {
                switch ($alert['content_action'])
                {
                    case 'like':
                        $class = 'main_icons like';
                        break;

                    case 'mention':
                        $class = 'main_icons im_on';
                        break;

                    case 'quote':
                        $class = 'main_icons quote';
                        break;

                    case 'unapproved_attachment':
                        $class = 'main_icons post_moderation_attach';
                        break;

                    case 'report':
                    case 'report_reply':
                        $class = 'main_icons post_moderation_moderate';
                        break;

                    default:
                        $class = 'main_icons posts';
                        break;
                }
            }
            break;

        case 'member':
            {
                switch ($alert['content_action'])
                {
                    case 'register_standard':
                    case 'register_approval':
                    case 'register_activation':
                        $class = 'main_icons members';
                        break;

                    case 'report':
                    case 'report_reply':
                        $class = 'main_icons members_watched';
                        break;

                    case 'buddy_request':
                        $class = 'main_icons people';
                        break;

                    case 'group_request':
                        $class = 'main_icons members_request';
                        break;

                    default:
                        $class = 'main_icons members';
                        break;
                }
            }
            break;

        case 'groupr':
            $class = 'main_icons members_request';
            break;

        case 'event':
            $class = 'main_icons calendar';
            break;

        case 'paidsubs':
            $class = 'main_icons paid';
            break;

        case 'birthday':
            $src = $settings['images_url'] . '/cake.png';
            break;

        default:
            $class = 'main_icons alerts';
            break;
    }

    if (isset($class))
        return '<span class="alert_icon ' . $class . '"></span>';
    elseif (isset($src))
        return '<img class="alert_icon" src="' . $src . '">';
    else
        return '';
}

?>
API documentation generated by ApiGen