diff --git a/.cliffignore b/.cliffignore
new file mode 100644
index 000000000..187668fd1
--- /dev/null
+++ b/.cliffignore
@@ -0,0 +1,7 @@
+9766c534bddad8e82e6d19f9bad5cf70b9887f9a
+92ce77ec0ec703c08a659419087a373f76e711f7
+2d53efc945c7747be1755d0b66557a86bdc12cbd
+602137b65129b817811b80975a369ebde3270c6d
+4eb26ae37e1f4c82a45961517ffeb54c20200408
+e59adce848a9e10ee5775254045cbbd915236b8b
+9e0a64108d62236ab07b3f8d10e8c78269b8e1d1
diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 000000000..ddde48ba4
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,19 @@
+# EditorConfig helps developers define and maintain consistent
+# coding styles between different editors and IDEs
+# editorconfig.org
+
+root = true
+
+[*]
+end_of_line = lf
+charset = utf-8
+trim_trailing_whitespace = true
+insert_final_newline = true
+indent_style = space
+indent_size = 2
+
+[*.{diff,md}]
+trim_trailing_whitespace = false
+
+[*.{php,tpl}]
+indent_size = 4
diff --git a/.env.example b/.env.example
new file mode 100644
index 000000000..c0776eda9
--- /dev/null
+++ b/.env.example
@@ -0,0 +1,13 @@
+# Common params
+TP_HOST=example.com
+TP_PORT=80
+APP_ENV=production
+APP_CRON_ENABLED=true
+APP_DEMO_MODE=false
+
+# Database credentials
+DB_HOST=localhost
+DB_PORT=3306
+DB_DATABASE=torrentpier
+DB_USERNAME=root
+DB_PASSWORD=secret
diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml
new file mode 100644
index 000000000..0baf955a6
--- /dev/null
+++ b/.github/FUNDING.yml
@@ -0,0 +1,4 @@
+# These are supported funding model platforms
+
+github: torrentpier
+open_collective: torrentpier
diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml
new file mode 100644
index 000000000..c3a7bf266
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/bug_report.yml
@@ -0,0 +1,62 @@
+name: Bug Report
+description: File a bug report
+title: "[Bug]"
+labels: [Bug]
+body:
+ - type: markdown
+ attributes:
+ value: |
+ Thanks for taking the time to fill out this bug report!
+ The more detailed this bug report is, the faster it can be reviewed and fixed.
+ - type: input
+ id: version-torrentpier
+ attributes:
+ label: TorrentPier Version
+ description: TorrentPier version your using?
+ placeholder: 2.4.0
+ validations:
+ required: true
+ - type: input
+ id: version-php-os
+ attributes:
+ label: PHP & Platform
+ description: Exact PHP and Platform (OS) versions your using.
+ placeholder: 8.2.2 - Ubuntu 22.04 x64
+ validations:
+ required: true
+ - type: checkboxes
+ id: requirements
+ attributes:
+ label: Have you done this?
+ options:
+ - label: I am willing to share my stack trace and logs
+ required: true
+ - label: I can suggest a fix as a Pull Request
+ required: false
+ - type: textarea
+ id: expectation
+ attributes:
+ label: Expectation
+ description: Write what you expect to (correctly) happen.
+ placeholder: When I do this, I expect to this to happen.
+ validations:
+ required: true
+ - type: textarea
+ id: description
+ attributes:
+ label: Description
+ description: Write what (incorrectly) happens instead.
+ placeholder: Instead, when I do this, I receive that.
+ validations:
+ required: true
+ - type: textarea
+ id: logs
+ attributes:
+ label: Stack trace & logs
+ description: |
+ If you have a stack trace, you can copy it here. You may hide sensitive information.
+ Including a stack trace when reporting an error 500 is required.
+ placeholder: This is automatically formatted into code, no need for backticks.
+ render: shell
+ validations:
+ required: false
diff --git a/.github/ISSUE_TEMPLATE/feature---enhancement-request.md b/.github/ISSUE_TEMPLATE/feature---enhancement-request.md
new file mode 100644
index 000000000..9f68fc3a6
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/feature---enhancement-request.md
@@ -0,0 +1,7 @@
+---
+name: Feature / Enhancement request
+about: Suggest an idea for TorrentPier
+title: "[Feature]"
+labels: [Feature, Enhancement]
+assignees: ''
+---
diff --git a/.github/dependabot.yml b/.github/dependabot.yml
new file mode 100644
index 000000000..28f94a001
--- /dev/null
+++ b/.github/dependabot.yml
@@ -0,0 +1,16 @@
+# To get started with Dependabot version updates, you'll need to specify which
+# package ecosystems to update and where the package manifests are located.
+# Please see the documentation for all configuration options:
+# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
+
+version: 2
+
+updates:
+ - package-ecosystem: "composer"
+ directory: "/"
+ versioning-strategy: increase-if-necessary
+ commit-message:
+ prefix: "Composer"
+ include: "scope"
+ schedule:
+ interval: "daily"
diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml
new file mode 100644
index 000000000..f257360c6
--- /dev/null
+++ b/.github/workflows/cd.yml
@@ -0,0 +1,80 @@
+name: Continuous Deployment
+
+on:
+ push:
+ tags:
+ - "v*.*.*"
+
+jobs:
+ generate-changelog:
+ name: Generate changelog
+ runs-on: ubuntu-22.04
+ outputs:
+ release_body: ${{ steps.git-cliff.outputs.content }}
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v4
+ with:
+ fetch-depth: 0
+
+ - name: Generate a changelog
+ uses: orhun/git-cliff-action@v4
+ id: git-cliff
+ with:
+ config: cliff.toml
+ args: -vv --latest --no-exec --github-repo ${{ github.repository }}
+
+ - name: Print the changelog
+ run: cat "${{ steps.git-cliff.outputs.changelog }}"
+
+ release:
+ name: Create release
+ needs: [ generate-changelog ]
+ runs-on: ubuntu-22.04
+
+ steps:
+ - uses: actions/checkout@v4
+ - name: Set the release version
+ shell: bash
+ run: echo "RELEASE_VERSION=${GITHUB_REF:11}" >> $GITHUB_ENV
+
+ - name: Setup PHP
+ uses: shivammathur/setup-php@v2
+ with:
+ php-version: '8.2'
+
+ - name: Install Composer dependencies
+ run: composer install --no-dev --no-progress --prefer-dist --optimize-autoloader
+
+ - name: Cleanup
+ run: php _cleanup.php && rm _cleanup.php
+
+ - name: Create archive
+ id: create-zip
+ run: |
+ ZIP_NAME="torrentpier-v${{ env.RELEASE_VERSION }}.zip"
+ zip -r "$ZIP_NAME" . -x ".git/*"
+ echo "ZIP_NAME=$ZIP_NAME" >> $GITHUB_OUTPUT
+
+ - name: Publish to GitHub
+ if: ${{ !contains(github.ref, '-') }}
+ uses: svenstaro/upload-release-action@v2
+ with:
+ repo_token: ${{ secrets.GITHUB_TOKEN }}
+ file: ${{ steps.create-zip.outputs.ZIP_NAME }}
+ overwrite: true
+ tag: ${{ github.ref }}
+ release_name: "v${{ env.RELEASE_VERSION }}"
+ body: "${{ needs.generate-changelog.outputs.release_body }}"
+
+ - name: Publish to GitHub (pre-release)
+ if: ${{ contains(github.ref, '-') }}
+ uses: svenstaro/upload-release-action@v2
+ with:
+ repo_token: ${{ secrets.GITHUB_TOKEN }}
+ file: ${{ steps.create-zip.outputs.ZIP_NAME }}
+ overwrite: true
+ tag: ${{ github.ref }}
+ release_name: "v${{ env.RELEASE_VERSION }}"
+ body: "${{ needs.generate-changelog.outputs.release_body }}"
+ prerelease: true
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
new file mode 100644
index 000000000..d4fd0b722
--- /dev/null
+++ b/.github/workflows/ci.yml
@@ -0,0 +1,45 @@
+name: Continuous Integration
+
+on:
+ push:
+ branches:
+ - master
+
+jobs:
+ nightly:
+ name: Nightly builds 📦
+ runs-on: ubuntu-22.04
+
+ steps:
+ - name: Checkout code 🗳
+ uses: actions/checkout@v4
+
+ - name: Setup PHP 🔩
+ uses: shivammathur/setup-php@v2
+ with:
+ php-version: '8.2'
+
+ - name: Install Composer dependencies 🪚
+ run: composer install --no-dev --no-progress --prefer-dist --optimize-autoloader
+
+ - name: Get commit hash 🔗
+ id: get-commit-hash
+ run: |
+ COMMIT_HASH=$(git rev-parse --short HEAD)
+ echo "COMMIT_HASH=$COMMIT_HASH" >> $GITHUB_OUTPUT
+
+ - name: Cleanup
+ run: php _cleanup.php && rm _cleanup.php
+
+ - name: Create archive 🗞
+ id: create-zip
+ run: |
+ ZIP_NAME="torrentpier-${{ steps.get-commit-hash.outputs.COMMIT_HASH }}.zip"
+ zip -r "$ZIP_NAME" . -x ".git/*"
+ echo "ZIP_NAME=$ZIP_NAME" >> $GITHUB_OUTPUT
+
+ - name: Upload Archive 📤
+ uses: actions/upload-artifact@v4
+ with:
+ name: TorrentPier-master
+ path: ${{ steps.create-zip.outputs.ZIP_NAME }}
diff --git a/.github/workflows/phpmd.yml b/.github/workflows/phpmd.yml
new file mode 100644
index 000000000..3e06d7538
--- /dev/null
+++ b/.github/workflows/phpmd.yml
@@ -0,0 +1,57 @@
+# This workflow uses actions that are not certified by GitHub.
+# They are provided by a third-party and are governed by
+# separate terms of service, privacy policy, and support
+# documentation.
+# PHPMD is a spin-off project of PHP Depend and
+# aims to be a PHP equivalent of the well known Java tool PMD.
+# What PHPMD does is: It takes a given PHP source code base
+# and look for several potential problems within that source.
+# These problems can be things like:
+# Possible bugs
+# Suboptimal code
+# Overcomplicated expressions
+# Unused parameters, methods, properties
+# More details at https://phpmd.org/
+
+name: PHPMD
+
+on:
+ push:
+ branches: [ "master" ]
+ pull_request:
+ # The branches below must be a subset of the branches above
+ branches: [ "master" ]
+ schedule:
+ - cron: '40 0 * * 3'
+
+permissions:
+ contents: read
+
+jobs:
+ PHPMD:
+ name: Run PHPMD scanning
+ runs-on: ubuntu-latest
+ permissions:
+ contents: read # for checkout to fetch code
+ security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
+ actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
+
+ steps:
+ - name: Checkout code
+ uses: actions/checkout@v3
+
+ - name: Setup PHP
+ uses: shivammathur/setup-php@aa1fe473f9c687b6fb896056d771232c0bc41161
+ with:
+ coverage: none
+ tools: phpmd
+
+ - name: Run PHPMD
+ run: phpmd . sarif codesize --reportfile phpmd-results.sarif
+ continue-on-error: true
+
+ - name: Upload analysis results to GitHub
+ uses: github/codeql-action/upload-sarif@v2
+ with:
+ sarif_file: phpmd-results.sarif
+ wait-for-processing: true
diff --git a/.github/workflows/schedule.yml b/.github/workflows/schedule.yml
new file mode 100644
index 000000000..c1ad4f3c1
--- /dev/null
+++ b/.github/workflows/schedule.yml
@@ -0,0 +1,41 @@
+name: Changelog generation
+
+on:
+ schedule:
+ - cron: '0 0 * * *'
+ workflow_dispatch:
+
+jobs:
+ changelog:
+ name: Changelog generation
+ runs-on: ubuntu-22.04
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v4
+ with:
+ fetch-depth: 0
+ ref: master
+ token: ${{ secrets.REPO_TOKEN }}
+
+ - name: Generate a changelog
+ uses: orhun/git-cliff-action@v4
+ id: git-cliff
+ with:
+ config: cliff.toml
+ args: v2.4.6-alpha.4.. --verbose
+ env:
+ OUTPUT: CHANGELOG.md
+ GITHUB_REPO: ${{ github.repository }}
+
+ - name: Print the changelog
+ run: cat "${{ steps.git-cliff.outputs.changelog }}"
+
+ - name: Commit changelog
+ run: |
+ git checkout master
+ git config --local user.name 'belomaxorka'
+ git config --local user.email 'roman25052006.kelesh@gmail.com'
+ set +e
+ git add CHANGELOG.md
+ git commit -m "changelog: Update CHANGELOG.md 📖"
+ git push https://${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git master
diff --git a/.gitignore b/.gitignore
index d430f2cc7..dd0e1f365 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,30 +1,40 @@
+### IDE ###
+.idea
+.vscode
+
### TorrentPier ###
-.idea/
-data/avatars/**/
-data/old_files/
-data/torrent_files/
-internal_data/ajax_html/*.html
-internal_data/atom/
-internal_data/cache/
-internal_data/captcha/**/
-internal_data/log/
-internal_data/sitemap/*.xml
-internal_data/triggers/
+*.log
+install.php_*
+composer-setup.php
+.env
+.php_cs.cache
+data/avatars
+data/uploads
+internal_data/atom
+internal_data/cache
+internal_data/log
+internal_data/updater.json
+sitemap
+internal_data/triggers
library/config.local.php
+vendor
### Archives ###
-*.log
-*.zip
+*.phar
*.rar
*.tar
*.gz
+*.zip
+*.7z
*.torrent
+*.pak
### Windows ###
Thumbs.db
Desktop.ini
$RECYCLE.BIN/
*.lnk
+*.bat
### OSX ###
.DS_Store
@@ -32,4 +42,6 @@ $RECYCLE.BIN/
.LSOverride
._*
.Spotlight-V100
-.Trashes
\ No newline at end of file
+.Trashes
+*.orig
+*.rej
diff --git a/.htaccess b/.htaccess
index 8298e9bdd..a689fba84 100644
--- a/.htaccess
+++ b/.htaccess
@@ -6,13 +6,13 @@ Options All -Indexes
## sitemap and atom rewrite
RewriteEngine On
-RewriteRule ^sitemap.xml$ internal_data/sitemap/sitemap.xml [L]
+RewriteRule ^sitemap.xml$ sitemap/sitemap.xml [L]
RewriteRule ^/internal_data/atom/(.*) /atom$1 [L]
## deny access to git folder
RedirectMatch 404 /\\.git(/|$)
## deny access to system files
-
-deny from all
-
\ No newline at end of file
+
+Require all denied
+
diff --git a/.styleci.yml b/.styleci.yml
new file mode 100644
index 000000000..64c6be3ca
--- /dev/null
+++ b/.styleci.yml
@@ -0,0 +1,10 @@
+preset: psr2
+
+finder:
+ name:
+ - "*.php"
+ not-name:
+ - "*Stub.php"
+ path:
+ - "src"
+ - "tests"
diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 000000000..deebe3d07
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,113 @@
+[](https://github.com/torrentpier)
+
+# 📖 Change Log
+
+## [v2.8.3](https://github.com/torrentpier/torrentpier/compare/v2.8.2..v2.8.3) (2025-07-03)
+
+### 🚀 Features
+
+- *(lang)* Added `RTL` languages support ([#2031](https://github.com/torrentpier/torrentpier/pull/2031)) - ([fd46d3d](https://github.com/torrentpier/torrentpier/commit/fd46d3d04ad3ab1453256b2ab620508e2ba33586))
+- *(updater)* Added exceptions logging ([#2026](https://github.com/torrentpier/torrentpier/pull/2026)) - ([51f2c70](https://github.com/torrentpier/torrentpier/commit/51f2c70d81b910012cdecd111b5b92c1dfd0d6f6))
+
+### 🚜 Refactor
+
+- *(TorrentFileList)* Reduce duplication in root directory unset logic ([#2027](https://github.com/torrentpier/torrentpier/pull/2027)) - ([d4d8210](https://github.com/torrentpier/torrentpier/commit/d4d82101dd67c9f4cd86e0f6f909495696974354))
+
+
+## [v2.8.2](https://github.com/torrentpier/torrentpier/compare/v2.8.1..v2.8.2) (2025-06-30)
+
+### 🐛 Bug Fixes
+
+- *(TorrentFileList)* Avoid `array_merge` reindexing for numeric folder names ([#2014](https://github.com/torrentpier/torrentpier/pull/2014)) - ([915e1d8](https://github.com/torrentpier/torrentpier/commit/915e1d817c61d2a4f0691b24ec1bc6577a9cd44b))
+
+### 🚜 Refactor
+
+- Use `DEFAULT_CHARSET` constant instead of hardcoded string ([#2011](https://github.com/torrentpier/torrentpier/pull/2011)) - ([7ac3359](https://github.com/torrentpier/torrentpier/commit/7ac335974baa44a8575bebb71ae2fbc0902d10e7))
+
+
+## [v2.8.1](https://github.com/torrentpier/torrentpier/compare/v2.8.0..v2.8.1) (2025-06-24)
+
+### 🐛 Bug Fixes
+
+- *(filelist)* `Undefined property: FileTree::$length` when v2 torrent only ([#2004](https://github.com/torrentpier/torrentpier/pull/2004)) - ([7f4cc9d](https://github.com/torrentpier/torrentpier/commit/7f4cc9d3b9a5b87100f710cc60f636d6e7d5a34e))
+- *(ip-api)* Add error handling and logging for freeipapi.com requests ([#2006](https://github.com/torrentpier/torrentpier/pull/2006)) - ([f1d6e74](https://github.com/torrentpier/torrentpier/commit/f1d6e74e5d4c74b6e12e9e742f60f62e71783d11))
+
+
+## [v2.8.0](https://github.com/torrentpier/torrentpier/compare/v2.7.0..v2.8.0) (2025-06-21)
+
+### 🐛 Bug Fixes
+
+- *(template)* Handle L_ variables in template vars when not found in lang vars ([#1998](https://github.com/torrentpier/torrentpier/pull/1998)) - ([c6076c2](https://github.com/torrentpier/torrentpier/commit/c6076c2c278e9a423f3862670236b75bddeadd87))
+
+
+## [v2.7.0](https://github.com/torrentpier/torrentpier/compare/v2.6.0..v2.7.0) (2025-06-21)
+
+### 🚀 Features
+
+- *(database)* Add visual markers for Nette Explorer queries in debug panel ([#1965](https://github.com/torrentpier/torrentpier/pull/1965)) - ([2fd3067](https://github.com/torrentpier/torrentpier/commit/2fd306704f21febee7d53f4b4531601ce0cb81ce))
+- *(language)* Add new language variable for migration file and enhance template fallback logic ([#1984](https://github.com/torrentpier/torrentpier/pull/1984)) - ([a33574c](https://github.com/torrentpier/torrentpier/commit/a33574c28f2eb6267a74fa6c9d97fea86527157a))
+- *(migrations)* Implement Phinx database migration system ([#1976](https://github.com/torrentpier/torrentpier/pull/1976)) - ([fbde8cd](https://github.com/torrentpier/torrentpier/commit/fbde8cd421c9048afe70ddb41d0a9ed26d3fbef5))
+- *(test)* [**breaking**] Add comprehensive testing infrastructure with Pest PHP ([#1979](https://github.com/torrentpier/torrentpier/pull/1979)) - ([cc9d412](https://github.com/torrentpier/torrentpier/commit/cc9d412522938a023bd2b8eb880c4d2dd307c82a))
+- [**breaking**] Implement Language singleton with shorthand functions ([#1966](https://github.com/torrentpier/torrentpier/pull/1966)) - ([49717d3](https://github.com/torrentpier/torrentpier/commit/49717d3a687b95885fe9773f2597354aed4b2b60))
+
+### 🐛 Bug Fixes
+
+- *(database)* Update affected rows tracking in Database class ([#1980](https://github.com/torrentpier/torrentpier/pull/1980)) - ([4f9cc9f](https://github.com/torrentpier/torrentpier/commit/4f9cc9fe0f7f4a85c90001a3f5514efdf04836da))
+
+### 🚜 Refactor
+
+- *(database)* Enhance error logging and various fixes ([#1978](https://github.com/torrentpier/torrentpier/pull/1978)) - ([7aed6bc](https://github.com/torrentpier/torrentpier/commit/7aed6bc7d89f4ed31e7ed6c6eeecc6e08d348c24))
+- *(database)* Rename DB to Database and extract debug functionality ([#1964](https://github.com/torrentpier/torrentpier/pull/1964)) - ([6c0219d](https://github.com/torrentpier/torrentpier/commit/6c0219d53c7544b7d8a6374c0d0848945d32ae17))
+- *(stats)* Improve database row fetching in tr_stats.php ([#1985](https://github.com/torrentpier/torrentpier/pull/1985)) - ([728116d](https://github.com/torrentpier/torrentpier/commit/728116d6dc9cf4476cce572ced5e8a7ef529ead8))
+
+### ⚙️ Miscellaneous
+
+- Update minimum `PHP` requirement to `8.2` ([#1987](https://github.com/torrentpier/torrentpier/pull/1987)) - ([9b322c7](https://github.com/torrentpier/torrentpier/commit/9b322c7093a634669e9f17a32ac42500f44f2496))
+- Removed useless `composer update` from workflows & installer ([#1986](https://github.com/torrentpier/torrentpier/pull/1986)) - ([423424e](https://github.com/torrentpier/torrentpier/commit/423424e9478e0772957014fb30f5e84158067af7))
+- Added --no-dev composer flag for some workflows ([#1982](https://github.com/torrentpier/torrentpier/pull/1982)) - ([e9a9e09](https://github.com/torrentpier/torrentpier/commit/e9a9e095768ba68aa5d5058a3e152ffaec916117))
+- Added `--no-dev` composer flag for some workflows ([#1981](https://github.com/torrentpier/torrentpier/pull/1981)) - ([e8cba5d](https://github.com/torrentpier/torrentpier/commit/e8cba5dd3fc83b616f83c24991f79dc7258c5df3))
+
+
+## [v2.6.0](https://github.com/torrentpier/torrentpier/compare/v2.5.0..v2.6.0) (2025-06-18)
+
+### 🚀 Features
+
+- [**breaking**] Implement unified cache system with Nette Caching ([#1963](https://github.com/torrentpier/torrentpier/pull/1963)) - ([07a06a3](https://github.com/torrentpier/torrentpier/commit/07a06a33cd97b37f68b533a87cdb5f7578f2c86f))
+- Replace legacy database layer with Nette Database implementation ([#1961](https://github.com/torrentpier/torrentpier/pull/1961)) - ([f50b914](https://github.com/torrentpier/torrentpier/commit/f50b914cc18f777d92002baf2c812a635d5eed4b))
+
+### 🐛 Bug Fixes
+
+- *(User)* Add null and array checks before session data operations ([#1962](https://github.com/torrentpier/torrentpier/pull/1962)) - ([e458109](https://github.com/torrentpier/torrentpier/commit/e458109eefc54d86a78a1ddb3954581524852516))
+
+
+## [v2.5.0](https://github.com/torrentpier/torrentpier/compare/v2.4.6-alpha.4..v2.5.0) (2025-06-18)
+
+### 🚀 Features
+
+- [**breaking**] Implement centralized Config class to replace global $bb_cfg array ([#1953](https://github.com/torrentpier/torrentpier/pull/1953)) - ([bf9100f](https://github.com/torrentpier/torrentpier/commit/bf9100fbfa74768edb01c62636198a44739d9923))
+
+### 🐛 Bug Fixes
+
+- *(installer)* Strip protocol from TP_HOST to keep only hostname ([#1952](https://github.com/torrentpier/torrentpier/pull/1952)) - ([81bf67c](https://github.com/torrentpier/torrentpier/commit/81bf67c2be85d49e988b7802ca7e9738ff580031))
+- *(sql)* Resolve only_full_group_by compatibility issues in tracker cleanup ([#1951](https://github.com/torrentpier/torrentpier/pull/1951)) - ([37a0675](https://github.com/torrentpier/torrentpier/commit/37a0675adfb02014e7068f4aa82301e29f39eab6))
+
+### 📦 Dependencies
+
+- *(deps)* Bump filp/whoops from 2.18.2 to 2.18.3 ([#1948](https://github.com/torrentpier/torrentpier/pull/1948)) - ([b477680](https://github.com/torrentpier/torrentpier/commit/b4776804a408217229caa327c79849cf13ce2aa5))
+
+### 🚜 Refactor
+
+- *(censor)* [**breaking**] Migrate Censor class to singleton pattern ([#1954](https://github.com/torrentpier/torrentpier/pull/1954)) - ([74a564d](https://github.com/torrentpier/torrentpier/commit/74a564d7954c6f8745ebcffdcd9c8997e371d47a))
+- *(config)* [**breaking**] Encapsulate global $bb_cfg array in Config class ([#1950](https://github.com/torrentpier/torrentpier/pull/1950)) - ([5842994](https://github.com/torrentpier/torrentpier/commit/5842994782dfa62788f8427c55045abdbfb5b8e9))
+
+### 📚 Documentation
+
+- Add Select class migration guide ([#1960](https://github.com/torrentpier/torrentpier/pull/1960)) - ([86abafb](https://github.com/torrentpier/torrentpier/commit/86abafb11469d14a746d12725b15cf6b7015ec44))
+
+### ⚙️ Miscellaneous
+
+- *(_release.php)* Finally! Removed some useless params ([#1947](https://github.com/torrentpier/torrentpier/pull/1947)) - ([9c7d270](https://github.com/torrentpier/torrentpier/commit/9c7d270598c0153fb82f4b7ad96f5b59399b2159))
+- *(cliff)* Add conventional commit prefix to changelog message ([#1957](https://github.com/torrentpier/torrentpier/pull/1957)) - ([b1b2618](https://github.com/torrentpier/torrentpier/commit/b1b26187579f6981165d85c316a3c5b7199ce2ee))
+
+
+
diff --git a/CLAUDE.md b/CLAUDE.md
new file mode 100644
index 000000000..68bd96ae8
--- /dev/null
+++ b/CLAUDE.md
@@ -0,0 +1,144 @@
+# CLAUDE.md
+
+This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
+
+## Project Overview
+
+TorrentPier is a BitTorrent tracker engine written in PHP, designed for hosting BitTorrent communities with forum functionality. The project is in active modernization, transitioning from legacy code to modern PHP practices while maintaining backward compatibility.
+
+## Technology Stack & Architecture
+
+- **PHP 8.2+** with modern features
+- **MySQL/MariaDB/Percona** database
+- **Nette Database** with backward-compatible wrapper
+- **Composer** for dependency management
+- **Custom BitTorrent tracker** implementation
+
+## Key Directory Structure
+
+- `/src/` - Modern PHP classes (PSR-4 autoloaded as `TorrentPier\`)
+- `/library/` - Core application logic and legacy code
+- `/admin/` - Administrative interface
+- `/bt/` - BitTorrent tracker functionality (announce.php, scrape.php)
+- `/styles/` - Templates, CSS, JS, images
+- `/internal_data/` - Cache, logs, compiled templates
+- `/install/` - Installation scripts and configuration examples
+- `/migrations/` - Database migration files (Phinx)
+
+## Entry Points & Key Files
+
+- `index.php` - Main forum homepage
+- `tracker.php` - Torrent search/browse interface
+- `bt/announce.php` - BitTorrent announce endpoint
+- `bt/scrape.php` - BitTorrent scrape endpoint
+- `admin/index.php` - Administrative panel
+- `cron.php` - Background task runner (CLI only)
+- `install.php` - Installation script (CLI only)
+
+## Development Commands
+
+### Installation & Setup
+```bash
+# Automated installation (CLI)
+php install.php
+
+# Install dependencies
+composer install
+
+# Update dependencies
+composer update
+```
+
+### Maintenance & Operations
+```bash
+# Run background maintenance tasks
+php cron.php
+```
+
+### Code Quality
+The project uses **StyleCI** with PSR-2 preset for code style enforcement. StyleCI configuration is in `.styleci.yml` targeting `src/` directory.
+
+## Modern Architecture Components
+
+### Database Layer (`/src/Database/`)
+- **Nette Database** with full old SqlDb backward compatibility
+- Singleton pattern accessible via `DB()` function
+- Support for multiple database connections and debug functionality
+- Migration path to ORM-style Explorer queries
+
+### Cache System (`/src/Cache/`)
+- **Unified caching** using Nette Caching internally
+- 100% backward compatibility with existing `CACHE()` and $datastore calls
+- Supports file, SQLite, memory, and Memcached storage
+- Advanced features: memoization, cache dependencies
+
+### Configuration Management
+- Environment-based config with `.env` files
+- Singleton `Config` class accessible via `config()` function
+- Local overrides supported via `library/config.local.php`
+
+## Configuration Files
+- `.env` - Environment variables (copy from `.env.example`)
+- `library/config.php` - Main application configuration
+- `library/config.local.php` - Local configuration overrides
+- `composer.json` - Dependencies and PSR-4 autoloading
+
+## Development Workflow
+
+### CI/CD Pipeline
+- **GitHub Actions** for automated testing and deployment
+- **StyleCI** for code style enforcement
+- **Dependabot** for dependency updates
+- **FTP deployment** to demo environment
+
+### Installation Methods
+1. **Automated**: `php install.php` (recommended)
+2. **Composer**: `composer create-project torrentpier/torrentpier`
+3. **Manual**: Git clone + `composer install` + database setup
+
+## Database & Schema
+
+- **Database migrations** managed via Phinx in `/migrations/` directory
+- Initial schema: `20250619000001_initial_schema.php`
+- Initial seed data: `20250619000002_seed_initial_data.php`
+- UTF-8 (utf8mb4) character set required
+- Multiple database alias support for different components
+
+### Migration Commands
+```bash
+# Run all pending migrations
+php vendor/bin/phinx migrate --configuration=phinx.php
+
+# Check migration status
+php vendor/bin/phinx status --configuration=phinx.php
+
+# Mark migrations as applied (for existing installations)
+php vendor/bin/phinx migrate --fake --configuration=phinx.php
+```
+
+## Legacy Compatibility Strategy
+
+The codebase maintains 100% backward compatibility while introducing modern alternatives:
+
+- **Database layer**: Existing old SqlDb calls work while new code can use Nette Database
+- **Cache system**: All existing `CACHE()` and $datastore calls preserved while adding modern features
+- **Configuration**: Legacy config access maintained alongside new singleton pattern
+
+This approach allows gradual modernization without breaking existing functionality - critical for a mature application with existing deployments.
+
+## Security & Performance
+
+- **Environment-based secrets** management via `.env`
+- **CDN/proxy support** (Cloudflare, Fastly)
+- **Input sanitization** and CSRF protection
+- **Advanced caching** with multiple storage backends
+- **Rate limiting** and IP-based restrictions
+
+## BitTorrent Tracker Features
+
+- **BitTorrent v1 & v2** support
+- **TorrServer integration** capability
+- **Client ban system** for problematic torrent clients
+- **Scrape support** for tracker statistics
+
+When working with this codebase, prioritize understanding the legacy compatibility approach and modern architecture patterns. Always test both legacy and modern code paths when making changes to core systems.
diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md
new file mode 100644
index 000000000..522445d96
--- /dev/null
+++ b/CODE_OF_CONDUCT.md
@@ -0,0 +1,46 @@
+# Contributor Covenant Code of Conduct
+
+## Our Pledge
+
+In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
+
+## Our Standards
+
+Examples of behavior that contributes to creating a positive environment include:
+
+* Using welcoming and inclusive language
+* Being respectful of differing viewpoints and experiences
+* Gracefully accepting constructive criticism
+* Focusing on what is best for the community
+* Showing empathy towards other community members
+
+Examples of unacceptable behavior by participants include:
+
+* The use of sexualized language or imagery and unwelcome sexual attention or advances
+* Trolling, insulting/derogatory comments, and personal or political attacks
+* Public or private harassment
+* Publishing others' private information, such as a physical or electronic address, without explicit permission
+* Other conduct which could reasonably be considered inappropriate in a professional setting
+
+## Our Responsibilities
+
+Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
+
+Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
+
+## Scope
+
+This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
+
+## Enforcement
+
+Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at admin@torrentpier.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
+
+Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
+
+## Attribution
+
+This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
+
+[homepage]: http://contributor-covenant.org
+[version]: http://contributor-covenant.org/version/1/4/
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 000000000..864d4b1d3
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,93 @@
+# Contributing
+
+When contributing to this repository, please first discuss the change you wish to make via issue,
+email, or any other method with the owners of this repository before making a change.
+
+Please note we have a code of conduct, please follow it in all your interactions with the project.
+
+## Pull Request Process
+
+1. Ensure any install or build dependencies are removed before the end of the layer when doing a
+ build.
+2. Update the README.md with details of changes to the interface, this includes new environment
+ variables, exposed ports, useful file locations and container parameters.
+3. Increase the version numbers in any examples files and the README.md to the new version that this
+ Pull Request would represent. The versioning scheme we use is [SemVer](http://semver.org/).
+4. You may merge the Pull Request in once you have the sign-off of two other developers, or if you
+ do not have permission to do that, you may request the second reviewer to merge it for you.
+
+## Code of Conduct
+
+### Our Pledge
+
+In the interest of fostering an open and welcoming environment, we as
+contributors and maintainers pledge to making participation in our project and
+our community a harassment-free experience for everyone, regardless of age, body
+size, disability, ethnicity, gender identity and expression, level of experience,
+nationality, personal appearance, race, religion, or sexual identity and
+orientation.
+
+### Our Standards
+
+Examples of behavior that contributes to creating a positive environment
+include:
+
+* Using welcoming and inclusive language
+* Being respectful of differing viewpoints and experiences
+* Gracefully accepting constructive criticism
+* Focusing on what is best for the community
+* Showing empathy towards other community members
+
+Examples of unacceptable behavior by participants include:
+
+* The use of sexualized language or imagery and unwelcome sexual attention or
+ advances
+* Trolling, insulting/derogatory comments, and personal or political attacks
+* Public or private harassment
+* Publishing others' private information, such as a physical or electronic
+ address, without explicit permission
+* Other conduct which could reasonably be considered inappropriate in a
+ professional setting
+
+### Our Responsibilities
+
+Project maintainers are responsible for clarifying the standards of acceptable
+behavior and are expected to take appropriate and fair corrective action in
+response to any instances of unacceptable behavior.
+
+Project maintainers have the right and responsibility to remove, edit, or
+reject comments, commits, code, wiki edits, issues, and other contributions
+that are not aligned to this Code of Conduct, or to ban temporarily or
+permanently any contributor for other behaviors that they deem inappropriate,
+threatening, offensive, or harmful.
+
+### Scope
+
+This Code of Conduct applies both within project spaces and in public spaces
+when an individual is representing the project or its community. Examples of
+representing a project or community include using an official project e-mail
+address, posting via an official social media account, or acting as an appointed
+representative at an online or offline event. Representation of a project may be
+further defined and clarified by project maintainers.
+
+### Enforcement
+
+Instances of abusive, harassing, or otherwise unacceptable behavior may be
+reported by contacting the project team at admin@torrentpier.com. All
+complaints will be reviewed and investigated and will result in a response that
+is deemed necessary and appropriate to the circumstances. The project team is
+obligated to maintain confidentiality with regard to the reporter of an incident.
+Further details of specific enforcement policies may be posted separately.
+
+Project maintainers who do not follow or enforce the Code of Conduct in good
+faith may face temporary or permanent repercussions as determined by other
+members of the project's leadership.
+
+### Attribution
+
+This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
+available at [http://contributor-covenant.org/version/1/4][version]
+
+[homepage]: http://contributor-covenant.org
+
+[version]: http://contributor-covenant.org/version/1/4/
diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md
deleted file mode 100644
index 7c8c5d101..000000000
--- a/CONTRIBUTORS.md
+++ /dev/null
@@ -1,48 +0,0 @@
-Уважаемые пользователи TorrentPier II!
-
-За помощь, оказанную в развитии нашего движка, выражаем особую благодарность нижеперечисленным участникам форума:
-
-***************************
-** Сборы 2013 года **
-***************************
-
-emilio13
-UralSOFT
-aik
-Sarymian
-eve
-Алексей Письменский
-qaqra
-rserg99
-leszav
-Dr_Brown
-Bullit
-Triceratop (http://goldenshara.com/)
-Ramzess
-
-****************************
-** Сборы 2014 года **
-****************************
-
-SamSeGo
-alesel (http://sporttracker.kz/)
-Bullit
-igorsaevets
-vasilich619
-wint1000 (http://asmlocator.ru/)
-Philstone (http://worldofminecraft.su/)
-Nightwolf
-nord51
-Вася
-Alexander.S (http://torrent.dchub.ws/)
-sasha20072007
-gerhanovn
-
-*****************************
-** Прочая информация **
-*****************************
-
-Отдельная благодарность выражается компании JetBrains за предоставление лицензии на PhpStorm (http://www.jetbrains.com/phpstorm/).
-
-Если в данных списках кто-то не указан, либо если вы хотите указать дополнительно адрес своего трекера, отправьте письмо по адресу admin@torrentpier.me,
-с указанием вашего ника на форуме и адреса вашего трекера, дабы мы могли вас добавить в этот список.
\ No newline at end of file
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 000000000..494696b2b
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2005-2025 TorrentPier
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/README.md b/README.md
index af7f6a07f..96b27a825 100644
--- a/README.md
+++ b/README.md
@@ -1,78 +1,191 @@
-TorrentPier II
-======================
+
-TorrentPier II - движок торрент-трекера, написанный на php. Высокая скорость работы, простота модификации, устойчивость к высоким нагрузкам, в том числе и поддержка альтернативных анонсеров (например, Ocelot). Помимо этого, крайне развитый официальный форум поддержки, где помимо прочего можно испытать движок в работе на демо-версии, не устанавливая его, а также получить любую другую интересующую вас информацию и скачать моды.
+
+ Bull-powered BitTorrent tracker engine
+
+
-## Установка
+
+
+
+
+
+
+
+
+
+
+
-Для установки вам необходимо выполнить несколько простых шагов:
+## 🐂 About TorrentPier
-1. Распаковываем на сервер содержимое скачанной вами папки
+TorrentPier — bull-powered BitTorrent Public/Private tracker engine, written in PHP. High speed, simple modifications, load-balanced
+architecture. In addition, we have a very helpful
+[official support forum](https://torrentpier.com), where it's possible to get support and download modifications for the engine.
-2. Создаем базу данных, в которую при помощи phpmyadmin (или любого другого удобного инструмента) импортируем дамп, расположенный в папке **install/sql/mysql.sql**
-3. Правим файл конфигурации **library/config.php**, загруженный на сервер:
-> ***'db1' => array('localhost', 'dbase', 'user', 'pass', $charset, $pconnect)***
-В данной строке изменяем данные входа в базу данных
-***$domain_name = 'torrentpier.me';***
-В данной строке указываем ваше доменное имя. Остальные правки в файле вносятся по усмотрению, исходя из необходимости из внесения (ориентируйтесь на описания, указанные у полей).
+## 🌈 Current status
-4. Редактируем указанные файлы:
- + **favicon.ico** (меняем на свою иконку, если есть)
- + **robots.txt** (меняем адреса в строках **Host** и **Sitemap** на свои)
- + **opensearch_desc.xml** (меняем описание и адрес на свои)
- + **opensearch_desc_bt.xml** (меняем описание и адрес на свои)
+TorrentPier is currently in active development. The goal is to remove all legacy code and rewrite the existing code to
+modern specifications. If you want to delve deep into the code, check our [issues](https://github.com/torrentpier/torrentpier/issues)
+and go from there. The documentation will be translated to English in the near future, currently Russian is the main language.
-## Права доступа на папки и файлы
+## ✨ Features
+* Rich forum with browsing/moderation tools
+* High-load capable, heavily configurable announcer
+* Scrape support
+* FreeLeech
+* [TorrServer integration](https://github.com/YouROK/TorrServer) support
+* BitTorrent v2 support
+* Event-based invite system
+* Bonus points
+* Polling system
+* PM/DM system
+* Multilingual support (Russian and English are currently fully supported, with others in the future)
+* Atom/RSS feeds
+* ... and so MUCH MORE!
-Исходя из настроек вашего сервера, устанавливаем рекомендуемые права доступа (chmod) на указанные папки **777**, а на файлы внутри этих папок (кроме файлов **.htaccess** и **.keep**) **666**:
-- data/avatars
-- data/old_files
-- data/torrent_files
-- internal_data/ajax_html
-- internal_data/atom
-- internal_data/cache
-- internal_data/captcha
-- internal_data/log
-- internal_data/sitemap
-- internal_data/triggers
+## 🖥️ Demo
-## Необходимая версия php
+* URL: https://torrentpier.duckdns.org
+* Username: `admin`
+* Password: `admin`
-Минимально поддерживаемой версией в настоящий момент является 5.3. Существует поддержка вплоть до версии 5.5 (в данной версии в логах будет уведомление об использовании устаревших функций). Версия php 5.6 в настоящее время движком не поддерживается и его работа на ней не гарантируется. Мы делаем все возможное чтобы в самое ближайшее время добавить его поддержку.
+> [!NOTE]
+> Demo resets every 24 hours!
-## Необходимые настройки php
+## 🔧 Requirements
- mbstring.internal_encoding = UTF-8
- magic_quotes_gpc = Off
-Внести данные настройки необходимо в файл **php.ini**. Их вам может установить ваш хостер по запросу, если у вас возникают какие-либо проблемы с их самостоятельной установкой. Впрочем, эти настройки могут быть установлены на сервере по-умолчанию, поэтому их внесение требуется исключительно по необходимости.
+* Apache / nginx ([example config](install/nginx.conf)) / caddy ([example config](install/Caddyfile))
+* MySQL 5.5.3 or above (including MySQL 8.0+) / MariaDB 10.0 or above / Percona
+* PHP: 8.2 / 8.3 / 8.4
+* PHP Extensions: mbstring, gd, bcmath, intl, tidy (optional), xml, xmlwriter
+* Crontab (Recommended)
-## Необходимые модули php
+## 💾 Installation
- php5-tidy
-Начиная с версии 2.0.9 (ревизия 592 в старой нумерации) данный модуль не является обязательным, но его установка крайне рекомендуется для повышения качества обработки html-кода тем и сообщений пользователей.
+For the installation, select one of the installation variants below:
-## Рекомендуемый способ запуска cron.php
+### Quick (Clean install) 🚀
-Для значительного ускорения работы трекера может потребоваться отвязка встроенного форумного крона. С более подробной информацией об отвязке крона, вы можете ознакомиться в данной теме https://torrentpier.me/threads/52/ на нашем форуме поддержки.
+Check out our [autoinstall](https://github.com/torrentpier/autoinstall) repository with detailed instructions.
-## Локальный файл конфигурации
+> [!NOTE]
+> Thanks to [Sergei Solovev](https://github.com/SeAnSolovev) for this installation script ❤️
-Начиная с ревизии 599 была добавлена поддерка автоматического подключения файла config.local.php, при создании его вами. В данном файле вы можете переопределять настройки файла config.php для конкретного сервера, на котором запущен трекер или в целом менять стандартные значения файла config.php, для более простого обновления файлов движка в дальнейшем.
+### Quick (For web-panels) ☕️
-## Установка Ocelot
+1. Select the folder where you want TorrentPier installed
+ ```shell
+ cd /path/to/public_html
+ ```
+2. Download the latest version of TorrentPier
+ ```shell
+ sudo git clone https://github.com/torrentpier/torrentpier.git .
+ ```
+3. After completing, execute the command below and follow the instructions
+ ```shell
+ php install.php
+ ```
+4. Voila! ✨
-В движок встроена по-умолчанию поддержка альтернативного компилируемого анонсера - Ocelot. Настройка производится в файле **library/config.php**, сам анонсер находится в репозитории https://github.com/torrentpier/ocelot
+### Manual 🔩
-Инструкция по сборке приведена на нашем форуме: https://torrentpier.me/threads/sborka-ocelot-pod-debian-7-1.26078/
-Для работы анонсера требуется замена двух таблиц в базе данных - дамп в файле: **install/sql/ocelot.sql**
+1. Install [Composer](https://getcomposer.org/)
+2. Run the following command to create the TorrentPier project
+ ```shell
+ composer create-project torrentpier/torrentpier
+ ```
+3. [Check our system requirements](#-requirements)
+4. After, run this command in the project directory to install Composer dependencies
+ ```shell
+ composer install
+ ```
+5. Edit database configuration settings in the environment (`.env.example`), after, rename to `.env`
+6. Create a database and run migrations to set up the schema
+ ```shell
+ php vendor/bin/phinx migrate --configuration=phinx.php
+ ```
+7. Provide write permissions to the specified folders:
+ * `data/avatars`, `data/uploads`, `data/uploads/thumbs`
+ * `internal_data/atom`, `internal_data/cache`, `internal_data/log`, `internal_data/triggers`
+ * `sitemap`
+8. Voila! ✨
-## Папка install
+> [!TIP]
+> You can automate steps 4-7 by running `php install.php` instead, which will guide you through the setup process interactively.
-В корне движка присутствует папка **install**, в которой находятся служебные файлы, необходимые для его установки (дамп базы, примеры конфигов) и обновления (дамперы, скрипты конвертации). Доступ к данной папке по-умолчанию закрыт, но если ее присутствие вам мешает - вы можете ее удалить. На файлы **README.md** и **CONTRIBUTORS.md** это также распространяется.
+> [!IMPORTANT]
+> The specific settings depend on the server you are using, but in general we recommend chmod **0755** for folders, and chmod **0644** for the files in them.
-## Полезные ссылки
+### Additional steps 👣
-+ Наш форум https://torrentpier.me/
-+ Центр загрузки https://get.torrentpier.me/
-+ Часто задаваемые вопросы https://faq.torrentpier.me/
-+ Где задать вопрос https://torrentpier.me/forums/10/
+1. Edit these files:
+ * `favicon.png` (change to your own)
+ * `robots.txt` (change the addresses in lines `Host` and `Sitemap` to your own)
+2. Log in to the forum using the **admin/admin** login/password, and finish setting up via admin panel. Don't forget to change your password!
+
+## 🔐 Security vulnerabilities
+
+If you discover a security vulnerability within TorrentPier, please follow our [security policy](https://github.com/torrentpier/torrentpier/security/policy), so we can address it promptly.
+
+## 🧪 Testing
+
+TorrentPier includes a comprehensive testing suite built with **Pest PHP**. Run tests to ensure code quality and system reliability:
+
+```shell
+# Run all tests
+./vendor/bin/pest
+
+# Run with coverage
+./vendor/bin/pest --coverage
+```
+
+For detailed testing documentation, see [tests/README.md](tests/README.md).
+
+## 📌 Our recommendations
+
+* *It's recommended to run `cron.php`.* - For significant tracker speed increase it may be required to replace the built-in cron.php with an operating system daemon.
+* *Local configuration copy.* - You can override the settings using the local configuration file `library/config.local.php`.
+
+## 💚 Contributing / Contributors
+
+Please read our [contributing policy](CONTRIBUTING.md) and [code of conduct](CODE_OF_CONDUCT.md) for details, and the process for
+submitting pull requests to us. But we are always ready to review your pull-request for compliance with
+these requirements. Just send it!
+
+
+
+
+
+Made with [contrib.rocks](https://contrib.rocks).
+
+## 💞 Sponsoring
+
+Support this project by becoming a sponsor or a backer.
+
+[](https://opencollective.com/torrentpier)
+[](https://opencollective.com/torrentpier)
+
+
+ Monero
+
+```
+42zJE3FDvN8foP9QYgDrBjgtd7h2FipGCGmAcmG5VFQuRkJBGMbCvoLSmivepmAMEgik2E8MPWUzKaoYsGCtmhvL7ZN73jh
+```
+
+
+
+ YooMoney
+
+```
+4100118022415720
+```
+
+
+## 📦 Versioning
+
+We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/torrentpier/torrentpier/tags).
+
+## 📖 License
+
+This project is licensed under the MIT License - see the [LICENSE](https://github.com/torrentpier/torrentpier/blob/master/LICENSE) file for details.
diff --git a/SECURITY.md b/SECURITY.md
new file mode 100644
index 000000000..73d867596
--- /dev/null
+++ b/SECURITY.md
@@ -0,0 +1,13 @@
+# Security Policy
+
+## Versions
+
+Due to the nature of our project - being open source - we have decided to patch only the latest major release (currently v2.4.x) for security vulnerabilities.
+
+## How to disclose
+
+Please disclose security issues by mailing [admin@torrentpier.com](mailto:admin@torrentpier.com).
+
+## What we do
+
+Any submitted security issue will be checked thoroughly by our development team. A fix for the issue and a transparent information on GitHub about the issue existing will be released. You can view any previously identified issues on our [GitHub Security Page](https://github.com/torrentpier/torrentpier/security/advisories). New major versions of TorrentPier will also receive a security audit to verify our efforts on providing a secure application.
diff --git a/UPGRADE_GUIDE.md b/UPGRADE_GUIDE.md
new file mode 100644
index 000000000..2305e8bba
--- /dev/null
+++ b/UPGRADE_GUIDE.md
@@ -0,0 +1,1261 @@
+# 🚀 TorrentPier Upgrade Guide
+
+This guide helps you upgrade your TorrentPier installation to the latest version, covering breaking changes, new features, and migration strategies.
+
+## 📖 Table of Contents
+
+- [Database Migration System](#database-migration-system)
+- [Database Layer Migration](#database-layer-migration)
+- [Unified Cache System Migration](#unified-cache-system-migration)
+- [Configuration System Migration](#configuration-system-migration)
+- [Language System Migration](#language-system-migration)
+- [Censor System Migration](#censor-system-migration)
+- [Select System Migration](#select-system-migration)
+- [Development System Migration](#development-system-migration)
+- [Breaking Changes](#breaking-changes)
+- [Best Practices](#best-practices)
+
+## 🗄️ Database Migration System
+
+TorrentPier now includes a modern database migration system using **Phinx** (from CakePHP), replacing the legacy direct SQL import approach. This provides version-controlled database schema management with rollback capabilities.
+
+### Key Benefits
+
+- **Version Control**: Database schema changes are tracked in code
+- **Environment Consistency**: Same database structure across development, staging, and production
+- **Safe Rollbacks**: Ability to safely revert schema changes
+- **Team Collaboration**: No more merge conflicts on database changes
+- **Automated Deployments**: Database updates as part of deployment process
+
+### Migration Architecture
+
+#### Engine Strategy
+- **InnoDB**: Used for all tables for maximum data integrity and reliability
+- **ACID Compliance**: Full transaction support and crash recovery for all data
+- **Row-Level Locking**: Better concurrency for high-traffic operations
+
+#### Directory Structure
+```
+/migrations/
+ ├── 20250619000001_initial_schema.php # Complete database schema
+ ├── 20250619000002_seed_initial_data.php # Essential data seeding
+ └── future_migrations... # Your custom migrations
+/phinx.php # Migration configuration
+```
+
+### For New Installations
+
+New installations automatically use migrations instead of the legacy SQL dump:
+
+```bash
+# Fresh installation now uses migrations
+php install.php
+```
+
+The installer will:
+1. Set up environment configuration
+2. Create the database
+3. Run all migrations automatically
+4. Seed initial data (admin user, configuration, etc.)
+
+### For Existing Installations
+
+Existing installations continue to work without changes. The migration system is designed for new installations and development workflows.
+
+**Important**: Existing installations should **not** attempt to migrate to the new system without proper backup and testing procedures.
+
+### Developer Workflow
+
+#### Creating Migrations
+```bash
+# Create a new migration
+php vendor/bin/phinx create AddNewFeatureTable
+
+# Edit the generated migration file
+# /migrations/YYYYMMDDHHMMSS_add_new_feature_table.php
+```
+
+#### Running Migrations
+```bash
+# Run all pending migrations
+php vendor/bin/phinx migrate
+
+# Check migration status
+php vendor/bin/phinx status
+
+# Rollback last migration
+php vendor/bin/phinx rollback
+```
+
+#### Migration Template
+```php
+table('bb_new_feature', [
+ 'engine' => 'InnoDB',
+ 'collation' => 'utf8mb4_unicode_ci'
+ ]);
+
+ $table->addColumn('name', 'string', ['limit' => 100])
+ ->addColumn('created_at', 'timestamp', ['default' => 'CURRENT_TIMESTAMP'])
+ ->addIndex('name')
+ ->create();
+ }
+
+ // Optional: explicit up/down methods for complex operations
+ public function up()
+ {
+ // Complex data migration logic
+ }
+
+ public function down()
+ {
+ // Rollback logic
+ }
+}
+```
+
+#### Engine Guidelines
+```php
+// Use InnoDB for all tables for maximum reliability
+$table = $this->table('bb_user_posts', [
+ 'engine' => 'InnoDB',
+ 'collation' => 'utf8mb4_unicode_ci'
+]);
+
+// All tracker tables also use InnoDB for data integrity
+$table = $this->table('bb_bt_peer_stats', [
+ 'engine' => 'InnoDB',
+ 'collation' => 'utf8mb4_unicode_ci'
+]);
+
+// Buffer tables use InnoDB for consistency and reliability
+public function up() {
+ $this->execute('DROP TABLE IF EXISTS buf_temp_data');
+ // Recreate with new structure using InnoDB
+}
+```
+
+### Admin Panel Integration
+
+The admin panel includes a read-only migration status page at `/admin/admin_migrations.php`:
+
+- **Current migration version**
+- **Applied migrations history**
+- **Pending migrations list**
+- **Database statistics**
+- **Clear instructions for CLI operations**
+
+**Important**: The admin panel is **read-only** for security. All migration operations must be performed via CLI.
+
+### Complex Migration Handling
+
+For complex data transformations, create external scripts:
+
+```php
+// migrations/YYYYMMDDHHMMSS_complex_data_migration.php
+class ComplexDataMigration extends AbstractMigration
+{
+ public function up()
+ {
+ $this->output->writeln('Running complex data migration...');
+
+ // Call external script for complex operations
+ $result = shell_exec('php ' . __DIR__ . '/../scripts/migrate_torrent_data.php');
+ $this->output->writeln($result);
+
+ if (strpos($result, 'ERROR') !== false) {
+ throw new Exception('Complex migration failed');
+ }
+ }
+}
+```
+
+### Best Practices
+
+#### Migration Development
+```bash
+# 1. Create migration
+php vendor/bin/phinx create MyFeature
+
+# 2. Edit migration file
+# 3. Test locally
+php vendor/bin/phinx migrate -e development
+
+# 4. Test rollback
+php vendor/bin/phinx rollback -e development
+
+# 5. Commit to version control
+git add migrations/
+git commit -m "Add MyFeature migration"
+```
+
+#### Production Deployment
+```bash
+# Always backup database first
+mysqldump tracker_db > backup_$(date +%Y%m%d_%H%M%S).sql
+
+# Run migrations
+php vendor/bin/phinx migrate -e production
+
+# Verify application functionality
+# Monitor error logs
+```
+
+#### Team Collaboration
+- **Never modify existing migrations** that have been deployed
+- **Always create new migrations** for schema changes
+- **Test migrations on production-like data** before deployment
+- **Coordinate with team** before major schema changes
+
+### Configuration
+
+The migration system uses your existing `.env` configuration:
+
+```php
+// phinx.php automatically reads from .env
+'production' => [
+ 'adapter' => 'mysql',
+ 'host' => env('DB_HOST', 'localhost'),
+ 'port' => (int) env('DB_PORT', 3306),
+ 'name' => env('DB_DATABASE'),
+ 'user' => env('DB_USERNAME'),
+ 'pass' => env('DB_PASSWORD', ''),
+ 'charset' => 'utf8mb4',
+ 'collation' => 'utf8mb4_unicode_ci'
+]
+```
+
+### Troubleshooting
+
+#### Common Issues
+```bash
+# Migration table doesn't exist
+php vendor/bin/phinx init # Re-run if needed
+
+# Migration fails mid-way
+php vendor/bin/phinx rollback # Rollback to previous state
+
+# Check what would be applied
+php vendor/bin/phinx status # See pending migrations
+```
+
+#### Migration Recovery
+```bash
+# If migration fails, check status first
+php vendor/bin/phinx status
+
+# Rollback to known good state
+php vendor/bin/phinx rollback -t 20250619000002
+
+# Fix the migration code and re-run
+php vendor/bin/phinx migrate
+```
+
+### Legacy SQL Import Removal
+
+The legacy `install/sql/mysql.sql` approach has been replaced by migrations:
+
+- ✅ **New installations**: Use migrations automatically
+- ✅ **Development workflow**: Create migrations for all schema changes
+- ✅ **Version control**: All schema changes tracked in Git
+- ❌ **Direct SQL imports**: No longer used for new installations
+
+### Security Considerations
+
+- **CLI-only execution**: Migrations run via command line only
+- **Read-only admin interface**: Web interface shows status only
+- **Backup requirements**: Always backup before production migrations
+- **Access control**: Restrict migration command access to authorized personnel
+
+### Migration Setup for Existing Installations
+
+If you have an **existing TorrentPier installation** and want to adopt the migration system, you need to mark the initial migrations as already applied to avoid recreating your existing database schema.
+
+#### Detection: Do You Need This?
+
+You need migration setup if:
+- ✅ You have an existing TorrentPier installation with data
+- ✅ Your database already has tables like `bb_users`, `bb_forums`, etc.
+- ✅ The admin migration panel shows "Migration System: ✗ Not Initialized"
+
+#### Step-by-Step Setup Process
+
+**1. Backup Your Database**
+```bash
+mysqldump -u username -p database_name > backup_$(date +%Y%m%d_%H%M%S).sql
+```
+
+**2. Initialize Migration Table**
+```bash
+# This creates the bb_migrations table without running any migrations
+php vendor/bin/phinx init
+```
+
+**3. Mark Initial Migrations as Applied (Fake Run)**
+```bash
+# Mark the schema migration as applied without running it
+php vendor/bin/phinx migrate --fake --target=20250619000001
+
+# Mark the data seeding migration as applied without running it
+php vendor/bin/phinx migrate --fake --target=20250619000002
+```
+
+**4. Verify Setup**
+```bash
+# Check migration status
+php vendor/bin/phinx status
+```
+
+You should see both initial migrations marked as "up" (applied).
+
+#### Alternative: Manual SQL Method
+
+If you prefer manual control, you can directly insert migration records:
+
+```sql
+-- Create migration table (if phinx init didn't work)
+CREATE TABLE IF NOT EXISTS bb_migrations (
+ version bigint(20) NOT NULL,
+ migration_name varchar(100) DEFAULT NULL,
+ start_time timestamp NULL DEFAULT NULL,
+ end_time timestamp NULL DEFAULT NULL,
+ breakpoint tinyint(1) NOT NULL DEFAULT '0',
+ PRIMARY KEY (version)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+
+-- Mark initial migrations as applied
+INSERT INTO bb_migrations (version, migration_name, start_time, end_time, breakpoint)
+VALUES
+('20250619000001', 'InitialSchema', NOW(), NOW(), 0),
+('20250619000002', 'SeedInitialData', NOW(), NOW(), 0);
+```
+
+#### Post-Setup Workflow
+
+After setup, your existing installation will work exactly like a fresh installation:
+
+```bash
+# Create new migrations
+php vendor/bin/phinx create AddNewFeature
+
+# Run new migrations
+php vendor/bin/phinx migrate
+
+# Check status
+php vendor/bin/phinx status
+```
+
+#### Troubleshooting
+
+**Migration table already exists:**
+- Check if you've already set up migrations: `php vendor/bin/phinx status`
+- If it shows errors, you may need to recreate: `DROP TABLE bb_migrations;` then restart
+
+**"Nothing to migrate" message:**
+- This is normal after fake runs - it means setup was successful
+- New migrations will appear when you create them
+
+**Admin panel shows "Needs Setup":**
+- Follow the setup process above
+- Refresh the admin panel after completion
+
+## 🗄️ Database Layer Migration
+
+TorrentPier has completely replaced its legacy database layer (SqlDb/Dbs) with a modern implementation using Nette Database while maintaining 100% backward compatibility.
+
+### No Code Changes Required
+
+**Important**: All existing `DB()->method()` calls continue to work exactly as before. This is an internal modernization that requires **zero code changes** in your application.
+
+```php
+// ✅ All existing code continues to work unchanged
+$user = DB()->fetch_row("SELECT * FROM users WHERE id = ?", 123);
+$users = DB()->fetch_rowset("SELECT * FROM users");
+$affected = DB()->affected_rows();
+$result = DB()->sql_query("UPDATE users SET status = ? WHERE id = ?", 1, 123);
+$escaped = DB()->escape($userInput);
+```
+
+### Key Improvements
+
+#### Modern Foundation
+- **Nette Database v3.2**: Modern, actively maintained database layer
+- **PDO-based**: Improved security and performance
+- **Type Safety**: Better error detection and IDE support
+- **Singleton Pattern**: Efficient connection management
+
+#### Enhanced Reliability
+- **Automatic Resource Cleanup**: Better memory management
+- **Improved Error Handling**: More detailed error information
+- **Connection Stability**: Better handling of connection issues
+- **Performance Optimizations**: Reduced overhead and improved query execution
+
+#### Debugging and Development
+- **Enhanced Explain Support**: Improved query analysis
+- **Better Query Logging**: More detailed performance tracking
+- **Debug Information**: Comprehensive debugging features
+- **Memory Tracking**: Better resource usage monitoring
+
+### Multiple Database Support
+
+Multiple database servers continue to work exactly as before:
+
+```php
+// ✅ Multiple database access unchanged
+$main_db = DB('db'); // Main database
+$tracker_db = DB('tr'); // Tracker database
+$stats_db = DB('stats'); // Statistics database
+```
+
+### Error Handling
+
+All error handling patterns remain identical:
+
+```php
+// ✅ Error handling works exactly as before
+$result = DB()->sql_query("SELECT * FROM users");
+if (!$result) {
+ $error = DB()->sql_error();
+ echo "Error: " . $error['message'];
+}
+```
+
+### Debug and Explain Features
+
+All debugging functionality is preserved and enhanced:
+
+```php
+// ✅ Debug features work as before
+DB()->debug('start');
+// ... run queries ...
+DB()->debug('stop');
+
+// ✅ Explain functionality unchanged
+DB()->explain('start');
+DB()->explain('display');
+```
+
+### Performance Benefits
+
+While maintaining compatibility, you get:
+- **Faster Connection Handling**: Singleton pattern prevents connection overhead
+- **Modern Query Execution**: Nette Database optimizations
+- **Better Resource Management**: Automatic cleanup and proper connection handling
+- **Reduced Memory Usage**: More efficient object management
+
+### 📖 Detailed Documentation
+
+For comprehensive information about the database layer changes, implementation details, and technical architecture, see:
+
+**[src/Database/README.md](src/Database/README.md)**
+
+This documentation covers:
+- Complete architecture overview
+- Technical implementation details
+- Migration notes and compatibility information
+- Debugging features and usage examples
+- Performance benefits and benchmarks
+
+### Legacy Code Cleanup
+
+The following legacy files have been removed from the codebase:
+- `src/Legacy/SqlDb.php` - Original database class
+- `src/Legacy/Dbs.php` - Original database factory
+
+These were completely replaced by:
+- `src/Database/Database.php` - Modern database class with Nette Database (renamed from `DB.php`)
+- `src/Database/DatabaseFactory.php` - Modern factory with backward compatibility (renamed from `DbFactory.php`)
+- `src/Database/DatabaseDebugger.php` - Dedicated debug functionality extracted from Database class
+- `src/Database/DebugSelection.php` - Debug-enabled wrapper for Nette Database Selection
+
+### Verification
+
+To verify the migration is working correctly:
+
+```php
+// ✅ Test basic database operations
+$version = DB()->server_version();
+$testQuery = DB()->fetch_row("SELECT 1 as test");
+echo "Database version: $version, Test: " . $testQuery['test'];
+
+// ✅ Test error handling
+$result = DB()->sql_query("SELECT invalid_column FROM non_existent_table");
+if (!$result) {
+ $error = DB()->sql_error();
+ echo "Error handling works: " . $error['message'];
+}
+```
+
+## 💾 Unified Cache System Migration
+
+TorrentPier has replaced its legacy Cache and Datastore systems with a modern unified implementation using Nette Caching while maintaining 100% backward compatibility.
+
+### No Code Changes Required
+
+**Important**: All existing `CACHE()` and `$datastore` calls continue to work exactly as before. This is an internal modernization that requires **zero code changes** in your application.
+
+```php
+// ✅ All existing code continues to work unchanged
+$cache = CACHE('bb_cache');
+$value = $cache->get('key');
+$cache->set('key', $value, 3600);
+
+$datastore = datastore();
+$forums = $datastore->get('cat_forums');
+$datastore->store('custom_data', $data);
+```
+
+### Key Improvements
+
+#### Modern Foundation
+- **Nette Caching v3.3**: Modern, actively maintained caching library
+- **Unified System**: Single caching implementation instead of duplicate Cache/Datastore code
+- **Singleton Pattern**: Efficient memory usage and consistent TorrentPier architecture
+- **Advanced Features**: Dependencies, tags, bulk operations, memoization
+
+#### Enhanced Performance
+- **456,647+ operations per second**: Verified production performance
+- **Memory Optimization**: Shared storage and efficient instance management
+- **Debug Compatibility**: Full compatibility with Dev.php debugging features
+
+### Enhanced Capabilities
+
+New code can leverage advanced Nette Caching features:
+
+```php
+// ✅ Enhanced caching with dependencies
+$cache = CACHE('bb_cache');
+$forums = $cache->load('forums', function() {
+ return build_forums_data();
+}, [
+ \Nette\Caching\Cache::Expire => '1 hour',
+ \Nette\Caching\Cache::Files => ['/path/to/config.php']
+]);
+
+// ✅ Function memoization
+$result = $cache->call('expensive_function', $param);
+```
+
+### 📖 Detailed Documentation
+
+For comprehensive information about the unified cache system, advanced features, and technical architecture, see:
+
+**[src/Cache/README.md](src/Cache/README.md)**
+
+This documentation covers:
+- Complete architecture overview and singleton pattern
+- Advanced Nette Caching features and usage examples
+- Performance benchmarks and storage type comparisons
+- Critical compatibility issues resolved during implementation
+
+### Verification
+
+To verify the migration is working correctly:
+
+```php
+// ✅ Test basic cache operations
+$cache = CACHE('test_cache');
+$cache->set('test_key', 'test_value', 60);
+$value = $cache->get('test_key');
+echo "Cache test: " . ($value === 'test_value' ? 'PASSED' : 'FAILED');
+
+// ✅ Test datastore operations
+$datastore = datastore();
+$datastore->store('test_item', ['status' => 'verified']);
+$item = $datastore->get('test_item');
+echo "Datastore test: " . ($item['status'] === 'verified' ? 'PASSED' : 'FAILED');
+```
+
+## ⚙️ Configuration System Migration
+
+The new TorrentPier features a modern, centralized configuration system with full backward compatibility.
+
+### Quick Migration Overview
+
+```php
+// ❌ Old way (still works, but not recommended)
+global $bb_cfg;
+$announceUrl = $bb_cfg['bt_announce_url'];
+$dbHost = $bb_cfg['database']['host'];
+
+// ✅ New way (recommended)
+$announceUrl = config()->get('bt_announce_url');
+$dbHost = config()->get('database.host');
+```
+
+### Key Configuration Changes
+
+#### Basic Usage
+```php
+// Get configuration values using dot notation
+$siteName = config()->get('sitename');
+$dbHost = config()->get('database.host');
+$cacheTimeout = config()->get('cache.timeout');
+
+// Get with default value if key doesn't exist
+$maxUsers = config()->get('max_users_online', 100);
+$debugMode = config()->get('debug.enabled', false);
+```
+
+#### Setting Values
+```php
+// Set configuration values
+config()->set('sitename', 'My Awesome Tracker');
+config()->set('database.port', 3306);
+config()->set('cache.enabled', true);
+```
+
+#### Working with Sections
+```php
+// Get entire configuration section
+$dbConfig = config()->getSection('database');
+$trackerConfig = config()->getSection('tracker');
+
+// Check if configuration exists
+if (config()->has('bt_announce_url')) {
+ $announceUrl = config()->get('bt_announce_url');
+}
+```
+
+### Common Configuration Mappings
+
+| Old Syntax | New Syntax |
+|------------|------------|
+| `$bb_cfg['sitename']` | `config()->get('sitename')` |
+| `$bb_cfg['database']['host']` | `config()->get('database.host')` |
+| `$bb_cfg['tracker']['enabled']` | `config()->get('tracker.enabled')` |
+| `$bb_cfg['cache']['timeout']` | `config()->get('cache.timeout')` |
+| `$bb_cfg['torr_server']['url']` | `config()->get('torr_server.url')` |
+
+### Magic Methods Support
+```php
+// Magic getter
+$siteName = config()->sitename;
+$dbHost = config()->{'database.host'};
+
+// Magic setter
+config()->sitename = 'New Site Name';
+config()->{'database.port'} = 3306;
+
+// Magic isset
+if (isset(config()->bt_announce_url)) {
+ // Configuration exists
+}
+```
+
+## 🌐 Language System Migration
+
+TorrentPier has modernized its language system with a singleton pattern while maintaining 100% backward compatibility with existing global `$lang` variable.
+
+### No Code Changes Required
+
+**Important**: All existing `global $lang` calls continue to work exactly as before. This is an internal modernization that requires **zero code changes** in your application.
+
+```php
+// ✅ All existing code continues to work unchanged
+global $lang;
+echo $lang['FORUM'];
+echo $lang['DATETIME']['TODAY'];
+```
+
+### Key Improvements
+
+#### Modern Foundation
+- **Singleton Pattern**: Efficient memory usage and consistent TorrentPier architecture
+- **Centralized Management**: Single point of control for language loading and switching
+- **Type Safety**: Better error detection and IDE support
+- **Dot Notation Support**: Access nested language arrays with simple syntax
+
+#### Enhanced Functionality
+- **Automatic Fallback**: Source language fallback for missing translations
+- **Dynamic Loading**: Load additional language files for modules/extensions
+- **Runtime Modification**: Add or modify language strings at runtime
+- **Locale Management**: Automatic locale setting based on language selection
+
+### Enhanced Capabilities
+
+New code can leverage the modern Language singleton features with convenient shorthand functions:
+
+```php
+// ✅ Convenient shorthand functions (recommended for frequent use)
+echo __('FORUM'); // Same as lang()->get('FORUM')
+echo __('DATETIME.TODAY'); // Dot notation for nested arrays
+_e('WELCOME_MESSAGE'); // Echo shorthand
+$message = __('CUSTOM_MESSAGE', 'Default'); // With default value
+
+// ✅ Full singleton access (for advanced features)
+echo lang()->get('FORUM');
+echo lang()->get('DATETIME.TODAY'); // Dot notation for nested arrays
+
+// ✅ Check if language key exists
+if (lang()->has('ADVANCED_FEATURE')) {
+ echo __('ADVANCED_FEATURE');
+}
+
+// ✅ Get current language information
+$currentLang = lang()->getCurrentLanguage();
+$langName = lang()->getLanguageName();
+$langLocale = lang()->getLanguageLocale();
+
+// ✅ Load additional language files for modules
+lang()->loadAdditionalFile('custom_module', 'en');
+
+// ✅ Runtime language modifications
+lang()->set('CUSTOM_KEY', 'Custom Value');
+lang()->set('NESTED.KEY', 'Nested Value');
+```
+
+### Language Management
+
+#### Available Languages
+```php
+// Get all available languages from configuration
+$availableLanguages = lang()->getAvailableLanguages();
+
+// Get language display name
+$englishName = lang()->getLanguageName('en'); // Returns: "English"
+$currentName = lang()->getLanguageName(); // Current language name
+
+// Get language locale for formatting
+$locale = lang()->getLanguageLocale('ru'); // Returns: "ru_RU.UTF-8"
+```
+
+#### Dynamic Language Loading
+```php
+// Load additional language files (useful for modules/plugins)
+$success = lang()->loadAdditionalFile('torrent_management');
+if ($success) {
+ echo lang()->get('TORRENT_UPLOADED');
+}
+
+// Load from specific language
+lang()->loadAdditionalFile('admin_panel', 'de');
+```
+
+#### Runtime Modifications
+```php
+// Set custom language strings
+lang()->set('SITE_WELCOME', 'Welcome to Our Tracker!');
+lang()->set('ERRORS.INVALID_TORRENT', 'Invalid torrent file');
+
+// Modify existing strings
+lang()->set('LOGIN', 'Sign In');
+```
+
+### Backward Compatibility Features
+
+The singleton automatically maintains all global variables:
+
+```php
+// Global variable is automatically updated by the singleton
+global $lang;
+
+// When you call lang()->set(), global is updated
+lang()->set('CUSTOM', 'Value');
+echo $lang['CUSTOM']; // Outputs: "Value"
+
+// When language is initialized, $lang is populated
+// $lang contains user language + source language fallbacks
+```
+
+### Integration with User System
+
+The Language singleton integrates seamlessly with the User system:
+
+```php
+// User language is automatically detected and initialized
+// Based on user preferences, browser detection, or defaults
+
+// In User->init_userprefs(), language is now initialized with:
+lang()->initializeLanguage($userLanguage);
+
+// This replaces the old manual language file loading
+// while maintaining exact same functionality
+```
+
+### Convenient Shorthand Functions
+
+For frequent language access, TorrentPier provides convenient shorthand functions:
+
+```php
+// ✅ __() - Get language string (most common)
+echo __('FORUM'); // Returns: "Forum"
+echo __('DATETIME.TODAY'); // Nested access: "Today"
+$msg = __('MISSING_KEY', 'Default'); // With default value
+
+// ✅ _e() - Echo language string directly
+_e('WELCOME_MESSAGE'); // Same as: echo __('WELCOME_MESSAGE')
+_e('USER_ONLINE', 'Online'); // With default value
+
+// ✅ Common usage patterns
+$title = __('PAGE_TITLE', config()->get('sitename'));
+$error = __('ERROR.INVALID_INPUT', 'Invalid input');
+```
+
+These functions make language access much more convenient compared to the full `lang()->get()` syntax:
+
+```php
+// Before (verbose)
+echo lang()->get('FORUM');
+echo lang()->get('DATETIME.TODAY');
+$msg = lang()->get('WELCOME', 'Welcome');
+
+// After (concise)
+echo __('FORUM');
+echo __('DATETIME.TODAY');
+$msg = __('WELCOME', 'Welcome');
+```
+
+### Magic Methods Support
+```php
+// Magic getter (same as lang()->get())
+$welcome = lang()->WELCOME;
+$today = lang()->{'DATETIME.TODAY'};
+
+// Magic setter (same as lang()->set())
+lang()->CUSTOM_MESSAGE = 'Hello World';
+lang()->{'NESTED.KEY'} = 'Nested Value';
+
+// Magic isset
+if (isset(lang()->ADVANCED_FEATURE)) {
+ // Language key exists
+}
+```
+
+### Performance Benefits
+
+While maintaining compatibility, you get:
+- **Single Language Loading**: Languages loaded once and cached in singleton
+- **Memory Efficiency**: No duplicate language arrays across application
+- **Automatic Locale Setting**: Proper locale configuration for date/time formatting
+- **Fallback Chain**: Source language → Default language → Requested language
+
+### Verification
+
+To verify the migration is working correctly:
+
+```php
+// ✅ Test convenient shorthand functions
+echo "Forum text: " . __('FORUM');
+echo "Today text: " . __('DATETIME.TODAY');
+_e('INFORMATION'); // Echo directly
+
+// ✅ Test with default values
+echo "Custom: " . __('CUSTOM_KEY', 'Default Value');
+
+// ✅ Test full singleton access
+echo "Current language: " . lang()->getCurrentLanguage();
+echo "Language name: " . lang()->getLanguageName();
+
+// ✅ Test backward compatibility
+global $lang;
+echo "Global access: " . $lang['FORUM'];
+
+// ✅ Verify globals are synchronized
+lang()->set('TEST_KEY', 'Test Value');
+echo "Sync test: " . $lang['TEST_KEY']; // Should output: "Test Value"
+```
+
+## 🛡️ Censor System Migration
+
+The word censoring system has been refactored to use a singleton pattern, similar to the Configuration system, providing better performance and consistency.
+
+### Quick Migration Overview
+
+```php
+// ❌ Old way (still works, but not recommended)
+global $wordCensor;
+$censored = $wordCensor->censorString($text);
+
+// ✅ New way (recommended)
+$censored = censor()->censorString($text);
+```
+
+### Key Censor Changes
+
+#### Basic Usage
+```php
+// Censor a string
+$text = "This contains badword content";
+$censored = censor()->censorString($text);
+
+// Check if censoring is enabled
+if (censor()->isEnabled()) {
+ $censored = censor()->censorString($text);
+} else {
+ $censored = $text;
+}
+
+// Get count of loaded censored words
+$wordCount = censor()->getWordsCount();
+```
+
+#### Advanced Usage
+```php
+// Add runtime censored words (temporary, not saved to database)
+censor()->addWord('badword', '***');
+censor()->addWord('anotherbad*', 'replaced'); // Wildcards supported
+
+// Reload censored words from database (useful after admin updates)
+censor()->reload();
+
+// Check if censoring is enabled
+$isEnabled = censor()->isEnabled();
+```
+
+### Backward Compatibility
+
+The global `$wordCensor` variable is still available and works exactly as before:
+
+```php
+// This still works - backward compatibility maintained
+global $wordCensor;
+$censored = $wordCensor->censorString($text);
+
+// But this is now preferred
+$censored = censor()->censorString($text);
+```
+
+### Performance Benefits
+
+- **Single Instance**: Only one censor instance loads words from database
+- **Automatic Reloading**: Words are automatically reloaded when updated in admin panel
+- **Memory Efficient**: Shared instance across entire application
+- **Lazy Loading**: Words only loaded when censoring is enabled
+
+### Admin Panel Updates
+
+When you update censored words in the admin panel, the system now automatically:
+1. Updates the datastore cache
+2. Reloads the singleton instance with fresh words
+3. Applies changes immediately without requiring page refresh
+
+## 📋 Select System Migration
+
+The Select class has been moved and reorganized for better structure and consistency within the legacy system organization.
+
+### Quick Migration Overview
+
+```php
+// ❌ Old way (deprecated)
+\TorrentPier\Legacy\Select::language($new['default_lang'], 'default_lang');
+\TorrentPier\Legacy\Select::timezone('', 'timezone_type');
+\TorrentPier\Legacy\Select::template($pr_data['tpl_name'], 'tpl_name');
+
+// ✅ New way (recommended)
+\TorrentPier\Legacy\Common\Select::language($new['default_lang'], 'default_lang');
+\TorrentPier\Legacy\Common\Select::timezone('', 'timezone_type');
+\TorrentPier\Legacy\Common\Select::template($pr_data['tpl_name'], 'tpl_name');
+```
+
+#### Namespace Update
+The Select class has been moved from `\TorrentPier\Legacy\Select` to `\TorrentPier\Legacy\Common\Select` to better organize legacy components.
+
+#### Method Usage Remains Unchanged
+```php
+// Language selection dropdown
+$languageSelect = \TorrentPier\Legacy\Common\Select::language($currentLang, 'language_field');
+
+// Timezone selection dropdown
+$timezoneSelect = \TorrentPier\Legacy\Common\Select::timezone($currentTimezone, 'timezone_field');
+
+// Template selection dropdown
+$templateSelect = \TorrentPier\Legacy\Common\Select::template($currentTemplate, 'template_field');
+```
+
+#### Available Select Methods
+```php
+// All existing methods remain available:
+\TorrentPier\Legacy\Common\Select::language($selected, $name);
+\TorrentPier\Legacy\Common\Select::timezone($selected, $name);
+\TorrentPier\Legacy\Common\Select::template($selected, $name);
+```
+
+### Backward Compatibility
+
+The old class path is deprecated but still works through class aliasing:
+
+```php
+// This still works but is deprecated
+\TorrentPier\Legacy\Select::language($lang, 'default_lang');
+
+// This is the new recommended way
+\TorrentPier\Legacy\Common\Select::language($lang, 'default_lang');
+```
+
+### Migration Strategy
+
+1. **Search and Replace**: Update all references to the old namespace
+2. **Import Statements**: Update use statements if you're using them
+3. **Configuration Files**: Update any configuration that references the old class path
+
+```php
+// Update use statements
+// Old
+use TorrentPier\Legacy\Select;
+
+// New
+use TorrentPier\Legacy\Common\Select;
+```
+
+## 🛠️ Development System Migration
+
+The development and debugging system has been refactored to use a singleton pattern, providing better resource management and consistency across the application.
+
+### Quick Migration Overview
+
+```php
+// ❌ Old way (still works, but not recommended)
+$sqlLog = \TorrentPier\Dev::getSqlLog();
+$isDebugAllowed = \TorrentPier\Dev::sqlDebugAllowed();
+$shortQuery = \TorrentPier\Dev::shortQuery($sql);
+
+// ✅ New way (recommended)
+$sqlLog = dev()->getSqlDebugLog();
+$isDebugAllowed = dev()->checkSqlDebugAllowed();
+$shortQuery = dev()->formatShortQuery($sql);
+```
+
+### Key Development System Changes
+
+#### Basic Usage
+```php
+// Get SQL debug log
+$sqlLog = dev()->getSqlDebugLog();
+
+// Check if SQL debugging is allowed
+if (dev()->checkSqlDebugAllowed()) {
+ $debugInfo = dev()->getSqlDebugLog();
+}
+
+// Format SQL queries for display
+$formattedQuery = dev()->formatShortQuery($sql, true); // HTML escaped
+$plainQuery = dev()->formatShortQuery($sql, false); // Plain text
+```
+
+#### New Instance Methods
+```php
+// Access Whoops instance directly
+$whoops = dev()->getWhoops();
+
+// Check debug mode status
+if (dev()->isDebugEnabled()) {
+ // Debug mode is active
+}
+
+// Check environment
+if (dev()->isLocalEnvironment()) {
+ // Running in local development
+}
+```
+
+### Backward Compatibility
+
+All existing static method calls continue to work exactly as before:
+
+```php
+// This still works - backward compatibility maintained
+$sqlLog = \TorrentPier\Dev::getSqlLog();
+$isDebugAllowed = \TorrentPier\Dev::sqlDebugAllowed();
+$shortQuery = \TorrentPier\Dev::shortQuery($sql);
+
+// But this is now preferred
+$sqlLog = dev()->getSqlDebugLog();
+$isDebugAllowed = dev()->checkSqlDebugAllowed();
+$shortQuery = dev()->formatShortQuery($sql);
+```
+
+### Performance Benefits
+
+- **Single Instance**: Only one debugging instance across the entire application
+- **Resource Efficiency**: Whoops handlers initialized once and reused
+- **Memory Optimization**: Shared debugging state and configuration
+- **Lazy Loading**: Debug features only activated when needed
+
+### Advanced Usage
+
+```php
+// Access the singleton directly
+$devInstance = \TorrentPier\Dev::getInstance();
+
+// Initialize the system (called automatically in common.php)
+\TorrentPier\Dev::init();
+
+// Get detailed environment information
+$environment = [
+ 'debug_enabled' => dev()->isDebugEnabled(),
+ 'local_environment' => dev()->isLocalEnvironment(),
+ 'sql_debug_allowed' => dev()->sqlDebugAllowed(),
+];
+```
+
+## ⚠️ Breaking Changes
+
+### Database Layer Changes
+- **✅ No Breaking Changes**: All existing `DB()->method()` calls work exactly as before
+- **Removed Files**: `src/Legacy/SqlDb.php` and `src/Legacy/Dbs.php` (replaced by modern implementation)
+- **New Implementation**: Uses Nette Database v3.2 internally with full backward compatibility
+
+### Deprecated Functions
+- `get_config()` → Use `config()->get()`
+- `set_config()` → Use `config()->set()`
+- Direct `$bb_cfg` access → Use `config()` methods
+
+### Deprecated Patterns
+- `new TorrentPier\Censor()` → Use `censor()` global function
+- Direct `$wordCensor` access → Use `censor()` methods
+- `new TorrentPier\Dev()` → Use `dev()` global function
+- Static `Dev::` methods → Use `dev()` instance methods
+- `\TorrentPier\Legacy\Select::` → Use `\TorrentPier\Legacy\Common\Select::`
+
+### File Structure Changes
+- New `/src/Database/` directory for modern database classes
+- New `/src/` directory for modern PHP classes
+- Reorganized template structure
+
+### Template Changes
+- Updated template syntax in some areas
+- New template variables available
+- Deprecated template functions
+
+## 📋 Best Practices
+
+### Configuration Management
+```php
+// ✅ Always provide defaults
+$timeout = config()->get('api.timeout', 30);
+
+// ✅ Use type hints
+function getMaxUploadSize(): int {
+ return (int) config()->get('upload.max_size', 10485760);
+}
+
+// ✅ Cache frequently used values
+class TrackerService {
+ private string $announceUrl;
+
+ public function __construct() {
+ $this->announceUrl = config()->get('bt_announce_url');
+ }
+}
+```
+
+### Censor Management
+```php
+// ✅ Check if censoring is enabled before processing
+function processUserInput(string $text): string {
+ if (censor()->isEnabled()) {
+ return censor()->censorString($text);
+ }
+ return $text;
+}
+
+// ✅ Use the singleton consistently
+$censoredText = censor()->censorString($input);
+```
+
+### Select Usage
+```php
+// ✅ Use the new namespace consistently
+$languageSelect = \TorrentPier\Legacy\Common\Select::language($currentLang, 'language_field');
+
+// ✅ Store frequently used selects
+class AdminPanel {
+ private string $languageSelect;
+ private string $timezoneSelect;
+
+ public function __construct() {
+ $this->languageSelect = \TorrentPier\Legacy\Common\Select::language('', 'default_lang');
+ $this->timezoneSelect = \TorrentPier\Legacy\Common\Select::timezone('', 'timezone');
+ }
+}
+```
+
+### Development and Debugging
+```php
+// ✅ Use instance methods for debugging
+if (dev()->checkSqlDebugAllowed()) {
+ $debugLog = dev()->getSqlDebugLog();
+}
+
+// ✅ Access debugging utilities consistently
+function formatSqlForDisplay(string $sql): string {
+ return dev()->formatShortQuery($sql, true);
+}
+
+// ✅ Check environment properly
+if (dev()->isLocalEnvironment()) {
+ // Development-specific code
+}
+class ForumPost {
+ public function getDisplayText(): string {
+ return censor()->censorString($this->text);
+ }
+}
+
+// ✅ Add runtime words when needed
+function setupCustomCensoring(): void {
+ if (isCustomModeEnabled()) {
+ censor()->addWord('custombad*', '[censored]');
+ }
+}
+```
+
+### Error Handling
+```php
+// ✅ Graceful error handling
+try {
+ $dbConfig = config()->getSection('database');
+ // Database operations
+} catch (Exception $e) {
+ error_log("Database configuration error: " . $e->getMessage());
+ // Fallback behavior
+}
+```
+
+### Performance Optimization
+```php
+// ✅ Minimize configuration calls in loops
+$cacheEnabled = config()->get('cache.enabled', false);
+for ($i = 0; $i < 1000; $i++) {
+ if ($cacheEnabled) {
+ // Use cached value
+ }
+}
+```
+
+### Security Considerations
+```php
+// ✅ Validate configuration values
+$maxFileSize = min(
+ config()->get('upload.max_size', 1048576),
+ 1048576 * 100 // Hard limit: 100MB
+);
+
+// ✅ Sanitize user-configurable values
+$siteName = htmlspecialchars(config()->get('sitename', 'TorrentPier'));
+```
+
+### Testing and Quality Assurance
+```bash
+# ✅ Run tests before deploying changes
+./vendor/bin/pest
+
+# ✅ Validate test coverage for new components
+./vendor/bin/pest --coverage
+```
+
+For comprehensive testing documentation and best practices, see [tests/README.md](tests/README.md).
+
+---
+
+**Important**: Always test the upgrade process in a staging environment before applying it to production. Keep backups of your database and files until you're confident the upgrade was successful.
+
+For additional support, visit our [Official Forum](https://torrentpier.com) or check our [GitHub Repository](https://github.com/torrentpier/torrentpier) for the latest updates and community discussions.
diff --git a/_cleanup.php b/_cleanup.php
new file mode 100644
index 000000000..d9802822a
--- /dev/null
+++ b/_cleanup.php
@@ -0,0 +1,57 @@
+php ' . basename(__FILE__) . ' in CLI mode');
+}
+
+// Get all constants
+require_once BB_ROOT . 'library/defines.php';
+
+// Include CLI functions
+require INC_DIR . '/functions_cli.php';
+
+// Welcoming message
+out("--- Release creation tool ---\n", 'info');
+
+$configFile = BB_PATH . '/library/config.php';
+
+if (!is_file($configFile)) {
+ out('- Config file ' . basename($configFile) . ' not found', 'error');
+ exit;
+}
+if (!is_readable($configFile)) {
+ out('- Config file ' . basename($configFile) . ' is not readable', 'error');
+ exit;
+}
+if (!is_writable($configFile)) {
+ out('- Config file ' . basename($configFile) . ' is not writable', 'error');
+ exit;
+}
+
+// Ask for version
+fwrite(STDOUT, 'Enter version number (e.g, v2.4.0): ');
+$version = trim(fgets(STDIN));
+
+if (empty($version)) {
+ out("- Version cannot be empty. Please enter a valid version number", 'error');
+ exit;
+} else {
+ // Add 'v' prefix if missing
+ if (!str_starts_with($version, 'v')) {
+ $version = 'v' . $version;
+ }
+
+ out("- Using version: $version", 'info');
+}
+
+// Ask for version emoji
+fwrite(STDOUT, 'Enter version emoji: ');
+$versionEmoji = trim(fgets(STDIN));
+
+if (!empty($versionEmoji)) {
+ out("- Using version emoji: $versionEmoji", 'info');
+}
+
+// Ask for release date or use today's date
+fwrite(STDOUT, "Enter release date (e.g. 25-05-2025), leave empty to use today's date: ");
+$date = trim(fgets(STDIN));
+
+if (empty($date)) {
+ $date = date('d-m-Y');
+ out("- Using current date: $date", 'info');
+} else {
+ // Validate date format (dd-mm-yyyy)
+ $dateObj = DateTime::createFromFormat('d-m-Y', $date);
+ if (!$dateObj || $dateObj->format('d-m-Y') !== $date) {
+ out("- Invalid date format. Expected format: DD-MM-YYYY", 'error');
+ exit;
+ }
+
+ out("- Using date: $date", 'info');
+}
+
+// Read config file content
+$content = file_get_contents($configFile);
+
+// Update version
+$content = preg_replace(
+ "/\\\$bb_cfg\['tp_version'\]\s*=\s*'[^']*';/",
+ "\$bb_cfg['tp_version'] = '$version';",
+ $content
+);
+
+// Update release date
+$content = preg_replace(
+ "/\\\$bb_cfg\['tp_release_date'\]\s*=\s*'[^']*';/",
+ "\$bb_cfg['tp_release_date'] = '$date';",
+ $content
+);
+
+// Save updated config
+$bytesWritten = file_put_contents($configFile, $content);
+
+if ($bytesWritten === false) {
+ out("- Failed to write to config file", 'error');
+ exit;
+}
+
+if ($bytesWritten === 0) {
+ out("- Config file was not updated (0 bytes written)", 'error');
+ exit;
+}
+
+out("\n- Config file has been updated!", 'success');
+
+// Update CHANGELOG.md
+runProcess('npx git-cliff v2.4.6-alpha.4.. --config cliff.toml --tag "' . $version . '" > CHANGELOG.md');
+
+// Git add & commit
+runProcess('git add -A && git commit -m "release: ' . escapeshellarg($version) . (!empty($versionEmoji) ? (' ' . $versionEmoji) : '') . '"');
+
+// Git tag
+runProcess("git tag -a \"$version\" -m \"Release $version\"");
+runProcess("git tag -v \"$version\"");
+
+// Git push
+runProcess("git push origin master");
+runProcess("git push origin $version");
+
+out("\n- Release $version has been successfully prepared, committed and pushed!", 'success');
diff --git a/admin/admin_attach_cp.php b/admin/admin_attach_cp.php
index 274b673bb..a7f1ab498 100644
--- a/admin/admin_attach_cp.php
+++ b/admin/admin_attach_cp.php
@@ -1,556 +1,477 @@
get('topics_per_page');
+ break;
+ case 'attachments':
+ $order_by = 'ORDER BY total_attachments ' . $sort_order . ' LIMIT ' . $start . ', ' . config()->get('topics_per_page');
+ break;
+ case 'filesize':
+ $order_by = 'ORDER BY total_size ' . $sort_order . ' LIMIT ' . $start . ', ' . config()->get('topics_per_page');
+ break;
+ default:
+ $mode = 'attachments';
+ $sort_order = 'DESC';
+ $order_by = 'ORDER BY total_attachments ' . $sort_order . ' LIMIT ' . $start . ', ' . config()->get('topics_per_page');
+ break;
+ }
+} elseif ($view === 'attachments') {
+ switch ($mode) {
+ case 'real_filename':
+ $order_by = 'ORDER BY a.real_filename ' . $sort_order . ' LIMIT ' . $start . ', ' . config()->get('topics_per_page');
+ break;
+ case 'comment':
+ $order_by = 'ORDER BY a.comment ' . $sort_order . ' LIMIT ' . $start . ', ' . config()->get('topics_per_page');
+ break;
+ case 'extension':
+ $order_by = 'ORDER BY a.extension ' . $sort_order . ' LIMIT ' . $start . ', ' . config()->get('topics_per_page');
+ break;
+ case 'filesize':
+ $order_by = 'ORDER BY a.filesize ' . $sort_order . ' LIMIT ' . $start . ', ' . config()->get('topics_per_page');
+ break;
+ case 'downloads':
+ $order_by = 'ORDER BY a.download_count ' . $sort_order . ' LIMIT ' . $start . ', ' . config()->get('topics_per_page');
+ break;
+ case 'post_time':
+ $order_by = 'ORDER BY a.filetime ' . $sort_order . ' LIMIT ' . $start . ', ' . config()->get('topics_per_page');
+ break;
+ default:
+ $mode = 'a.real_filename';
+ $sort_order = 'ASC';
+ $order_by = 'ORDER BY a.real_filename ' . $sort_order . ' LIMIT ' . $start . ', ' . config()->get('topics_per_page');
+ break;
+ }
}
// Set select fields
-$view_types_text = array($lang['VIEW_STATISTIC'], $lang['VIEW_SEARCH']);
-$view_types = array('stats', 'search');
+$view_types_text = [$lang['VIEW_STATISTIC'], $lang['VIEW_SEARCH']];
+$view_types = ['stats', 'search'];
+$select_view = '';
-$select_view = '';
-
-for($i = 0; $i < count($view_types_text); $i++)
-{
- $selected = ($view == $view_types[$i]) ? ' selected="selected"' : '';
- $select_view .= '' . $view_types_text[$i] . ' ';
+if (in_array($view, $view_types)) {
+ $select_view = '';
+ for ($i = 0, $iMax = count($view_types_text); $i < $iMax; $i++) {
+ $selected = ($view === $view_types[$i]) ? ' selected' : '';
+ $select_view .= '' . $view_types_text[$i] . ' ';
+ }
+ $select_view .= ' ';
}
-$select_view .= ' ';
-if (count($mode_types_text) > 0)
-{
- $select_sort_mode = '';
-
- for($i = 0; $i < count($mode_types_text); $i++)
- {
- $selected = ($mode == $mode_types[$i]) ? ' selected="selected"' : '';
- $select_sort_mode .= '' . $mode_types_text[$i] . ' ';
- }
- $select_sort_mode .= ' ';
+if (count($mode_types_text) > 0 && !empty($mode_types)) {
+ $select_sort_mode = '';
+ for ($i = 0, $iMax = count($mode_types_text); $i < $iMax; $i++) {
+ $selected = ($mode === $mode_types[$i]) ? ' selected' : '';
+ $select_sort_mode .= '' . $mode_types_text[$i] . ' ';
+ }
+ $select_sort_mode .= ' ';
}
$select_sort_order = '';
-if ($sort_order == 'ASC')
-{
- $select_sort_order .= '' . $lang['ASC'] . ' ' . $lang['DESC'] . ' ';
-}
-else
-{
- $select_sort_order .= '' . $lang['ASC'] . ' ' . $lang['DESC'] . ' ';
+if ($sort_order === 'ASC') {
+ $select_sort_order .= '' . $lang['ASC'] . ' ' . $lang['DESC'] . ' ';
+} else {
+ $select_sort_order .= '' . $lang['ASC'] . ' ' . $lang['DESC'] . ' ';
}
$select_sort_order .= ' ';
-$submit_change = ( isset($_POST['submit_change']) ) ? TRUE : FALSE;
-$delete = ( isset($_POST['delete']) ) ? TRUE : FALSE;
-$delete_id_list = get_var('delete_id_list', array(0));
+$submit_change = isset($_POST['submit_change']);
+$delete = isset($_POST['delete']);
+$delete_id_list = get_var('delete_id_list', [0]);
$confirm = isset($_POST['confirm']);
-if ($confirm && sizeof($delete_id_list) > 0)
-{
- $attachments = array();
+if ($confirm && count($delete_id_list) > 0) {
+ $attachments = [];
- delete_attachment(0, $delete_id_list);
-}
-else if ($delete && sizeof($delete_id_list) > 0)
-{
- // Not confirmed, show confirmation message
- $hidden_fields = ' ';
- $hidden_fields .= ' ';
- $hidden_fields .= ' ';
- $hidden_fields .= ' ';
- $hidden_fields .= ' ';
+ delete_attachment(0, $delete_id_list);
+} elseif ($delete && count($delete_id_list) > 0) {
+ // Not confirmed, show confirmation message
+ $hidden_fields = ' ';
+ $hidden_fields .= ' ';
+ $hidden_fields .= ' ';
+ $hidden_fields .= ' ';
+ $hidden_fields .= ' ';
- for ($i = 0; $i < sizeof($delete_id_list); $i++)
- {
- $hidden_fields .= ' ';
- }
+ foreach ($delete_id_list as $iValue) {
+ $hidden_fields .= ' ';
+ }
- print_confirmation(array(
- 'FORM_ACTION' => "admin_attach_cp.php",
- 'HIDDEN_FIELDS' => $hidden_fields,
- ));
+ print_confirmation([
+ 'FORM_ACTION' => 'admin_attach_cp.php',
+ 'HIDDEN_FIELDS' => $hidden_fields,
+ ]);
}
// Assign Default Template Vars
-$template->assign_vars(array(
- 'S_VIEW_SELECT' => $select_view,
- 'S_MODE_ACTION' => 'admin_attach_cp.php',
-));
+$template->assign_vars([
+ 'S_VIEW_SELECT' => $select_view,
+ 'S_MODE_ACTION' => 'admin_attach_cp.php?view=' . $view . '&mode=' . $mode . '&order=' . $sort_order . '&uid=' . $uid
+]);
-if ($submit_change && $view == 'attachments')
-{
- $attach_change_list = get_var('attach_id_list', array(0));
- $attach_comment_list = get_var('attach_comment_list', array(''));
- $attach_download_count_list = get_var('attach_count_list', array(0));
+if ($submit_change && $view === 'attachments') {
+ $attach_change_list = get_var('attach_id_list', [0]);
+ $attach_comment_list = get_var('attach_comment_list', ['']);
+ $attach_download_count_list = get_var('attach_count_list', [0]);
- // Generate correct Change List
- $attachments = array();
+ // Generate correct Change List
+ $attachments = [];
- for ($i = 0; $i < count($attach_change_list); $i++)
- {
- $attachments['_' . $attach_change_list[$i]]['comment'] = $attach_comment_list[$i];
- $attachments['_' . $attach_change_list[$i]]['download_count'] = $attach_download_count_list[$i];
- }
+ for ($i = 0, $iMax = count($attach_change_list); $i < $iMax; $i++) {
+ $attachments['_' . $attach_change_list[$i]]['comment'] = $attach_comment_list[$i];
+ $attachments['_' . $attach_change_list[$i]]['download_count'] = $attach_download_count_list[$i];
+ }
- $sql = 'SELECT *
+ $sql = 'SELECT *
FROM ' . BB_ATTACHMENTS_DESC . '
ORDER BY attach_id';
- if (!($result = DB()->sql_query($sql)))
- {
- bb_die('Could not get attachment informations');
- }
+ if (!($result = DB()->sql_query($sql))) {
+ bb_die('Could not get attachment informations');
+ }
- while ( $attachrow = DB()->sql_fetchrow($result) )
- {
- if ( isset($attachments['_' . $attachrow['attach_id']]) )
- {
- if ($attachrow['comment'] != $attachments['_' . $attachrow['attach_id']]['comment'] || $attachrow['download_count'] != $attachments['_' . $attachrow['attach_id']]['download_count'])
- {
- $sql = "UPDATE " . BB_ATTACHMENTS_DESC . "
- SET comment = '" . attach_mod_sql_escape($attachments['_' . $attachrow['attach_id']]['comment']) . "', download_count = " . (int) $attachments['_' . $attachrow['attach_id']]['download_count'] . "
- WHERE attach_id = " . (int) $attachrow['attach_id'];
+ while ($attachrow = DB()->sql_fetchrow($result)) {
+ if (isset($attachments['_' . $attachrow['attach_id']])) {
+ if ($attachrow['comment'] != $attachments['_' . $attachrow['attach_id']]['comment'] || $attachrow['download_count'] != $attachments['_' . $attachrow['attach_id']]['download_count']) {
+ $sql = 'UPDATE ' . BB_ATTACHMENTS_DESC . "
+ SET comment = '" . DB()->escape($attachments['_' . $attachrow['attach_id']]['comment']) . "', download_count = " . (int)$attachments['_' . $attachrow['attach_id']]['download_count'] . '
+ WHERE attach_id = ' . (int)$attachrow['attach_id'];
- if (!DB()->sql_query($sql))
- {
- bb_die('Could not update attachments informations');
- }
- }
- }
- }
- DB()->sql_freeresult($result);
+ if (!DB()->sql_query($sql)) {
+ bb_die('Could not update attachments informations');
+ }
+ }
+ }
+ }
+ DB()->sql_freeresult($result);
}
// Statistics
-if ($view == 'stats')
-{
- $upload_dir_size = get_formatted_dirsize();
+if ($view == 'stats') {
+ $upload_dir_size = get_formatted_dirsize();
- $attachment_quota = humn_size($attach_config['attachment_quota']);
+ $attachment_quota = humn_size($attach_config['attachment_quota']);
- // number_of_attachments
- $row = DB()->fetch_row("
- SELECT COUNT(*) AS total FROM ". BB_ATTACHMENTS_DESC ."
- ");
- $number_of_attachments = $number_of_posts = $row['total'];
+ // number_of_attachments
+ $row = DB()->fetch_row('SELECT COUNT(*) AS total FROM ' . BB_ATTACHMENTS_DESC);
+ $number_of_attachments = $number_of_posts = $row['total'];
- $number_of_pms = 0;
+ $number_of_pms = 0;
- // number_of_topics
- $row = DB()->fetch_row("
- SELECT COUNT(*) AS topics FROM ". BB_TOPICS ." WHERE topic_attachment = 1
- ");
- $number_of_topics = $row['topics'];
+ // number_of_topics
+ $row = DB()->fetch_row('SELECT COUNT(*) AS topics FROM ' . BB_TOPICS . ' WHERE topic_attachment = 1');
+ $number_of_topics = $row['topics'];
- // number_of_users
- $row = DB()->fetch_row("
- SELECT COUNT(DISTINCT user_id_1) AS users FROM ". BB_ATTACHMENTS ." WHERE post_id != 0
- ");
- $number_of_users = $row['users'];
-
- $template->assign_vars(array(
- 'TPL_ATTACH_STATISTICS' => true,
- 'TOTAL_FILESIZE' => $upload_dir_size,
- 'ATTACH_QUOTA' => $attachment_quota,
- 'NUMBER_OF_ATTACHMENTS' => $number_of_attachments,
- 'NUMBER_OF_POSTS' => $number_of_posts,
- 'NUMBER_OF_PMS' => $number_of_pms,
- 'NUMBER_OF_TOPICS' => $number_of_topics,
- 'NUMBER_OF_USERS' => $number_of_users,
- ));
+ // number_of_users
+ $row = DB()->fetch_row('SELECT COUNT(DISTINCT user_id_1) AS users FROM ' . BB_ATTACHMENTS . ' WHERE post_id != 0');
+ $number_of_users = $row['users'];
+ $template->assign_vars([
+ 'TPL_ATTACH_STATISTICS' => true,
+ 'TOTAL_FILESIZE' => $upload_dir_size,
+ 'ATTACH_QUOTA' => $attachment_quota,
+ 'NUMBER_OF_ATTACHMENTS' => $number_of_attachments,
+ 'NUMBER_OF_POSTS' => $number_of_posts,
+ 'NUMBER_OF_PMS' => $number_of_pms,
+ 'NUMBER_OF_TOPICS' => $number_of_topics,
+ 'NUMBER_OF_USERS' => $number_of_users,
+ ]);
}
// Search
-if ($view == 'search')
-{
- // Get Forums and Categories
- //sf - add [, f.forum_parent]
- $sql = "SELECT c.cat_title, c.cat_id, f.forum_name, f.forum_id, f.forum_parent
- FROM " . BB_CATEGORIES . " c, " . BB_FORUMS . " f
+if ($view === 'search') {
+ // Get Forums and Categories
+ //sf - add [, f.forum_parent]
+ $sql = 'SELECT c.cat_title, c.cat_id, f.forum_name, f.forum_id, f.forum_parent
+ FROM ' . BB_CATEGORIES . ' c, ' . BB_FORUMS . ' f
WHERE f.cat_id = c.cat_id
- ORDER BY c.cat_id, f.forum_order";
+ ORDER BY c.cat_id, f.forum_order';
- if (!($result = DB()->sql_query($sql)))
- {
- bb_die('Could not obtain forum_name / forum_id');
- }
+ if (!($result = DB()->sql_query($sql))) {
+ bb_die('Could not obtain forum_name / forum_id');
+ }
- $s_forums = '';
- while ($row = DB()->sql_fetchrow($result))
- { //sf
- $s_forums .= '' . (($row['forum_parent']) ? HTML_SF_SPACER : '') . htmlCHR($row['forum_name']) . ' ';
+ $s_forums = '';
+ $list_cat = [];
+ while ($row = DB()->sql_fetchrow($result)) { //sf
+ $s_forums .= '' . ($row['forum_parent'] ? HTML_SF_SPACER : '') . htmlCHR($row['forum_name']) . ' ';
- if( empty($list_cat[$row['cat_id']]) )
- {
- $list_cat[$row['cat_id']] = $row['cat_title'];
- }
- }
+ if (empty($list_cat[$row['cat_id']])) {
+ $list_cat[$row['cat_id']] = $row['cat_title'];
+ }
+ }
- if( $s_forums != '' )
- {
- $s_forums = '' . $lang['ALL_AVAILABLE'] . ' ' . $s_forums;
+ $s_categories = '';
+ if ($s_forums) {
+ $s_forums = '' . $lang['ALL_AVAILABLE'] . ' ' . $s_forums;
- // Category to search
- $s_categories = '' . $lang['ALL_AVAILABLE'] . ' ';
+ // Category to search
+ $s_categories = '' . $lang['ALL_AVAILABLE'] . ' ';
- foreach ($list_cat as $cat_id => $cat_title)
- {
- $s_categories .= '' . htmlCHR($cat_title) . ' ';
- }
- }
- else
- {
- bb_die($lang['NO_SEARCHABLE_FORUMS']);
- }
+ foreach ($list_cat as $cat_id => $cat_title) {
+ $s_categories .= '' . htmlCHR($cat_title) . ' ';
+ }
+ } else {
+ bb_die($lang['NO_SEARCHABLE_FORUMS']);
+ }
- $template->assign_vars(array(
- 'TPL_ATTACH_SEARCH' => true,
- 'S_FORUM_OPTIONS' => $s_forums,
- 'S_CATEGORY_OPTIONS' => $s_categories,
- 'S_SORT_OPTIONS' => $select_sort_mode,
- 'S_SORT_ORDER' => $select_sort_order,
- ));
+ $template->assign_vars([
+ 'TPL_ATTACH_SEARCH' => true,
+ 'S_FORUM_OPTIONS' => $s_forums,
+ 'S_CATEGORY_OPTIONS' => $s_categories,
+ 'S_SORT_OPTIONS' => $select_sort_mode,
+ 'S_SORT_ORDER' => $select_sort_order,
+ ]);
}
// Username
-if ($view == 'username')
-{
- $template->assign_vars(array(
- 'TPL_ATTACH_USER' => true,
- 'S_MODE_SELECT' => $select_sort_mode,
- 'S_ORDER_SELECT' => $select_sort_order,
- ));
- $total_rows = 0;
- bb_die('removed');
+if ($view === 'username') {
+ $template->assign_vars([
+ 'TPL_ATTACH_USER' => true,
+ 'S_MODE_SELECT' => $select_sort_mode,
+ 'S_ORDER_SELECT' => $select_sort_order,
+ ]);
+ $total_rows = 0;
+ bb_die('removed');
}
// Attachments
-if ($view == 'attachments')
-{
- $user_based = ($uid) ? TRUE : FALSE;
- $search_based = (isset($_POST['search']) && $_POST['search']) ? TRUE : FALSE;
+if ($view === 'attachments') {
+ $user_based = (bool)$uid;
+ $search_based = (isset($_POST['search']) && $_POST['search']);
- $hidden_fields = '';
+ $hidden_fields = '';
- $template->assign_vars(array(
- 'TPL_ATTACH_ATTACHMENTS' => true,
- 'S_MODE_SELECT' => $select_sort_mode,
- 'S_ORDER_SELECT' => $select_sort_order,
- ));
+ $template->assign_vars([
+ 'TPL_ATTACH_ATTACHMENTS' => true,
+ 'S_MODE_SELECT' => $select_sort_mode,
+ 'S_ORDER_SELECT' => $select_sort_order,
+ ]);
- $total_rows = 0;
+ $total_rows = 0;
- // Are we called from Username ?
- if ($user_based)
- {
- $sql = "SELECT username FROM " . BB_USERS . " WHERE user_id = " . intval($uid);
+ // Are we called from Username ?
+ if ($user_based) {
+ $sql = 'SELECT username FROM ' . BB_USERS . ' WHERE user_id = ' . (int)$uid;
- if (!($result = DB()->sql_query($sql)))
- {
- bb_die('Error getting username');
- }
+ if (!($result = DB()->sql_query($sql))) {
+ bb_die('Error getting username');
+ }
- $row = DB()->sql_fetchrow($result);
- DB()->sql_freeresult($result);
- $username = $row['username'];
+ $row = DB()->sql_fetchrow($result);
+ DB()->sql_freeresult($result);
+ $username = $row['username'];
- $s_hidden = ' ';
+ $s_hidden = ' ';
- $template->assign_block_vars('switch_user_based', array());
+ $template->assign_block_vars('switch_user_based', []);
- $template->assign_vars(array(
- 'S_USER_HIDDEN' => $s_hidden,
- 'L_STATISTICS_FOR_USER' => sprintf($lang['STATISTICS_FOR_USER'], $username),
- ));
+ $template->assign_vars([
+ 'S_USER_HIDDEN' => $s_hidden,
+ 'L_STATISTICS_FOR_USER' => sprintf($lang['STATISTICS_FOR_USER'], $username),
+ ]);
- $sql = "SELECT attach_id
- FROM " . BB_ATTACHMENTS . "
- WHERE user_id_1 = " . intval($uid) . "
- GROUP BY attach_id";
+ $sql = 'SELECT attach_id
+ FROM ' . BB_ATTACHMENTS . '
+ WHERE user_id_1 = ' . (int)$uid . '
+ GROUP BY attach_id';
- if (!($result = DB()->sql_query($sql)))
- {
- bb_die('Could not query attachments #1');
- }
+ if (!($result = DB()->sql_query($sql))) {
+ bb_die('Could not query attachments #1');
+ }
- $attach_ids = DB()->sql_fetchrowset($result);
- $num_attach_ids = DB()->num_rows($result);
- DB()->sql_freeresult($result);
+ $attach_ids = DB()->sql_fetchrowset($result);
+ $num_attach_ids = DB()->num_rows($result);
+ DB()->sql_freeresult($result);
- if ($num_attach_ids == 0)
- {
- bb_die('For some reason no attachments are assigned to the user ' . $username);
- }
+ if ($num_attach_ids == 0) {
+ bb_die('For some reason no attachments are assigned to the user ' . $username);
+ }
- $total_rows = $num_attach_ids;
+ $total_rows = $num_attach_ids;
- $attach_id = array();
+ $attach_id = [];
- for ($j = 0; $j < $num_attach_ids; $j++)
- {
- $attach_id[] = intval($attach_ids[$j]['attach_id']);
- }
+ for ($j = 0; $j < $num_attach_ids; $j++) {
+ $attach_id[] = (int)$attach_ids[$j]['attach_id'];
+ }
- $sql = "SELECT a.*
- FROM " . BB_ATTACHMENTS_DESC . " a
- WHERE a.attach_id IN (" . implode(', ', $attach_id) . ") " .
- $order_by;
+ $sql = 'SELECT a.*
+ FROM ' . BB_ATTACHMENTS_DESC . ' a
+ WHERE a.attach_id IN (' . implode(', ', $attach_id) . ') ' .
+ $order_by;
- if (!($result = DB()->sql_query($sql)))
- {
- bb_die('Could not query attachments #2');
- }
+ if (!($result = DB()->sql_query($sql))) {
+ bb_die('Could not query attachments #2');
+ }
- $attachments = DB()->sql_fetchrowset($result);
- $num_attach = DB()->num_rows($result);
- DB()->sql_freeresult($result);
- }
- else
- {
- // we are called from search
- $attachments = search_attachments($order_by, $total_rows);
- }
+ $attachments = DB()->sql_fetchrowset($result);
+ $num_attach = DB()->num_rows($result);
+ DB()->sql_freeresult($result);
+ } else {
+ // we are called from search
+ $attachments = search_attachments($order_by, $total_rows);
+ }
- if (sizeof($attachments) > 0)
- {
- for ($i = 0; $i < sizeof($attachments); $i++)
- {
- $delete_box = ' ';
+ if (count($attachments) > 0) {
+ for ($i = 0, $iMax = count($attachments); $i < $iMax; $i++) {
+ $delete_box = ' ';
- for ($j = 0; $j < count($delete_id_list); $j++)
- {
- if ($delete_id_list[$j] == $attachments[$i]['attach_id'])
- {
- $delete_box = ' ';
- break;
- }
- }
+ foreach ($delete_id_list as $jValue) {
+ if ($jValue == $attachments[$i]['attach_id']) {
+ $delete_box = ' ';
+ break;
+ }
+ }
- $row_class = !($i % 2) ? 'row1' : 'row2';
+ $row_class = !($i % 2) ? 'row1' : 'row2';
- // Is the Attachment assigned to more than one post ?
- // If it's not assigned to any post, it's an private message thingy. ;)
- $post_titles = array();
+ // Is the Attachment assigned to more than one post ?
+ // If it's not assigned to any post, it's an private message thingy. ;)
+ $post_titles = [];
- $sql = "SELECT *
- FROM " . BB_ATTACHMENTS . "
- WHERE attach_id = " . intval($attachments[$i]['attach_id']);
+ $sql = 'SELECT *
+ FROM ' . BB_ATTACHMENTS . '
+ WHERE attach_id = ' . (int)$attachments[$i]['attach_id'];
- if (!($result = DB()->sql_query($sql)))
- {
- bb_die('Could not query attachments #3');
- }
+ if (!($result = DB()->sql_query($sql))) {
+ bb_die('Could not query attachments #3');
+ }
- $ids = DB()->sql_fetchrowset($result);
- $num_ids = DB()->num_rows($result);
- DB()->sql_freeresult($result);
+ $ids = DB()->sql_fetchrowset($result);
+ $num_ids = DB()->num_rows($result);
+ DB()->sql_freeresult($result);
- for ($j = 0; $j < $num_ids; $j++)
- {
- if ($ids[$j]['post_id'] != 0)
- {
- $sql = "SELECT t.topic_title
- FROM " . BB_TOPICS . " t, " . BB_POSTS . " p
- WHERE p.post_id = " . intval($ids[$j]['post_id']) . " AND p.topic_id = t.topic_id
- GROUP BY t.topic_id, t.topic_title";
+ for ($j = 0; $j < $num_ids; $j++) {
+ if ($ids[$j]['post_id'] != 0) {
+ $sql = 'SELECT t.topic_title
+ FROM ' . BB_TOPICS . ' t, ' . BB_POSTS . ' p
+ WHERE p.post_id = ' . (int)$ids[$j]['post_id'] . ' AND p.topic_id = t.topic_id
+ GROUP BY t.topic_id, t.topic_title';
- if (!($result = DB()->sql_query($sql)))
- {
- bb_die('Could not query topic');
- }
+ if (!($result = DB()->sql_query($sql))) {
+ bb_die('Could not query topic');
+ }
- $row = DB()->sql_fetchrow($result);
- DB()->sql_freeresult($result);
- $post_title = $row['topic_title'];
+ $row = DB()->sql_fetchrow($result);
+ DB()->sql_freeresult($result);
+ $post_title = str_short($row['topic_title'], 30);
- if (strlen($post_title) > 32)
- {
- $post_title = str_short($post_title, 30);
- }
+ $view_topic = BB_ROOT . POST_URL . $ids[$j]['post_id'] . '#' . $ids[$j]['post_id'];
- $view_topic = BB_ROOT . 'viewtopic.php?' . POST_POST_URL . '=' . $ids[$j]['post_id'] . '#' . $ids[$j]['post_id'];
+ $post_titles[] = '' . $post_title . ' ';
+ } else {
+ $post_titles[] = $lang['PRIVATE_MESSAGE'];
+ }
+ }
- $post_titles[] = '' . $post_title . ' ';
- }
- else
- {
- $post_titles[] = $lang['PRIVATE_MESSAGE'];
- }
- }
+ $post_titles = implode(' ', $post_titles);
- $post_titles = implode(' ', $post_titles);
+ $hidden_field = ' ';
- $hidden_field = ' ';
+ $template->assign_block_vars('attachrow', [
+ 'ROW_NUMBER' => $i + (@$_GET['start'] + 1),
+ 'ROW_CLASS' => $row_class,
- $template->assign_block_vars('attachrow', array(
- 'ROW_NUMBER' => $i + ( @$_GET['start'] + 1 ),
- 'ROW_CLASS' => $row_class,
+ 'FILENAME' => htmlspecialchars($attachments[$i]['real_filename']),
+ 'COMMENT' => htmlspecialchars($attachments[$i]['comment']),
+ 'EXTENSION' => $attachments[$i]['extension'],
+ 'SIZE' => humn_size($attachments[$i]['filesize'], 2),
+ 'DOWNLOAD_COUNT' => $attachments[$i]['download_count'],
+ 'POST_TIME' => bb_date($attachments[$i]['filetime']),
+ 'POST_TITLE' => $post_titles,
- 'FILENAME' => htmlspecialchars($attachments[$i]['real_filename']),
- 'COMMENT' => htmlspecialchars($attachments[$i]['comment']),
- 'EXTENSION' => $attachments[$i]['extension'],
- 'SIZE' => round(($attachments[$i]['filesize'] / 1024), 2),
- 'DOWNLOAD_COUNT' => $attachments[$i]['download_count'],
- 'POST_TIME' => bb_date($attachments[$i]['filetime']),
- 'POST_TITLE' => $post_titles,
+ 'S_DELETE_BOX' => $delete_box,
+ 'S_HIDDEN' => $hidden_field,
+ 'U_VIEW_ATTACHMENT' => BB_ROOT . DL_URL . $attachments[$i]['attach_id'],
+ ]);
+ }
+ }
- 'S_DELETE_BOX' => $delete_box,
- 'S_HIDDEN' => $hidden_field,
- 'U_VIEW_ATTACHMENT' => BB_ROOT . DOWNLOAD_URL . $attachments[$i]['attach_id'],
- ));
+ if (!$search_based && !$user_based) {
+ if (!$attachments) {
+ $sql = 'SELECT attach_id FROM ' . BB_ATTACHMENTS_DESC;
- }
- }
+ if (!($result = DB()->sql_query($sql))) {
+ bb_die('Could not query attachment description table');
+ }
- if (!$search_based && !$user_based)
- {
- if ($total_attachments == 0)
- {
- $sql = "SELECT attach_id FROM " . BB_ATTACHMENTS_DESC;
-
- if (!($result = DB()->sql_query($sql)))
- {
- bb_die('Could not query attachment description table');
- }
-
- $total_rows = DB()->num_rows($result);
- DB()->sql_freeresult($result);
- }
- }
+ $total_rows = DB()->num_rows($result);
+ DB()->sql_freeresult($result);
+ }
+ }
}
// Generate Pagination
-if ($do_pagination && $total_rows > $bb_cfg['topics_per_page'])
-{
- generate_pagination('admin_attach_cp.php?view=' . $view . '&mode=' . $mode . '&order=' . $sort_order . '&uid=' . $uid, $total_rows, $bb_cfg['topics_per_page'], $start).' ';
+if ($do_pagination && $total_rows > config()->get('topics_per_page')) {
+ generate_pagination('admin_attach_cp.php?view=' . $view . '&mode=' . $mode . '&order=' . $sort_order . '&uid=' . $uid, $total_rows, config()->get('topics_per_page'), $start);
}
-print_page('admin_attach_cp.tpl', 'admin');
\ No newline at end of file
+print_page('admin_attach_cp.tpl', 'admin');
diff --git a/admin/admin_attachments.php b/admin/admin_attachments.php
index 3d0d93356..9ee6c129c 100644
--- a/admin/admin_attachments.php
+++ b/admin/admin_attachments.php
@@ -1,149 +1,124 @@
sql_query($sql))
-{
- bb_die('Could not find attachment config table #1');
+if (!$result = DB()->sql_query($sql)) {
+ bb_die('Could not find attachment config table #1');
}
-while ($row = DB()->sql_fetchrow($result))
-{
- $config_name = $row['config_name'];
- $config_value = $row['config_value'];
+while ($row = DB()->sql_fetchrow($result)) {
+ $config_name = $row['config_name'];
+ $config_value = $row['config_value'];
- $new_attach[$config_name] = get_var($config_name, trim($attach_config[$config_name]));
+ $new_attach[$config_name] = get_var($config_name, trim($attach_config[$config_name]));
- if (!$size && !$submit && $config_name == 'max_filesize')
- {
- $size = ($attach_config[$config_name] >= 1048576) ? 'mb' : (($attach_config[$config_name] >= 1024) ? 'kb' : 'b');
- }
+ if (!$size && !$submit && $config_name == 'max_filesize') {
+ $size = ($attach_config[$config_name] >= 1048576) ? 'mb' : (($attach_config[$config_name] >= 1024) ? 'kb' : 'b');
+ }
- if (!$quota_size && !$submit && $config_name == 'attachment_quota')
- {
- $quota_size = ($attach_config[$config_name] >= 1048576) ? 'mb' : (($attach_config[$config_name] >= 1024) ? 'kb' : 'b');
- }
+ if (!$quota_size && !$submit && $config_name == 'attachment_quota') {
+ $quota_size = ($attach_config[$config_name] >= 1048576) ? 'mb' : (($attach_config[$config_name] >= 1024) ? 'kb' : 'b');
+ }
- if (!$pm_size && !$submit && $config_name == 'max_filesize_pm')
- {
- $pm_size = ($attach_config[$config_name] >= 1048576) ? 'mb' : (($attach_config[$config_name] >= 1024) ? 'kb' : 'b');
- }
+ if (!$pm_size && !$submit && $config_name == 'max_filesize_pm') {
+ $pm_size = ($attach_config[$config_name] >= 1048576) ? 'mb' : (($attach_config[$config_name] >= 1024) ? 'kb' : 'b');
+ }
- if (!$submit && ($config_name == 'max_filesize' || $config_name == 'attachment_quota' || $config_name == 'max_filesize_pm'))
- {
- if ($new_attach[$config_name] >= 1048576)
- {
- $new_attach[$config_name] = round($new_attach[$config_name] / 1048576 * 100) / 100;
- }
- else if ($new_attach[$config_name] >= 1024)
- {
- $new_attach[$config_name] = round($new_attach[$config_name] / 1024 * 100) / 100;
- }
- }
+ if (!$submit && ($config_name == 'max_filesize' || $config_name == 'attachment_quota' || $config_name == 'max_filesize_pm')) {
+ if ($new_attach[$config_name] >= 1048576) {
+ $new_attach[$config_name] = round($new_attach[$config_name] / 1048576 * 100) / 100;
+ } elseif ($new_attach[$config_name] >= 1024) {
+ $new_attach[$config_name] = round($new_attach[$config_name] / 1024 * 100) / 100;
+ }
+ }
- if ( $submit && ( $mode == 'manage' || $mode == 'cats') )
- {
- if ($config_name == 'max_filesize')
- {
- $old = $new_attach[$config_name];
- $new_attach[$config_name] = ( $size == 'kb' ) ? round($new_attach[$config_name] * 1024) : ( ($size == 'mb') ? round($new_attach[$config_name] * 1048576) : $new_attach[$config_name] );
- }
+ if ($submit && ($mode == 'manage' || $mode == 'cats')) {
+ if ($config_name == 'max_filesize') {
+ $old = $new_attach[$config_name];
+ $new_attach[$config_name] = ($size == 'kb') ? round($new_attach[$config_name] * 1024) : (($size == 'mb') ? round($new_attach[$config_name] * 1048576) : $new_attach[$config_name]);
+ }
- if ($config_name == 'attachment_quota')
- {
- $old = $new_attach[$config_name];
- $new_attach[$config_name] = ( $quota_size == 'kb' ) ? round($new_attach[$config_name] * 1024) : ( ($quota_size == 'mb') ? round($new_attach[$config_name] * 1048576) : $new_attach[$config_name] );
- }
+ if ($config_name == 'attachment_quota') {
+ $old = $new_attach[$config_name];
+ $new_attach[$config_name] = ($quota_size == 'kb') ? round($new_attach[$config_name] * 1024) : (($quota_size == 'mb') ? round($new_attach[$config_name] * 1048576) : $new_attach[$config_name]);
+ }
- if ($config_name == 'max_filesize_pm')
- {
- $old = $new_attach[$config_name];
- $new_attach[$config_name] = ( $pm_size == 'kb' ) ? round($new_attach[$config_name] * 1024) : ( ($pm_size == 'mb') ? round($new_attach[$config_name] * 1048576) : $new_attach[$config_name] );
- }
+ if ($config_name == 'max_filesize_pm') {
+ $old = $new_attach[$config_name];
+ $new_attach[$config_name] = ($pm_size == 'kb') ? round($new_attach[$config_name] * 1024) : (($pm_size == 'mb') ? round($new_attach[$config_name] * 1048576) : $new_attach[$config_name]);
+ }
- if ($config_name == 'max_filesize')
- {
- $old_size = $attach_config[$config_name];
- $new_size = $new_attach[$config_name];
+ if ($config_name == 'max_filesize') {
+ $old_size = $attach_config[$config_name];
+ $new_size = $new_attach[$config_name];
- if ($old_size != $new_size)
- {
- // See, if we have a similar value of old_size in Mime Groups. If so, update these values.
- $sql = 'UPDATE ' . BB_EXTENSION_GROUPS . '
- SET max_filesize = ' . (int) $new_size . '
- WHERE max_filesize = ' . (int) $old_size;
+ if ($old_size != $new_size) {
+ // See, if we have a similar value of old_size in Mime Groups. If so, update these values.
+ $sql = 'UPDATE ' . BB_EXTENSION_GROUPS . '
+ SET max_filesize = ' . (int)$new_size . '
+ WHERE max_filesize = ' . (int)$old_size;
- if (!($result_2 = DB()->sql_query($sql)))
- {
- bb_die('Could not update extension group information');
- }
+ if (!($result_2 = DB()->sql_query($sql))) {
+ bb_die('Could not update extension group information');
+ }
+ }
- }
+ $sql = 'UPDATE ' . BB_ATTACH_CONFIG . "
+ SET config_value = '" . DB()->escape($new_attach[$config_name]) . "'
+ WHERE config_name = '" . DB()->escape($config_name) . "'";
+ } else {
+ $sql = 'UPDATE ' . BB_ATTACH_CONFIG . "
+ SET config_value = '" . DB()->escape($new_attach[$config_name]) . "'
+ WHERE config_name = '" . DB()->escape($config_name) . "'";
+ }
- $sql = "UPDATE " . BB_ATTACH_CONFIG . "
- SET config_value = '" . attach_mod_sql_escape($new_attach[$config_name]) . "'
- WHERE config_name = '" . attach_mod_sql_escape($config_name) . "'";
- }
- else
- {
- $sql = "UPDATE " . BB_ATTACH_CONFIG . "
- SET config_value = '" . attach_mod_sql_escape($new_attach[$config_name]) . "'
- WHERE config_name = '" . attach_mod_sql_escape($config_name) . "'";
- }
+ if (!DB()->sql_query($sql)) {
+ bb_die('Failed to update attachment configuration for ' . $config_name);
+ }
- if (!DB()->sql_query($sql))
- {
- bb_die('Failed to update attachment configuration for ' . $config_name);
- }
-
- if ($config_name == 'max_filesize' || $config_name == 'attachment_quota' || $config_name == 'max_filesize_pm')
- {
- $new_attach[$config_name] = $old;
- }
- }
+ if ($config_name == 'max_filesize' || $config_name == 'attachment_quota' || $config_name == 'max_filesize_pm') {
+ $new_attach[$config_name] = $old;
+ }
+ }
}
DB()->sql_freeresult($result);
@@ -154,566 +129,424 @@ $select_size_mode = size_select('size', $size);
$select_quota_size_mode = size_select('quota_size', $quota_size);
$select_pm_size_mode = size_select('pm_size', $pm_size);
-// Search Imagick
-if ($search_imagick)
-{
- $imagick = '';
-
- if (preg_match('/convert/i', $imagick))
- {
- return true;
- }
- else if ($imagick != 'none')
- {
- if (!preg_match('/WIN/i', PHP_OS))
- {
- $retval = @exec('whereis convert');
- $paths = explode(' ', $retval);
-
- if (is_array($paths))
- {
- for ( $i=0; $i < sizeof($paths); $i++)
- {
- $path = basename($paths[$i]);
-
- if ($path == 'convert')
- {
- $imagick = $paths[$i];
- }
- }
- }
- }
- else if (preg_match('/WIN/i', PHP_OS))
- {
- $path = 'c:/imagemagick/convert.exe';
-
- if ( !@file_exists(@amod_realpath($path)))
- {
- $imagick = $path;
- }
- }
- }
-
- if ( !@file_exists(@amod_realpath(trim($imagick))))
- {
- $new_attach['img_imagick'] = trim($imagick);
- }
- else
- {
- $new_attach['img_imagick'] = '';
- }
-}
-
// Check Settings
-if ($check_upload)
-{
- // Some tests...
- $attach_config = array();
+if ($check_upload) {
+ // Some tests...
+ $attach_config = [];
- $sql = 'SELECT * FROM ' . BB_ATTACH_CONFIG;
+ $sql = 'SELECT * FROM ' . BB_ATTACH_CONFIG;
- if (!($result = DB()->sql_query($sql)))
- {
- bb_die('Could not find attachment config table #2');
- }
+ if (!($result = DB()->sql_query($sql))) {
+ bb_die('Could not find attachment config table #2');
+ }
- $row = DB()->sql_fetchrowset($result);
- $num_rows = DB()->num_rows($result);
- DB()->sql_freeresult($result);
+ $row = DB()->sql_fetchrowset($result);
+ $num_rows = DB()->num_rows($result);
+ DB()->sql_freeresult($result);
- for ($i = 0; $i < $num_rows; $i++)
- {
- $attach_config[$row[$i]['config_name']] = trim($row[$i]['config_value']);
- }
+ for ($i = 0; $i < $num_rows; $i++) {
+ $attach_config[$row[$i]['config_name']] = trim($row[$i]['config_value']);
+ }
- if ($attach_config['upload_dir'][0] == '/' || ($attach_config['upload_dir'][0] != '/' && $attach_config['upload_dir'][1] == ':'))
- {
- $upload_dir = $attach_config['upload_dir'];
- }
- else
- {
- $upload_dir = BB_ROOT . $attach_config['upload_dir'];
- }
+ if ($attach_config['upload_dir'][0] == '/' || ($attach_config['upload_dir'][0] != '/' && $attach_config['upload_dir'][1] == ':')) {
+ $upload_dir = $attach_config['upload_dir'];
+ } else {
+ $upload_dir = BB_ROOT . $attach_config['upload_dir'];
+ }
- $error = false;
+ $error = false;
- // Does the target directory exist, is it a directory and writeable
- if ( !@file_exists(@amod_realpath($upload_dir)) )
- {
- $error = true;
- $error_msg = sprintf($lang['DIRECTORY_DOES_NOT_EXIST'], $attach_config['upload_dir']) . ' ';
- }
+ // Does the target directory exist, is it a directory and writeable
+ if (!@file_exists(realpath($upload_dir))) {
+ $error = true;
+ $error_msg = sprintf($lang['DIRECTORY_DOES_NOT_EXIST'], $attach_config['upload_dir']) . ' ';
+ }
- if (!$error && !is_dir($upload_dir))
- {
- $error = TRUE;
- $error_msg = sprintf($lang['DIRECTORY_IS_NOT_A_DIR'], $attach_config['upload_dir']) . ' ';
- }
+ if (!$error && !is_dir($upload_dir)) {
+ $error = true;
+ $error_msg = sprintf($lang['DIRECTORY_IS_NOT_A_DIR'], $attach_config['upload_dir']) . ' ';
+ }
- if (!$error)
- {
- if ( !($fp = @fopen($upload_dir . '/0_000000.000', 'w')) )
- {
- $error = TRUE;
- $error_msg = sprintf($lang['DIRECTORY_NOT_WRITEABLE'], $attach_config['upload_dir']) . ' ';
- }
- else
- {
- @fclose($fp);
- unlink_attach($upload_dir . '/0_000000.000');
- }
- }
+ if (!$error) {
+ if (!($fp = @fopen($upload_dir . '/0_000000.000', 'wb+'))) {
+ $error = true;
+ $error_msg = sprintf($lang['DIRECTORY_NOT_WRITEABLE'], $attach_config['upload_dir']) . ' ';
+ } else {
+ @fclose($fp);
+ unlink_attach($upload_dir . '/0_000000.000');
+ }
+ }
- if (!$error)
- {
- bb_die($lang['TEST_SETTINGS_SUCCESSFUL'] . ' ' . sprintf($lang['CLICK_RETURN_ATTACH_CONFIG'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '));
- }
+ if (!$error) {
+ bb_die($lang['TEST_SETTINGS_SUCCESSFUL'] . ' ' . sprintf($lang['CLICK_RETURN_ATTACH_CONFIG'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '));
+ }
}
// Management
-if ($submit && $mode == 'manage')
-{
- if (!$error)
- {
- bb_die($lang['ATTACH_CONFIG_UPDATED'] . ' ' . sprintf($lang['CLICK_RETURN_ATTACH_CONFIG'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '));
- }
+if ($submit && $mode == 'manage') {
+ if (!$error) {
+ bb_die($lang['ATTACH_CONFIG_UPDATED'] . ' ' . sprintf($lang['CLICK_RETURN_ATTACH_CONFIG'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '));
+ }
}
-if ($mode == 'manage')
-{
- $yes_no_switches = array('disable_mod', 'allow_pm_attach', 'display_order');
+if ($mode == 'manage') {
+ $template->assign_vars(array(
+ 'TPL_ATTACH_MANAGE' => true,
+ 'S_ATTACH_ACTION' => 'admin_attachments.php?mode=manage',
+ 'S_FILESIZE' => $select_size_mode,
+ 'S_FILESIZE_QUOTA' => $select_quota_size_mode,
+ 'S_FILESIZE_PM' => $select_pm_size_mode,
+ 'S_DEFAULT_UPLOAD_LIMIT' => default_quota_limit_select('default_upload_quota', (int)trim($new_attach['default_upload_quota'])),
+ 'S_DEFAULT_PM_LIMIT' => default_quota_limit_select('default_pm_quota', (int)trim($new_attach['default_pm_quota'])),
- for ($i = 0; $i < sizeof($yes_no_switches); $i++)
- {
- eval("\$" . $yes_no_switches[$i] . "_yes = ( \$new_attach['" . $yes_no_switches[$i] . "'] != '0' ) ? 'checked=\"checked\"' : '';");
- eval("\$" . $yes_no_switches[$i] . "_no = ( \$new_attach['" . $yes_no_switches[$i] . "'] == '0' ) ? 'checked=\"checked\"' : '';");
- }
-
- $template->assign_vars(array(
- 'TPL_ATTACH_MANAGE' => true,
- 'S_ATTACH_ACTION' => 'admin_attachments.php?mode=manage',
- 'S_FILESIZE' => $select_size_mode,
- 'S_FILESIZE_QUOTA' => $select_quota_size_mode,
- 'S_FILESIZE_PM' => $select_pm_size_mode,
- 'S_DEFAULT_UPLOAD_LIMIT' => default_quota_limit_select('default_upload_quota', intval(trim($new_attach['default_upload_quota']))),
- 'S_DEFAULT_PM_LIMIT' => default_quota_limit_select('default_pm_quota', intval(trim($new_attach['default_pm_quota']))),
-
- 'UPLOAD_DIR' => $new_attach['upload_dir'],
- 'ATTACHMENT_IMG_PATH' => $new_attach['upload_img'],
- 'TOPIC_ICON' => $new_attach['topic_icon'],
- 'MAX_FILESIZE' => $new_attach['max_filesize'],
- 'ATTACHMENT_QUOTA' => $new_attach['attachment_quota'],
- 'MAX_FILESIZE_PM' => $new_attach['max_filesize_pm'],
- 'MAX_ATTACHMENTS' => $new_attach['max_attachments'],
- 'MAX_ATTACHMENTS_PM' => $new_attach['max_attachments_pm'],
- 'DISABLE_MOD_YES' => $disable_mod_yes,
- 'DISABLE_MOD_NO' => $disable_mod_no,
- 'PM_ATTACH_YES' => $allow_pm_attach_yes,
- 'PM_ATTACH_NO' => $allow_pm_attach_no,
- 'DISPLAY_ORDER_ASC' => $display_order_yes,
- 'DISPLAY_ORDER_DESC' => $display_order_no,
- ));
+ 'UPLOAD_DIR' => $new_attach['upload_dir'],
+ 'ATTACHMENT_IMG_PATH' => $new_attach['upload_img'],
+ 'TOPIC_ICON' => $new_attach['topic_icon'],
+ 'MAX_FILESIZE' => $new_attach['max_filesize'],
+ 'ATTACHMENT_QUOTA' => $new_attach['attachment_quota'],
+ 'MAX_FILESIZE_PM' => $new_attach['max_filesize_pm'],
+ 'MAX_ATTACHMENTS' => $new_attach['max_attachments'],
+ 'MAX_ATTACHMENTS_PM' => $new_attach['max_attachments_pm'],
+ 'DISABLE_MOD_YES' => $new_attach['disable_mod'] !== '0' ? 'checked' : '',
+ 'DISABLE_MOD_NO' => $new_attach['disable_mod'] === '0' ? 'checked' : '',
+ 'PM_ATTACH_YES' => $new_attach['allow_pm_attach'] !== '0' ? 'checked' : '',
+ 'PM_ATTACH_NO' => $new_attach['allow_pm_attach'] === '0' ? 'checked' : '',
+ 'DISPLAY_ORDER_ASC' => $new_attach['display_order'] !== '0' ? 'checked' : '',
+ 'DISPLAY_ORDER_DESC' => $new_attach['display_order'] === '0' ? 'checked' : '',
+ ));
}
-if ($submit && $mode == 'cats')
-{
- if (!$error)
- {
- bb_die($lang['ATTACH_CONFIG_UPDATED'] . ' ' . sprintf($lang['CLICK_RETURN_ATTACH_CONFIG'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '));
- }
+if ($submit && $mode == 'cats') {
+ if (!$error) {
+ bb_die($lang['ATTACH_CONFIG_UPDATED'] . ' ' . sprintf($lang['CLICK_RETURN_ATTACH_CONFIG'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '));
+ }
}
-if ($mode == 'cats')
-{
- $s_assigned_group_images = $lang['NONE'];
+if ($mode == 'cats') {
+ $s_assigned_group_images = $lang['NONE'];
- $sql = 'SELECT group_name, cat_id FROM ' . BB_EXTENSION_GROUPS . ' WHERE cat_id > 0 ORDER BY cat_id';
+ $sql = 'SELECT group_name, cat_id FROM ' . BB_EXTENSION_GROUPS . ' WHERE cat_id > 0 ORDER BY cat_id';
- $s_assigned_group_images = array();
+ $s_assigned_group_images = [];
- if (!($result = DB()->sql_query($sql)))
- {
- bb_die('Could not get group names from ' . BB_EXTENSION_GROUPS);
- }
+ if (!($result = DB()->sql_query($sql))) {
+ bb_die('Could not get group names from ' . BB_EXTENSION_GROUPS);
+ }
- $row = DB()->sql_fetchrowset($result);
- DB()->sql_freeresult($result);
+ $row = DB()->sql_fetchrowset($result);
+ DB()->sql_freeresult($result);
- for ($i = 0; $i < sizeof($row); $i++)
- {
- if ($row[$i]['cat_id'] == IMAGE_CAT)
- {
- $s_assigned_group_images[] = $row[$i]['group_name'];
- }
- }
+ for ($i = 0, $iMax = count($row); $i < $iMax; $i++) {
+ if ($row[$i]['cat_id'] == IMAGE_CAT) {
+ $s_assigned_group_images[] = $row[$i]['group_name'];
+ }
+ }
- $display_inlined_yes = ( $new_attach['img_display_inlined'] != '0' ) ? 'checked="checked"' : '';
- $display_inlined_no = ( $new_attach['img_display_inlined'] == '0' ) ? 'checked="checked"' : '';
+ $display_inlined_yes = ($new_attach['img_display_inlined'] != '0') ? 'checked' : '';
+ $display_inlined_no = ($new_attach['img_display_inlined'] == '0') ? 'checked' : '';
- $create_thumbnail_yes = ( $new_attach['img_create_thumbnail'] != '0' ) ? 'checked="checked"' : '';
- $create_thumbnail_no = ( $new_attach['img_create_thumbnail'] == '0' ) ? 'checked="checked"' : '';
+ $create_thumbnail_yes = ($new_attach['img_create_thumbnail'] != '0') ? 'checked' : '';
+ $create_thumbnail_no = ($new_attach['img_create_thumbnail'] == '0') ? 'checked' : '';
- $use_gd2_yes = ( $new_attach['use_gd2'] != '0' ) ? 'checked="checked"' : '';
- $use_gd2_no = ( $new_attach['use_gd2'] == '0' ) ? 'checked="checked"' : '';
+ // Check Thumbnail Support
+ if (!extension_loaded('gd')) {
+ $new_attach['img_create_thumbnail'] = '0';
+ } else {
+ $template->assign_block_vars('switch_thumbnail_support', []);
+ }
- // Check Thumbnail Support
- if (!is_imagick() && !@extension_loaded('gd'))
- {
- $new_attach['img_create_thumbnail'] = '0';
- }
- else
- {
- $template->assign_block_vars('switch_thumbnail_support', array());
- }
-
- $template->assign_vars(array(
- 'TPL_ATTACH_SPECIAL_CATEGORIES' => true,
- 'IMAGE_MAX_HEIGHT' => $new_attach['img_max_height'],
- 'IMAGE_MAX_WIDTH' => $new_attach['img_max_width'],
- 'IMAGE_LINK_HEIGHT' => $new_attach['img_link_height'],
- 'IMAGE_LINK_WIDTH' => $new_attach['img_link_width'],
- 'IMAGE_MIN_THUMB_FILESIZE' => $new_attach['img_min_thumb_filesize'],
- 'IMAGE_IMAGICK_PATH' => $new_attach['img_imagick'],
- 'DISPLAY_INLINED_YES' => $display_inlined_yes,
- 'DISPLAY_INLINED_NO' => $display_inlined_no,
- 'CREATE_THUMBNAIL_YES' => $create_thumbnail_yes,
- 'CREATE_THUMBNAIL_NO' => $create_thumbnail_no,
- 'USE_GD2_YES' => $use_gd2_yes,
- 'USE_GD2_NO' => $use_gd2_no,
- 'S_ASSIGNED_GROUP_IMAGES' => implode(', ', $s_assigned_group_images),
- 'S_ATTACH_ACTION' => 'admin_attachments.php?mode=cats',
- ));
+ $template->assign_vars(array(
+ 'TPL_ATTACH_SPECIAL_CATEGORIES' => true,
+ 'IMAGE_MAX_HEIGHT' => $new_attach['img_max_height'],
+ 'IMAGE_MAX_WIDTH' => $new_attach['img_max_width'],
+ 'IMAGE_LINK_HEIGHT' => $new_attach['img_link_height'],
+ 'IMAGE_LINK_WIDTH' => $new_attach['img_link_width'],
+ 'IMAGE_MIN_THUMB_FILESIZE' => $new_attach['img_min_thumb_filesize'],
+ 'DISPLAY_INLINED_YES' => $display_inlined_yes,
+ 'DISPLAY_INLINED_NO' => $display_inlined_no,
+ 'CREATE_THUMBNAIL_YES' => $create_thumbnail_yes,
+ 'CREATE_THUMBNAIL_NO' => $create_thumbnail_no,
+ 'S_ASSIGNED_GROUP_IMAGES' => implode(', ', $s_assigned_group_images),
+ 'S_ATTACH_ACTION' => 'admin_attachments.php?mode=cats',
+ ));
}
// Check Cat Settings
-if ($check_image_cat)
-{
- // Some tests...
- $attach_config = array();
+if ($check_image_cat) {
+ // Some tests...
+ $attach_config = [];
- $sql = 'SELECT * FROM ' . BB_ATTACH_CONFIG;
+ $sql = 'SELECT * FROM ' . BB_ATTACH_CONFIG;
- if (!($result = DB()->sql_query($sql)))
- {
- bb_die('Could not find attachment config table #3');
- }
+ if (!($result = DB()->sql_query($sql))) {
+ bb_die('Could not find attachment config table #3');
+ }
- $row = DB()->sql_fetchrowset($result);
- $num_rows = DB()->num_rows($result);
- DB()->sql_freeresult($result);
+ $row = DB()->sql_fetchrowset($result);
+ $num_rows = DB()->num_rows($result);
+ DB()->sql_freeresult($result);
- for ($i = 0; $i < $num_rows; $i++)
- {
- $attach_config[$row[$i]['config_name']] = trim($row[$i]['config_value']);
- }
+ for ($i = 0; $i < $num_rows; $i++) {
+ $attach_config[$row[$i]['config_name']] = trim($row[$i]['config_value']);
+ }
- if ($attach_config['upload_dir'][0] == '/' || ($attach_config['upload_dir'][0] != '/' && $attach_config['upload_dir'][1] == ':'))
- {
- $upload_dir = $attach_config['upload_dir'];
- }
- else
- {
- $upload_dir = BB_ROOT . $attach_config['upload_dir'];
- }
+ if ($attach_config['upload_dir'][0] == '/' || ($attach_config['upload_dir'][0] != '/' && $attach_config['upload_dir'][1] == ':')) {
+ $upload_dir = $attach_config['upload_dir'];
+ } else {
+ $upload_dir = BB_ROOT . $attach_config['upload_dir'];
+ }
- $upload_dir = $upload_dir . '/' . THUMB_DIR;
+ $upload_dir = $upload_dir . '/' . THUMB_DIR;
- $error = false;
+ $error = false;
- // Does the target directory exist, is it a directory and writeable
- if ( !@file_exists(@amod_realpath($upload_dir)) )
- {
- @mkdir($upload_dir, 0755);
- @chmod($upload_dir, 0777);
+ // Does the target directory exist, is it a directory and writeable
+ if (!@file_exists(realpath($upload_dir))) {
+ if (!bb_mkdir($upload_dir) && !is_dir($upload_dir)) {
+ throw new \RuntimeException(sprintf('Directory "%s" was not created', $upload_dir));
+ }
- if ( !@file_exists(@amod_realpath($upload_dir)) )
- {
- $error = TRUE;
- $error_msg = sprintf($lang['DIRECTORY_DOES_NOT_EXIST'], $upload_dir) . ' ';
- }
- }
+ if (!@file_exists(realpath($upload_dir))) {
+ $error = true;
+ $error_msg = sprintf($lang['DIRECTORY_DOES_NOT_EXIST'], $upload_dir) . ' ';
+ }
+ }
- if (!$error && !is_dir($upload_dir))
- {
- $error = TRUE;
- $error_msg = sprintf($lang['DIRECTORY_IS_NOT_A_DIR'], $upload_dir) . ' ';
- }
+ if (!$error && !is_dir($upload_dir)) {
+ $error = true;
+ $error_msg = sprintf($lang['DIRECTORY_IS_NOT_A_DIR'], $upload_dir) . ' ';
+ }
- if (!$error)
- {
- if ( !($fp = @fopen($upload_dir . '/0_000000.000', 'w')) )
- {
- $error = TRUE;
- $error_msg = sprintf($lang['DIRECTORY_NOT_WRITEABLE'], $upload_dir) . ' ';
- }
- else
- {
- @fclose($fp);
- @unlink($upload_dir . '/0_000000.000');
- }
- }
+ if (!$error) {
+ if (!($fp = @fopen($upload_dir . '/0_000000.000', 'wb+'))) {
+ $error = true;
+ $error_msg = sprintf($lang['DIRECTORY_NOT_WRITEABLE'], $upload_dir) . ' ';
+ } else {
+ @fclose($fp);
+ @unlink($upload_dir . '/0_000000.000');
+ }
+ }
- if (!$error)
- {
- bb_die($lang['TEST_SETTINGS_SUCCESSFUL'] . ' ' . sprintf($lang['CLICK_RETURN_ATTACH_CONFIG'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '));
- }
+ if (!$error) {
+ bb_die($lang['TEST_SETTINGS_SUCCESSFUL'] . ' ' . sprintf($lang['CLICK_RETURN_ATTACH_CONFIG'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '));
+ }
}
// Quota Limit Settings
-if ($submit && $mode == 'quota')
-{
- // Change Quota Limit
- $quota_change_list = get_var('quota_change_list', array(0));
- $quota_desc_list = get_var('quota_desc_list', array(''));
- $filesize_list = get_var('max_filesize_list', array(0));
- $size_select_list = get_var('size_select_list', array(''));
+if ($submit && $mode == 'quota') {
+ // Change Quota Limit
+ $quota_change_list = get_var('quota_change_list', array(0));
+ $quota_desc_list = get_var('quota_desc_list', array(''));
+ $filesize_list = get_var('max_filesize_list', array(0));
+ $size_select_list = get_var('size_select_list', array(''));
- $allowed_list = array();
+ $allowed_list = [];
- for ($i = 0; $i < sizeof($quota_change_list); $i++)
- {
- $filesize_list[$i] = ( $size_select_list[$i] == 'kb' ) ? round($filesize_list[$i] * 1024) : ( ($size_select_list[$i] == 'mb') ? round($filesize_list[$i] * 1048576) : $filesize_list[$i] );
+ for ($i = 0, $iMax = count($quota_change_list); $i < $iMax; $i++) {
+ $filesize_list[$i] = ($size_select_list[$i] == 'kb') ? round($filesize_list[$i] * 1024) : (($size_select_list[$i] == 'mb') ? round($filesize_list[$i] * 1048576) : $filesize_list[$i]);
- $sql = 'UPDATE ' . BB_QUOTA_LIMITS . "
- SET quota_desc = '" . attach_mod_sql_escape($quota_desc_list[$i]) . "', quota_limit = " . (int) $filesize_list[$i] . "
- WHERE quota_limit_id = " . (int) $quota_change_list[$i];
+ $sql = 'UPDATE ' . BB_QUOTA_LIMITS . "
+ SET quota_desc = '" . DB()->escape($quota_desc_list[$i]) . "', quota_limit = " . (int)$filesize_list[$i] . '
+ WHERE quota_limit_id = ' . (int)$quota_change_list[$i];
- if (!(DB()->sql_query($sql)))
- {
- bb_die('Could not update quota limits');
- }
- }
+ if (!DB()->sql_query($sql)) {
+ bb_die('Could not update quota limits');
+ }
+ }
- // Delete Quota Limits
- $quota_id_list = get_var('quota_id_list', array(0));
+ // Delete Quota Limits
+ $quota_id_list = get_var('quota_id_list', array(0));
- $quota_id_sql = implode(', ', $quota_id_list);
+ $quota_id_sql = implode(', ', $quota_id_list);
- if ($quota_id_sql != '')
- {
- $sql = 'DELETE FROM ' . BB_QUOTA_LIMITS . ' WHERE quota_limit_id IN (' . $quota_id_sql . ')';
+ if ($quota_id_sql != '') {
+ $sql = 'DELETE FROM ' . BB_QUOTA_LIMITS . ' WHERE quota_limit_id IN (' . $quota_id_sql . ')';
- if (!($result = DB()->sql_query($sql)))
- {
- bb_die('Could not delete quota limits');
- }
+ if (!($result = DB()->sql_query($sql))) {
+ bb_die('Could not delete quota limits');
+ }
- // Delete Quotas linked to this setting
- $sql = 'DELETE FROM ' . BB_QUOTA . ' WHERE quota_limit_id IN (' . $quota_id_sql . ')';
+ // Delete Quotas linked to this setting
+ $sql = 'DELETE FROM ' . BB_QUOTA . ' WHERE quota_limit_id IN (' . $quota_id_sql . ')';
- if (!($result = DB()->sql_query($sql)))
- {
- bb_die('Could not delete quotas');
- }
- }
+ if (!($result = DB()->sql_query($sql))) {
+ bb_die('Could not delete quotas');
+ }
+ }
- // Add Quota Limit ?
- $quota_desc = get_var('quota_description', '');
- $filesize = get_var('add_max_filesize', 0);
- $size_select = get_var('add_size_select', '');
- $add = ( isset($_POST['add_quota_check']) ) ? TRUE : FALSE;
+ // Add Quota Limit ?
+ $quota_desc = get_var('quota_description', '');
+ $filesize = get_var('add_max_filesize', 0);
+ $size_select = get_var('add_size_select', '');
+ $add = isset($_POST['add_quota_check']);
- if ($quota_desc != '' && $add)
- {
- // check Quota Description
- $sql = 'SELECT quota_desc FROM ' . BB_QUOTA_LIMITS;
+ if ($quota_desc != '' && $add) {
+ // check Quota Description
+ $sql = 'SELECT quota_desc FROM ' . BB_QUOTA_LIMITS;
- if (!($result = DB()->sql_query($sql)))
- {
- bb_die('Could not query quota limits table');
- }
+ if (!($result = DB()->sql_query($sql))) {
+ bb_die('Could not query quota limits table');
+ }
- $row = DB()->sql_fetchrowset($result);
- $num_rows = DB()->num_rows($result);
- DB()->sql_freeresult($result);
+ $row = DB()->sql_fetchrowset($result);
+ $num_rows = DB()->num_rows($result);
+ DB()->sql_freeresult($result);
- if ( $num_rows > 0 )
- {
- for ($i = 0; $i < $num_rows; $i++)
- {
- if ($row[$i]['quota_desc'] == $quota_desc)
- {
- $error = TRUE;
- if( isset($error_msg) )
- {
- $error_msg .= ' ';
- }
- $error_msg .= sprintf($lang['QUOTA_LIMIT_EXIST'], $extension_group);
- }
- }
- }
+ if ($num_rows > 0) {
+ for ($i = 0; $i < $num_rows; $i++) {
+ if ($row[$i]['quota_desc'] == $quota_desc) {
+ $error = true;
+ if (isset($error_msg)) {
+ $error_msg .= ' ';
+ }
+ $error_msg .= sprintf($lang['QUOTA_LIMIT_EXIST'], $extension_group);
+ }
+ }
+ }
- if (!$error)
- {
- $filesize = ( $size_select == 'kb' ) ? round($filesize * 1024) : ( ($size_select == 'mb') ? round($filesize * 1048576) : $filesize );
+ if (!$error) {
+ $filesize = ($size_select == 'kb') ? round($filesize * 1024) : (($size_select == 'mb') ? round($filesize * 1048576) : $filesize);
- $sql = "INSERT INTO " . BB_QUOTA_LIMITS . " (quota_desc, quota_limit)
- VALUES ('" . attach_mod_sql_escape($quota_desc) . "', " . (int) $filesize . ")";
+ $sql = 'INSERT INTO ' . BB_QUOTA_LIMITS . " (quota_desc, quota_limit)
+ VALUES ('" . DB()->escape($quota_desc) . "', " . (int)$filesize . ')';
- if (!(DB()->sql_query($sql)))
- {
- bb_die('Could not add quota limit');
- }
- }
-
- }
-
- if (!$error)
- {
- bb_die($lang['ATTACH_CONFIG_UPDATED'] . ' ' . sprintf($lang['CLICK_RETURN_ATTACH_CONFIG'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '));
- }
+ if (!DB()->sql_query($sql)) {
+ bb_die('Could not add quota limit');
+ }
+ }
+ }
+ if (!$error) {
+ bb_die($lang['ATTACH_CONFIG_UPDATED'] . ' ' . sprintf($lang['CLICK_RETURN_ATTACH_CONFIG'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '));
+ }
}
-if ($mode == 'quota')
-{
- $max_add_filesize = $attach_config['max_filesize'];
- $size = ($max_add_filesize >= 1048576) ? 'mb' : ( ($max_add_filesize >= 1024) ? 'kb' : 'b' );
+if ($mode == 'quota') {
+ $max_add_filesize = $attach_config['max_filesize'];
+ $size = ($max_add_filesize >= 1048576) ? 'mb' : (($max_add_filesize >= 1024) ? 'kb' : 'b');
- if ($max_add_filesize >= 1048576)
- {
- $max_add_filesize = round($max_add_filesize / 1048576 * 100) / 100;
- }
- else if ( $max_add_filesize >= 1024)
- {
- $max_add_filesize = round($max_add_filesize / 1024 * 100) / 100;
- }
+ if ($max_add_filesize >= 1048576) {
+ $max_add_filesize = round($max_add_filesize / 1048576 * 100) / 100;
+ } elseif ($max_add_filesize >= 1024) {
+ $max_add_filesize = round($max_add_filesize / 1024 * 100) / 100;
+ }
- $template->assign_vars(array(
- 'TPL_ATTACH_QUOTA' => true,
- 'MAX_FILESIZE' => $max_add_filesize,
- 'S_FILESIZE' => size_select('add_size_select', $size),
- 'S_ATTACH_ACTION' => 'admin_attachments.php?mode=quota',
- ));
+ $template->assign_vars(array(
+ 'TPL_ATTACH_QUOTA' => true,
+ 'MAX_FILESIZE' => $max_add_filesize,
+ 'S_FILESIZE' => size_select('add_size_select', $size),
+ 'S_ATTACH_ACTION' => 'admin_attachments.php?mode=quota',
+ ));
- $sql = "SELECT * FROM " . BB_QUOTA_LIMITS . " ORDER BY quota_limit DESC";
+ $sql = 'SELECT * FROM ' . BB_QUOTA_LIMITS . ' ORDER BY quota_limit DESC';
- if (!($result = DB()->sql_query($sql)))
- {
- bb_die('Could not get quota limits #1');
- }
+ if (!($result = DB()->sql_query($sql))) {
+ bb_die('Could not get quota limits #1');
+ }
- $rows = DB()->sql_fetchrowset($result);
- DB()->sql_freeresult($result);
+ $rows = DB()->sql_fetchrowset($result);
+ DB()->sql_freeresult($result);
- for ($i = 0; $i < sizeof($rows); $i++)
- {
- $size_format = ($rows[$i]['quota_limit'] >= 1048576) ? 'mb' : ( ($rows[$i]['quota_limit'] >= 1024) ? 'kb' : 'b' );
+ for ($i = 0, $iMax = count($rows); $i < $iMax; $i++) {
+ $size_format = ($rows[$i]['quota_limit'] >= 1048576) ? 'mb' : (($rows[$i]['quota_limit'] >= 1024) ? 'kb' : 'b');
- if ( $rows[$i]['quota_limit'] >= 1048576)
- {
- $rows[$i]['quota_limit'] = round($rows[$i]['quota_limit'] / 1048576 * 100) / 100;
- }
- else if($rows[$i]['quota_limit'] >= 1024)
- {
- $rows[$i]['quota_limit'] = round($rows[$i]['quota_limit'] / 1024 * 100) / 100;
- }
+ if ($rows[$i]['quota_limit'] >= 1048576) {
+ $rows[$i]['quota_limit'] = round($rows[$i]['quota_limit'] / 1048576 * 100) / 100;
+ } elseif ($rows[$i]['quota_limit'] >= 1024) {
+ $rows[$i]['quota_limit'] = round($rows[$i]['quota_limit'] / 1024 * 100) / 100;
+ }
- $template->assign_block_vars('limit_row', array(
- 'QUOTA_NAME' => $rows[$i]['quota_desc'],
- 'QUOTA_ID' => $rows[$i]['quota_limit_id'],
- 'S_FILESIZE' => size_select('size_select_list[]', $size_format),
- 'U_VIEW' => "admin_attachments.php?mode=$mode&e_mode=view_quota"a_id=" . $rows[$i]['quota_limit_id'],
- 'MAX_FILESIZE' => $rows[$i]['quota_limit'],
- ));
- }
+ $template->assign_block_vars('limit_row', array(
+ 'QUOTA_NAME' => $rows[$i]['quota_desc'],
+ 'QUOTA_ID' => $rows[$i]['quota_limit_id'],
+ 'S_FILESIZE' => size_select('size_select_list[]', $size_format),
+ 'U_VIEW' => "admin_attachments.php?mode=$mode&e_mode=view_quota"a_id=" . $rows[$i]['quota_limit_id'],
+ 'MAX_FILESIZE' => $rows[$i]['quota_limit'],
+ ));
+ }
}
-if ($mode == 'quota' && $e_mode == 'view_quota')
-{
- $quota_id = get_var('quota_id', 0);
+if ($mode == 'quota' && $e_mode == 'view_quota') {
+ $quota_id = get_var('quota_id', 0);
- if (!$quota_id)
- {
- bb_die('Invalid call');
- }
+ if (!$quota_id) {
+ bb_die('Invalid call');
+ }
- $template->assign_block_vars('switch_quota_limit_desc', array());
+ $template->assign_block_vars('switch_quota_limit_desc', []);
- $sql = "SELECT * FROM " . BB_QUOTA_LIMITS . " WHERE quota_limit_id = " . (int) $quota_id . " LIMIT 1";
+ $sql = 'SELECT * FROM ' . BB_QUOTA_LIMITS . ' WHERE quota_limit_id = ' . (int)$quota_id . ' LIMIT 1';
- if (!($result = DB()->sql_query($sql)))
- {
- bb_die('Could not get quota limits #2');
- }
+ if (!($result = DB()->sql_query($sql))) {
+ bb_die('Could not get quota limits #2');
+ }
- $row = DB()->sql_fetchrow($result);
- DB()->sql_freeresult($result);
+ $row = DB()->sql_fetchrow($result);
+ DB()->sql_freeresult($result);
- $template->assign_vars(array(
- 'L_QUOTA_LIMIT_DESC' => $row['quota_desc'],
- ));
+ $template->assign_vars(array(
+ 'L_QUOTA_LIMIT_DESC' => $row['quota_desc'],
+ ));
- $sql = 'SELECT q.user_id, u.username, q.quota_type
+ $sql = 'SELECT q.user_id, u.username, q.quota_type
FROM ' . BB_QUOTA . ' q, ' . BB_USERS . ' u
- WHERE q.quota_limit_id = ' . (int) $quota_id . '
+ WHERE q.quota_limit_id = ' . (int)$quota_id . '
AND q.user_id <> 0
AND q.user_id = u.user_id';
- if (!($result = DB()->sql_query($sql)))
- {
- bb_die('Could not get quota limits #3');
- }
+ if (!($result = DB()->sql_query($sql))) {
+ bb_die('Could not get quota limits #3');
+ }
- $rows = DB()->sql_fetchrowset($result);
- $num_rows = DB()->num_rows($result);
- DB()->sql_freeresult($result);
+ $rows = DB()->sql_fetchrowset($result);
+ $num_rows = DB()->num_rows($result);
+ DB()->sql_freeresult($result);
- for ($i = 0; $i < $num_rows; $i++)
- {
- if ($rows[$i]['quota_type'] == QUOTA_UPLOAD_LIMIT)
- {
- $template->assign_block_vars('users_upload_row', array(
- 'USER_ID' => $rows[$i]['user_id'],
- 'USERNAME' => $rows[$i]['username'],
- ));
- }
- else if ($rows[$i]['quota_type'] == QUOTA_PM_LIMIT)
- {
- $template->assign_block_vars('users_pm_row', array(
- 'USER_ID' => $rows[$i]['user_id'],
- 'USERNAME' => $rows[$i]['username'],
- ));
- }
- }
+ for ($i = 0; $i < $num_rows; $i++) {
+ if ($rows[$i]['quota_type'] == QUOTA_UPLOAD_LIMIT) {
+ $template->assign_block_vars('users_upload_row', array(
+ 'USER_ID' => $rows[$i]['user_id'],
+ 'USERNAME' => $rows[$i]['username'],
+ ));
+ } elseif ($rows[$i]['quota_type'] == QUOTA_PM_LIMIT) {
+ $template->assign_block_vars('users_pm_row', array(
+ 'USER_ID' => $rows[$i]['user_id'],
+ 'USERNAME' => $rows[$i]['username'],
+ ));
+ }
+ }
- $sql = 'SELECT q.group_id, g.group_name, q.quota_type
+ $sql = 'SELECT q.group_id, g.group_name, q.quota_type
FROM ' . BB_QUOTA . ' q, ' . BB_GROUPS . ' g
- WHERE q.quota_limit_id = ' . (int) $quota_id . '
+ WHERE q.quota_limit_id = ' . (int)$quota_id . '
AND q.group_id <> 0
AND q.group_id = g.group_id';
- if (!($result = DB()->sql_query($sql)))
- {
- bb_die('Could not get quota limits #4');
- }
+ if (!($result = DB()->sql_query($sql))) {
+ bb_die('Could not get quota limits #4');
+ }
- $rows = DB()->sql_fetchrowset($result);
- $num_rows = DB()->num_rows($result);
- DB()->sql_freeresult($result);
+ $rows = DB()->sql_fetchrowset($result);
+ $num_rows = DB()->num_rows($result);
+ DB()->sql_freeresult($result);
- for ($i = 0; $i < $num_rows; $i++)
- {
- if ($rows[$i]['quota_type'] == QUOTA_UPLOAD_LIMIT)
- {
- $template->assign_block_vars('groups_upload_row', array(
- 'GROUP_ID' => $rows[$i]['group_id'],
- 'GROUPNAME' => $rows[$i]['group_name'],
- ));
- }
- else if ($rows[$i]['quota_type'] == QUOTA_PM_LIMIT)
- {
- $template->assign_block_vars('groups_pm_row', array(
- 'GROUP_ID' => $rows[$i]['group_id'],
- 'GROUPNAME' => $rows[$i]['group_name'],
- ));
- }
- }
+ for ($i = 0; $i < $num_rows; $i++) {
+ if ($rows[$i]['quota_type'] == QUOTA_UPLOAD_LIMIT) {
+ $template->assign_block_vars('groups_upload_row', array(
+ 'GROUP_ID' => $rows[$i]['group_id'],
+ 'GROUPNAME' => $rows[$i]['group_name'],
+ ));
+ } elseif ($rows[$i]['quota_type'] == QUOTA_PM_LIMIT) {
+ $template->assign_block_vars('groups_pm_row', array(
+ 'GROUP_ID' => $rows[$i]['group_id'],
+ 'GROUPNAME' => $rows[$i]['group_name'],
+ ));
+ }
+ }
}
-if ($error)
-{
- $template->assign_vars(array('ERROR_MESSAGE' => $error_msg));
+if ($error) {
+ $template->assign_vars(array('ERROR_MESSAGE' => $error_msg));
}
-print_page('admin_attachments.tpl', 'admin');
\ No newline at end of file
+print_page('admin_attachments.tpl', 'admin');
diff --git a/admin/admin_board.php b/admin/admin_board.php
index a709f7a34..191666675 100644
--- a/admin/admin_board.php
+++ b/admin/admin_board.php
@@ -1,149 +1,154 @@
' '. sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '),
- 'config' => ' '. sprintf($lang['CLICK_RETURN_CONFIG'], '', ' '),
- 'config_mods' => ' '. sprintf($lang['CLICK_RETURN_CONFIG_MODS'], '', ' ')
-);
-
-//
-// Pull all config data
-//
-$sql = "SELECT * FROM " . BB_CONFIG;
-if (!$result = DB()->sql_query($sql))
-{
- bb_die('Could not query config information in admin_board');
-}
-else
-{
- while ($row = DB()->sql_fetchrow($result))
- {
- $config_name = $row['config_name'];
- $config_value = $row['config_value'];
- $default_config[$config_name] = $config_value;
-
- $new[$config_name] = isset($_POST[$config_name]) ? $_POST[$config_name] : $default_config[$config_name];
-
- if (isset($_POST['submit']) && $row['config_value'] != $new[$config_name])
- {
- if ($config_name == 'seed_bonus_points' || $config_name == 'seed_bonus_release' || $config_name == 'bonus_upload' || $config_name == 'bonus_upload_price') $new[$config_name] = serialize(str_replace(',', '.', $new[$config_name]));
- bb_update_config(array($config_name => $new[$config_name]));
- }
- }
-
- if (isset($_POST['submit']))
- {
- bb_die($lang['CONFIG_UPDATED'] . $return_links[$mode] . $return_links['index']);
- }
+if (!empty($setmodules)) {
+ $module['GENERAL']['CONFIGURATION'] = basename(__FILE__) . '?mode=config';
+ $module['MODS']['CONFIGURATION'] = basename(__FILE__) . '?mode=config_mods';
+ return;
}
-switch ($mode)
-{
- case 'config_mods':
- $template->assign_vars(array(
- 'S_CONFIG_ACTION' => 'admin_board.php?mode=config_mods',
- 'CONFIG_MODS' => true,
+require __DIR__ . '/pagestart.php';
- 'MAGNET_LINKS_ENABLED' => $new['magnet_links_enabled'],
- 'GENDER' => $new['gender'],
- 'CALLSEED' => $new['callseed'],
- 'TOR_STATS' => $new['tor_stats'],
- 'SHOW_LATEST_NEWS' => $new['show_latest_news'],
- 'MAX_NEWS_TITLE' => $new['max_news_title'],
- 'LATEST_NEWS_COUNT' => $new['latest_news_count'],
- 'LATEST_NEWS_FORUM_ID' => $new['latest_news_forum_id'],
- 'SHOW_NETWORK_NEWS' => $new['show_network_news'],
- 'MAX_NET_TITLE' => $new['max_net_title'],
- 'NETWORK_NEWS_COUNT' => $new['network_news_count'],
- 'NETWORK_NEWS_FORUM_ID' => $new['network_news_forum_id'],
- 'WHOIS_INFO' => $new['whois_info'],
- 'SHOW_MOD_INDEX' => $new['show_mod_index'],
- 'BIRTHDAY_ENABLED' => $new['birthday_enabled'],
- 'BIRTHDAY_MAX_AGE' => $new['birthday_max_age'],
- 'BIRTHDAY_MIN_AGE' => $new['birthday_min_age'],
- 'BIRTHDAY_CHECK_DAY' => $new['birthday_check_day'],
- 'PREMOD' => $new['premod'],
- 'TOR_COMMENT' => $new['tor_comment'],
- 'NEW_TPLS' => $new['new_tpls'],
- 'SEED_BONUS_ENABLED' => $new['seed_bonus_enabled'],
- 'SEED_BONUS_TOR_SIZE' => $new['seed_bonus_tor_size'],
- 'SEED_BONUS_USER_REGDATE' => $new['seed_bonus_user_regdate'],
- ));
+$mode = $_GET['mode'] ?? '';
- if ($new['seed_bonus_points'] && $new['seed_bonus_release'])
- {
- $seed_bonus = unserialize($new['seed_bonus_points']);
- $seed_release = unserialize($new['seed_bonus_release']);
+$return_links = [
+ 'index' => ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '),
+ 'config' => ' ' . sprintf($lang['CLICK_RETURN_CONFIG'], '', ' '),
+ 'config_mods' => ' ' . sprintf($lang['CLICK_RETURN_CONFIG_MODS'], '', ' ')
+];
- foreach ($seed_bonus as $i => $row)
- {
- if (!$row || !$seed_release[$i]) continue;
+/**
+ * Pull all config data
+ */
+$sql = 'SELECT * FROM ' . BB_CONFIG;
+if (!$result = DB()->sql_query($sql)) {
+ bb_die('Could not query config information in admin_board');
+} else {
+ while ($row = DB()->sql_fetchrow($result)) {
+ $config_name = $row['config_name'];
+ $config_value = $row['config_value'];
+ $default_config[$config_name] = $config_value;
- $template->assign_block_vars('seed_bonus', array(
- 'RELEASE' => $seed_release[$i],
- 'POINTS' => $row,
- ));
- }
- }
+ $new[$config_name] = $_POST[$config_name] ?? $default_config[$config_name];
- if ($new['bonus_upload'] && $new['bonus_upload_price'])
- {
- $upload_row = unserialize($new['bonus_upload']);
- $price_row = unserialize($new['bonus_upload_price']);
+ if (isset($_POST['submit']) && $row['config_value'] != $new[$config_name]) {
+ if ($config_name == 'seed_bonus_points' ||
+ $config_name == 'seed_bonus_release' ||
+ $config_name == 'bonus_upload' ||
+ $config_name == 'bonus_upload_price'
+ ) {
+ $new[$config_name] = serialize(str_replace(',', '.', $new[$config_name]));
+ }
+ bb_update_config([$config_name => $new[$config_name]]);
+ }
+ }
- foreach ($upload_row as $i => $row)
- {
- if (!$row || !$price_row[$i]) continue;
-
- $template->assign_block_vars('bonus_upload', array(
- 'UP' => $row,
- 'PRICE' => $price_row[$i],
- ));
- }
- }
- break;
-
- default:
- $template->assign_vars(array(
- 'S_CONFIG_ACTION' => 'admin_board.php?mode=config',
- 'CONFIG' => true,
-
- 'SITENAME' => htmlCHR($new['sitename']),
- 'CONFIG_SITE_DESCRIPTION' => htmlCHR($new['site_desc']),
- 'DISABLE_BOARD' => ($new['board_disable']) ? true : false,
- 'ALLOW_AUTOLOGIN' => ($new['allow_autologin']) ? true : false,
- 'AUTOLOGIN_TIME' => (int) $new['max_autologin_time'],
- 'MAX_POLL_OPTIONS' => $new['max_poll_options'],
- 'FLOOD_INTERVAL' => $new['flood_interval'],
- 'TOPICS_PER_PAGE' => $new['topics_per_page'],
- 'POSTS_PER_PAGE' => $new['posts_per_page'],
- 'HOT_TOPIC' => $new['hot_threshold'],
- 'DEFAULT_DATEFORMAT' => $new['default_dateformat'],
- 'LANG_SELECT' => language_select($new['default_lang'], 'default_lang'),
- 'TIMEZONE_SELECT' => tz_select($new['board_timezone'], 'board_timezone'),
- 'MAX_LOGIN_ATTEMPTS' => $new['max_login_attempts'],
- 'LOGIN_RESET_TIME' => $new['login_reset_time'],
- 'PRUNE_ENABLE' => ($new['prune_enable']) ? true : false,
- 'ALLOW_BBCODE' => ($new['allow_bbcode']) ? true : false,
- 'ALLOW_SMILIES' => ($new['allow_smilies']) ? true : false,
- 'ALLOW_SIG' => ($new['allow_sig']) ? true : false,
- 'SIG_SIZE' => $new['max_sig_chars'],
- 'ALLOW_NAMECHANGE' => ($new['allow_namechange']) ? true : false,
- 'SMILIES_PATH' => $new['smilies_path'],
- ));
- break;
+ if (isset($_POST['submit'])) {
+ bb_die($lang['CONFIG_UPDATED'] . $return_links[$mode] . $return_links['index']);
+ }
}
-print_page('admin_board.tpl', 'admin');
\ No newline at end of file
+switch ($mode) {
+ case 'config_mods':
+ $template->assign_vars([
+ 'S_CONFIG_ACTION' => 'admin_board.php?mode=config_mods',
+ 'CONFIG_MODS' => true,
+
+ 'MAGNET_LINKS_ENABLED' => $new['magnet_links_enabled'],
+ 'MAGNET_LINKS_FOR_GUESTS' => $new['magnet_links_for_guests'],
+ 'GENDER' => $new['gender'],
+ 'CALLSEED' => $new['callseed'],
+ 'TOR_STATS' => $new['tor_stats'],
+ 'SHOW_LATEST_NEWS' => $new['show_latest_news'],
+ 'MAX_NEWS_TITLE' => $new['max_news_title'],
+ 'LATEST_NEWS_COUNT' => $new['latest_news_count'],
+ 'LATEST_NEWS_FORUM_ID' => $new['latest_news_forum_id'],
+ 'SHOW_NETWORK_NEWS' => $new['show_network_news'],
+ 'MAX_NET_TITLE' => $new['max_net_title'],
+ 'NETWORK_NEWS_COUNT' => $new['network_news_count'],
+ 'NETWORK_NEWS_FORUM_ID' => $new['network_news_forum_id'],
+ 'WHOIS_INFO' => $new['whois_info'],
+ 'SHOW_MOD_INDEX' => $new['show_mod_index'],
+ 'SHOW_BOARD_START_INDEX' => $new['show_board_start_index'],
+ 'BIRTHDAY_ENABLED' => $new['birthday_enabled'],
+ 'BIRTHDAY_MAX_AGE' => $new['birthday_max_age'],
+ 'BIRTHDAY_MIN_AGE' => $new['birthday_min_age'],
+ 'BIRTHDAY_CHECK_DAY' => $new['birthday_check_day'],
+ 'PREMOD' => $new['premod'],
+ 'TOR_COMMENT' => $new['tor_comment'],
+ 'SEED_BONUS_ENABLED' => $new['seed_bonus_enabled'],
+ 'SEED_BONUS_TOR_SIZE' => $new['seed_bonus_tor_size'],
+ 'SEED_BONUS_USER_REGDATE' => $new['seed_bonus_user_regdate']
+ ]);
+
+ if ($new['seed_bonus_points'] && $new['seed_bonus_release']) {
+ $seed_bonus = unserialize($new['seed_bonus_points']);
+ $seed_release = unserialize($new['seed_bonus_release']);
+
+ foreach ($seed_bonus as $i => $row) {
+ if (!$row || !$seed_release[$i]) {
+ continue;
+ }
+
+ $template->assign_block_vars('seed_bonus', [
+ 'RELEASE' => $seed_release[$i],
+ 'POINTS' => $row
+ ]);
+ }
+ }
+
+ if ($new['bonus_upload'] && $new['bonus_upload_price']) {
+ $upload_row = unserialize($new['bonus_upload']);
+ $price_row = unserialize($new['bonus_upload_price']);
+
+ foreach ($upload_row as $i => $row) {
+ if (!$row || !$price_row[$i]) {
+ continue;
+ }
+
+ $template->assign_block_vars('bonus_upload', [
+ 'UP' => $row,
+ 'PRICE' => $price_row[$i]
+ ]);
+ }
+ }
+ break;
+
+ default:
+ $template->assign_vars([
+ 'S_CONFIG_ACTION' => 'admin_board.php?mode=config',
+ 'CONFIG' => true,
+
+ 'SITENAME' => htmlCHR($new['sitename']),
+ 'CONFIG_SITE_DESCRIPTION' => htmlCHR($new['site_desc']),
+ 'DISABLE_BOARD' => (bool)$new['board_disable'],
+ 'ALLOW_AUTOLOGIN' => (bool)$new['allow_autologin'],
+ 'AUTOLOGIN_TIME' => (int)$new['max_autologin_time'],
+ 'MAX_POLL_OPTIONS' => $new['max_poll_options'],
+ 'FLOOD_INTERVAL' => $new['flood_interval'],
+ 'TOPICS_PER_PAGE' => $new['topics_per_page'],
+ 'POSTS_PER_PAGE' => $new['posts_per_page'],
+ 'HOT_TOPIC' => $new['hot_threshold'],
+ 'DEFAULT_DATEFORMAT' => $new['default_dateformat'],
+ 'LANG_SELECT' => \TorrentPier\Legacy\Common\Select::language($new['default_lang'], 'default_lang'),
+ 'TIMEZONE_SELECT' => \TorrentPier\Legacy\Common\Select::timezone($new['board_timezone'], 'board_timezone'),
+ 'MAX_LOGIN_ATTEMPTS' => $new['max_login_attempts'],
+ 'LOGIN_RESET_TIME' => $new['login_reset_time'],
+ 'PRUNE_ENABLE' => (bool)$new['prune_enable'],
+ 'ALLOW_BBCODE' => (bool)$new['allow_bbcode'],
+ 'ALLOW_SMILIES' => (bool)$new['allow_smilies'],
+ 'ALLOW_SIG' => (bool)$new['allow_sig'],
+ 'SIG_SIZE' => $new['max_sig_chars'],
+ 'ALLOW_NAMECHANGE' => (bool)$new['allow_namechange'],
+ 'SMILIES_PATH' => $new['smilies_path']
+ ]);
+ break;
+}
+
+print_page('admin_board.tpl', 'admin');
diff --git a/admin/admin_bt_forum_cfg.php b/admin/admin_bt_forum_cfg.php
index ba06b1382..75453e0ca 100644
--- a/admin/admin_bt_forum_cfg.php
+++ b/admin/admin_bt_forum_cfg.php
@@ -1,150 +1,154 @@
'http://demo.torrentpier.me/bt/',
+ 'bt_announce_url' => 'https://torrentpier.duckdns.org/bt/',
);
$default_cfg_bool = array(
- 'bt_disable_dht' => 1,
- 'bt_show_peers' => 1,
- 'bt_add_auth_key' => 1,
- 'bt_show_dl_list' => 0,
- 'bt_dl_list_only_1st_page' => 1,
- 'bt_dl_list_only_count' => 1,
- 'bt_replace_ann_url' => 1,
- 'bt_show_ip_only_moder' => 1,
- 'bt_show_port_only_moder' => 1,
- 'bt_check_announce_url' => 0,
- 'bt_show_dl_list_buttons' => 1,
- 'bt_show_dl_but_will' => 1,
- 'bt_show_dl_but_down' => 0,
- 'bt_show_dl_but_compl' => 1,
- 'bt_show_dl_but_cancel' => 1,
- 'bt_show_dl_stat_on_index' => 1,
- 'bt_newtopic_auto_reg' => 1,
- 'bt_tor_browse_only_reg' => 1,
- 'bt_search_bool_mode' => 1,
- 'bt_allow_spmode_change' => 1,
- 'bt_del_addit_ann_urls' => 1,
- 'bt_set_dltype_on_tor_reg' => 1,
- 'bt_unset_dltype_on_tor_unreg' => 1,
+ 'bt_disable_dht' => 1,
+ 'bt_show_peers' => 1,
+ 'bt_add_auth_key' => 1,
+ 'bt_show_dl_list' => 0,
+ 'bt_dl_list_only_1st_page' => 1,
+ 'bt_dl_list_only_count' => 1,
+ 'bt_replace_ann_url' => 1,
+ 'bt_show_ip_only_moder' => 1,
+ 'bt_show_port_only_moder' => 1,
+ 'bt_check_announce_url' => 0,
+ 'bt_show_dl_list_buttons' => 1,
+ 'bt_show_dl_but_will' => 1,
+ 'bt_show_dl_but_down' => 0,
+ 'bt_show_dl_but_compl' => 1,
+ 'bt_show_dl_but_cancel' => 1,
+ 'bt_show_dl_stat_on_index' => 1,
+ 'bt_newtopic_auto_reg' => 1,
+ 'bt_tor_browse_only_reg' => 1,
+ 'bt_search_bool_mode' => 1,
+ 'bt_allow_spmode_change' => 1,
+ 'bt_del_addit_ann_urls' => 1,
+ 'bt_set_dltype_on_tor_reg' => 1,
+ 'bt_unset_dltype_on_tor_unreg' => 1,
);
$default_cfg_num = array(
- 'bt_show_peers_mode' => SHOW_PEERS_COUNT,
+ 'bt_show_peers_mode' => SHOW_PEERS_COUNT,
);
$default_cfg = array_merge($default_cfg_str, $default_cfg_bool, $default_cfg_num);
$db_fields_bool = array(
- 'allow_reg_tracker' => 0, // Allowed forums for registering torrents on tracker
- 'allow_porno_topic' => 0, // Allowed forums for porno topics
- 'self_moderated' => 0, // Users can move theirs topic to another forum
+ 'allow_reg_tracker' => 0, // Allowed forums for registering torrents on tracker
+ 'allow_porno_topic' => 0, // Allowed forums for porno topics
+ 'self_moderated' => 0, // Users can move theirs topic to another forum
);
-// Get config
+/**
+ * Get config
+ */
$cfg = bb_get_config(BB_CONFIG, true, false);
-// Submit new config
-if ($submit && $confirm)
-{
- foreach ($db_fields_bool as $field_name => $field_def_val)
- {
- update_table_bool(BB_FORUMS, 'forum_id', $field_name, $field_def_val);
- }
+/**
+ * Submit new config
+ */
+if ($submit && $confirm) {
+ foreach ($db_fields_bool as $field_name => $field_def_val) {
+ \TorrentPier\Legacy\Admin\Torrent::update_table_bool(BB_FORUMS, 'forum_id', $field_name, $field_def_val);
+ }
- update_config_table(BB_CONFIG, $default_cfg_str, $cfg, 'str');
- update_config_table(BB_CONFIG, $default_cfg_bool, $cfg, 'bool');
- update_config_table(BB_CONFIG, $default_cfg_num, $cfg, 'num');
+ \TorrentPier\Legacy\Admin\Torrent::update_config_table(BB_CONFIG, $default_cfg_str, $cfg, 'str');
+ \TorrentPier\Legacy\Admin\Torrent::update_config_table(BB_CONFIG, $default_cfg_bool, $cfg, 'bool');
+ \TorrentPier\Legacy\Admin\Torrent::update_config_table(BB_CONFIG, $default_cfg_num, $cfg, 'num');
- $datastore->update('cat_forums');
+ $datastore->update('cat_forums');
- bb_die($lang['CONFIG_UPD'] .' '. sprintf($lang['RETURN_CONFIG'], '', ' ') .' '. sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '));
+ bb_die($lang['CONFIG_UPD'] . ' ' . sprintf($lang['RETURN_CONFIG'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '));
}
// Set template vars
-set_tpl_vars ($default_cfg_str, $cfg);
-set_tpl_vars_lang ($default_cfg_str);
+\TorrentPier\Legacy\Admin\Torrent::set_tpl_vars($default_cfg_str, $cfg);
+\TorrentPier\Legacy\Admin\Torrent::set_tpl_vars_lang($default_cfg_str);
-set_tpl_vars_bool ($default_cfg_bool, $cfg);
-set_tpl_vars_lang ($default_cfg_bool);
+\TorrentPier\Legacy\Admin\Torrent::set_tpl_vars_bool($default_cfg_bool, $cfg);
+\TorrentPier\Legacy\Admin\Torrent::set_tpl_vars_lang($default_cfg_bool);
-set_tpl_vars ($default_cfg_num, $cfg);
-set_tpl_vars_lang ($default_cfg_num);
+\TorrentPier\Legacy\Admin\Torrent::set_tpl_vars($default_cfg_num, $cfg);
+\TorrentPier\Legacy\Admin\Torrent::set_tpl_vars_lang($default_cfg_num);
-set_tpl_vars_lang ($db_fields_bool);
+\TorrentPier\Legacy\Admin\Torrent::set_tpl_vars_lang($db_fields_bool);
// Get Forums list
-$sql = "SELECT f.*
- FROM ". BB_CATEGORIES ." c, ". BB_FORUMS ." f
+$sql = 'SELECT f.*
+ FROM ' . BB_CATEGORIES . ' c, ' . BB_FORUMS . ' f
WHERE f.cat_id = c.cat_id
- ORDER BY c.cat_order, f.forum_order";
+ ORDER BY c.cat_order, f.forum_order';
-if (!$result = DB()->sql_query($sql))
-{
- bb_die('Could not obtain forum names');
+if (!$result = DB()->sql_query($sql)) {
+ bb_die('Could not obtain forum names');
}
$rowset = DB()->sql_fetchrowset($result);
$forum_rows = min($max_forum_rows, count($rowset));
-foreach ($db_fields_bool as $field_name => $field_def_val)
-{
- $$field_name = '';
+foreach ($db_fields_bool as $field_name => $field_def_val) {
+ $$field_name = '';
}
-foreach ($rowset as $rid => $forum)
-{
- foreach ($db_fields_bool as $field_name => $field_def_val)
- {
- $forum_name = $forum['forum_name'];
- $selected = ($forum[$field_name]) ? ' selected="selected"' : '';
+foreach ($rowset as $rid => $forum) {
+ foreach ($db_fields_bool as $field_name => $field_def_val) {
+ $forum_name = $forum['forum_name'];
+ $selected = $forum[$field_name] ? ' selected' : '';
- $forum_name = str_short($forum_name, $max_forum_name_len);
+ $forum_name = str_short($forum_name, $max_forum_name_len);
- $$field_name .= ' ' . (($forum['forum_parent']) ? HTML_SF_SPACER : '') . htmlCHR($forum_name) ." \n";
- }
+ $$field_name .= ' ' . ($forum['forum_parent'] ? HTML_SF_SPACER : '') . htmlCHR($forum_name) . " \n";
+ }
}
-foreach ($db_fields_bool as $field_name => $field_def_val)
-{
- $$field_name = '". $$field_name .' ';
- $template->assign_vars(array('S_'. strtoupper($field_name) => $$field_name));
+foreach ($db_fields_bool as $field_name => $field_def_val) {
+ $$field_name = '" . $$field_name . ' ';
+ $template->assign_vars(array('S_' . strtoupper($field_name) => $$field_name));
}
$template->assign_vars(array(
- 'L_BT_SHOW_PEERS_MODE_COUNT' => ($cfg['bt_show_peers_mode'] == SHOW_PEERS_COUNT) ? ''. $lang['BT_SHOW_PEERS_MODE_COUNT'] .' ' : $lang['BT_SHOW_PEERS_MODE_COUNT'],
- 'L_BT_SHOW_PEERS_MODE_NAMES' => ($cfg['bt_show_peers_mode'] == SHOW_PEERS_NAMES) ? ''. $lang['BT_SHOW_PEERS_MODE_NAMES'] .' ' : $lang['BT_SHOW_PEERS_MODE_NAMES'],
- 'L_BT_SHOW_PEERS_MODE_FULL' => ($cfg['bt_show_peers_mode'] == SHOW_PEERS_FULL) ? ''. $lang['BT_SHOW_PEERS_MODE_FULL'] .' ' : $lang['BT_SHOW_PEERS_MODE_FULL'],
+ 'L_BT_SHOW_PEERS_MODE_COUNT' => ($cfg['bt_show_peers_mode'] == SHOW_PEERS_COUNT) ? '' . $lang['BT_SHOW_PEERS_MODE_COUNT'] . ' ' : $lang['BT_SHOW_PEERS_MODE_COUNT'],
+ 'L_BT_SHOW_PEERS_MODE_NAMES' => ($cfg['bt_show_peers_mode'] == SHOW_PEERS_NAMES) ? '' . $lang['BT_SHOW_PEERS_MODE_NAMES'] . ' ' : $lang['BT_SHOW_PEERS_MODE_NAMES'],
+ 'L_BT_SHOW_PEERS_MODE_FULL' => ($cfg['bt_show_peers_mode'] == SHOW_PEERS_FULL) ? '' . $lang['BT_SHOW_PEERS_MODE_FULL'] . ' ' : $lang['BT_SHOW_PEERS_MODE_FULL'],
- 'BT_SHOW_PEERS_MODE_COUNT_VAL' => SHOW_PEERS_COUNT,
- 'BT_SHOW_PEERS_MODE_NAMES_VAL' => SHOW_PEERS_NAMES,
- 'BT_SHOW_PEERS_MODE_FULL_VAL' => SHOW_PEERS_FULL,
+ 'BT_SHOW_PEERS_MODE_COUNT_VAL' => SHOW_PEERS_COUNT,
+ 'BT_SHOW_PEERS_MODE_NAMES_VAL' => SHOW_PEERS_NAMES,
+ 'BT_SHOW_PEERS_MODE_FULL_VAL' => SHOW_PEERS_FULL,
- 'BT_SHOW_PEERS_MODE_COUNT_SEL' => ($cfg['bt_show_peers_mode'] == SHOW_PEERS_COUNT) ? HTML_CHECKED : '',
- 'BT_SHOW_PEERS_MODE_NAMES_SEL' => ($cfg['bt_show_peers_mode'] == SHOW_PEERS_NAMES) ? HTML_CHECKED : '',
- 'BT_SHOW_PEERS_MODE_FULL_SEL' => ($cfg['bt_show_peers_mode'] == SHOW_PEERS_FULL) ? HTML_CHECKED : '',
+ 'BT_SHOW_PEERS_MODE_COUNT_SEL' => ($cfg['bt_show_peers_mode'] == SHOW_PEERS_COUNT) ? HTML_CHECKED : '',
+ 'BT_SHOW_PEERS_MODE_NAMES_SEL' => ($cfg['bt_show_peers_mode'] == SHOW_PEERS_NAMES) ? HTML_CHECKED : '',
+ 'BT_SHOW_PEERS_MODE_FULL_SEL' => ($cfg['bt_show_peers_mode'] == SHOW_PEERS_FULL) ? HTML_CHECKED : '',
- 'S_HIDDEN_FIELDS' => '',
- 'S_CONFIG_ACTION' => 'admin_bt_forum_cfg.php',
+ 'S_HIDDEN_FIELDS' => '',
+ 'S_CONFIG_ACTION' => 'admin_bt_forum_cfg.php',
));
-print_page('admin_bt_forum_cfg.tpl', 'admin');
\ No newline at end of file
+print_page('admin_bt_forum_cfg.tpl', 'admin');
diff --git a/admin/admin_bt_tracker_cfg.php b/admin/admin_bt_tracker_cfg.php
deleted file mode 100644
index 9406a5b89..000000000
--- a/admin/admin_bt_tracker_cfg.php
+++ /dev/null
@@ -1,64 +0,0 @@
- 'Tracker is disabled',
- 'browser_redirect_url' => 'http://demo.torrentpier.me/',
-);
-
-$default_cfg_bool = array(
- 'autoclean' => 1,
- 'off' => 0,
- 'compact_mode' => 1,
- 'update_dlstat' => 1,
- 'limit_active_tor' => 0,
- 'limit_concurrent_ips' => 0,
- 'retracker' => 1,
-);
-
-$default_cfg_num = array(
- 'numwant' => 50,
- 'expire_factor' => 4,
- 'limit_seed_count' => 20,
- 'limit_leech_count' => 4,
- 'leech_expire_factor' => 60,
- 'limit_seed_ips' => 0,
- 'limit_leech_ips' => 0,
-);
-
-// Set template vars
-set_tpl_vars ($default_cfg_str, $tr_cfg);
-set_tpl_vars_lang ($default_cfg_str);
-
-set_tpl_vars_bool ($default_cfg_bool, $tr_cfg);
-set_tpl_vars_lang ($default_cfg_bool);
-
-set_tpl_vars ($default_cfg_num, $tr_cfg);
-set_tpl_vars_lang ($default_cfg_num);
-
-$template->assign_vars(array(
- 'IGNORE_REPORTED_IP' => $bb_cfg['ignore_reported_ip'],
- 'ANNOUNCE_INTERVAL' => $bb_cfg['announce_interval'],
- 'PASSKEY_KEY' => $bb_cfg['passkey_key'],
- 'GOLD_SILVER_ENABLED' => $tr_cfg['gold_silver_enabled'],
- 'DISABLE_SUBMIT' => true,
-
- 'S_HIDDEN_FIELDS' => '',
- 'S_CONFIG_ACTION' => 'admin_bt_tracker_cfg.php',
-));
-
-print_page('admin_bt_tracker_cfg.tpl', 'admin');
\ No newline at end of file
diff --git a/admin/admin_cron.php b/admin/admin_cron.php
index 7999137c4..757108ec0 100644
--- a/admin/admin_cron.php
+++ b/admin/admin_cron.php
@@ -1,228 +1,216 @@
session_start();
- redirect('admin/'.basename(__FILE__) . '?mode=list');
+if ($mode == 'run' && !$job_id) {
+ define('BB_ROOT', './../');
+ require BB_ROOT . 'common.php';
+ $user->session_start();
+ redirect('admin/' . basename(__FILE__) . '?mode=list');
+} else {
+ require __DIR__ . '/pagestart.php';
}
-else require('./pagestart.php');
-if (!IS_SUPER_ADMIN) bb_die($lang['NOT_ADMIN']);
+// Check for demo mode
+if (IN_DEMO_MODE && ($submit || !in_array($mode, ['add', 'list']))) {
+ bb_die($lang['CANT_EDIT_IN_DEMO_MODE']);
+}
-require(INC_DIR .'functions_admin_torrent.php');
-require(INC_DIR .'functions_admin_cron.php');
+if (!IS_SUPER_ADMIN) {
+ bb_die($lang['ONLY_FOR_SUPER_ADMIN']);
+}
-$sql = DB()->fetch_rowset("SELECT * FROM ". BB_CONFIG ." WHERE config_name = 'cron_enabled' OR config_name = 'cron_check_interval'");
+$sql = DB()->fetch_rowset('SELECT * FROM ' . BB_CONFIG . " WHERE config_name = 'cron_check_interval'");
-foreach ($sql as $row)
-{
- $config_name = $row['config_name'];
- $config_value = $row['config_value'];
- $default_config[$config_name] = $config_value;
+foreach ($sql as $row) {
+ $config_name = $row['config_name'];
+ $config_value = $row['config_value'];
+ $default_config[$config_name] = $config_value;
- $new[$config_name] = isset($_POST[$config_name]) ? $_POST[$config_name] : $default_config[$config_name];
+ $new[$config_name] = $_POST[$config_name] ?? $default_config[$config_name];
- if (isset($_POST['submit']) && $row['config_value'] != $new[$config_name])
- {
- bb_update_config(array($config_name => $new[$config_name]));
- }
+ if (isset($_POST['submit']) && $row['config_value'] != $new[$config_name]) {
+ bb_update_config(array($config_name => $new[$config_name]));
+ }
}
$template->assign_vars(array(
- 'CRON_ENABLED' => ($new['cron_enabled']) ? true : false,
- 'CRON_CHECK_INTERVAL' => $new['cron_check_interval'],
+ 'CRON_ENABLED' => TorrentPier\Helpers\CronHelper::isEnabled(),
+ 'CRON_CHECK_INTERVAL' => $new['cron_check_interval'],
));
-switch ($mode)
-{
- case 'list':
- $sql = DB()->fetch_rowset("SELECT * FROM ". BB_CRON ." ORDER BY cron_id");
+switch ($mode) {
+ case 'list':
+ $sql = DB()->fetch_rowset('SELECT * FROM ' . BB_CRON . ' ORDER BY cron_id');
- foreach ($sql as $i => $row)
- {
- $template->assign_block_vars('list', array(
- 'ROW_CLASS' => !($i % 2) ? 'row2' : 'row1',
- 'JOB_ID' => $i + 1,
- 'CRON_ID' => $row['cron_id'],
- 'CRON_ACTIVE' => $row['cron_active'] ? ' ' : ' ',
- 'CRON_TITLE' => $row['cron_title'],
- 'CRON_SCRIPT' => $row['cron_script'],
- 'SCHEDULE' => $row['schedule'] ? $lang['SCHEDULE'][$row['schedule']] : ''. $lang['NOSELECT'] .' ',
- 'RUN_DAY' => $row['run_day'],
- 'LAST_RUN' => $row['last_run'],
- 'NEXT_RUN' => $row['next_run'],
- 'RUN_COUNT' => $row['run_counter'],
- ));
- }
+ foreach ($sql as $i => $row) {
+ $template->assign_block_vars('list', array(
+ 'ROW_CLASS' => !($i % 2) ? 'row2' : 'row1',
+ 'JOB_ID' => $i + 1,
+ 'CRON_ID' => $row['cron_id'],
+ 'CRON_ACTIVE' => $row['cron_active'] ? ' ' : ' ',
+ 'CRON_TITLE' => $row['cron_title'],
+ 'CRON_SCRIPT' => $row['cron_script'],
+ 'SCHEDULE' => $row['schedule'] ? $lang['SCHEDULE'][$row['schedule']] : '' . $lang['NOSELECT'] . ' ',
+ 'RUN_DAY' => $row['run_day'],
+ 'LAST_RUN' => $row['last_run'],
+ 'NEXT_RUN' => $row['next_run'],
+ 'RUN_COUNT' => $row['run_counter'],
+ ));
+ }
- $template->assign_vars(array(
- 'TPL_CRON_LIST' => true,
- 'S_CRON_ACTION' => 'admin_cron.php',
- 'S_MODE' => 'list',
- ));
+ $template->assign_vars(array(
+ 'TPL_CRON_LIST' => true,
+ 'S_CRON_ACTION' => 'admin_cron.php',
+ 'S_MODE' => 'list',
+ ));
- //detect cron status
- if (@file_exists('../triggers/cron_running'))
- {
- $template->assign_vars(array(
- 'CRON_RUNNING' => true,
- ));
- }
- break;
+ //detect cron status
+ if (is_file(CRON_RUNNING)) {
+ $template->assign_vars(array(
+ 'CRON_RUNNING' => true,
+ ));
+ }
+ break;
- case 'repair':
- if (@file_exists('../triggers/cron_running'))
- {
- rename("../triggers/cron_running", "../triggers/cron_allowed");
- }
- redirect('admin/'.basename(__FILE__) . '?mode=list');
- break;
+ case 'repair':
+ if (is_file(CRON_RUNNING)) {
+ rename(CRON_RUNNING, CRON_ALLOWED);
+ }
+ redirect('admin/' . basename(__FILE__) . '?mode=list');
+ break;
- case 'run':
- run_jobs($job_id);
- redirect('admin/'.basename(__FILE__) . '?mode=list');
- break;
+ case 'run':
+ \TorrentPier\Legacy\Admin\Cron::run_jobs($job_id);
+ redirect('admin/' . basename(__FILE__) . '?mode=list');
+ break;
- case 'edit':
- $sql = DB()->fetch_rowset("SELECT * FROM ". BB_CRON ." WHERE cron_id = $job_id");
+ case 'edit':
+ $sql = DB()->fetch_rowset('SELECT * FROM ' . BB_CRON . " WHERE cron_id = $job_id");
- foreach ($sql as $row)
- {
- $template->assign_vars(array(
- 'CRON_ID' => $row['cron_id'],
- 'CRON_ACTIVE' => $row['cron_active'],
- 'CRON_TITLE' => $row['cron_title'],
- 'CRON_SCRIPT' => $row['cron_script'],
- 'SCHEDULE' => $row['schedule'] ? $lang['SCHEDULE'][$row['schedule']] : '',
- 'RUN_DAY' => $row['run_day'],
- 'RUN_TIME' => $row['run_time'],
- 'RUN_ORDER' => $row['run_order'],
- 'LAST_RUN' => $row['last_run'],
- 'NEXT_RUN' => $row['next_run'],
- 'RUN_INTERVAL' => $row['run_interval'],
- 'LOG_ENABLED' => $row['log_enabled'],
- 'LOG_FILE' => $row['log_file'],
- 'LOG_SQL_QUERIES' => $row['log_sql_queries'],
- 'DISABLE_BOARD' => $row['disable_board'],
- 'RUN_COUNTER' => $row['run_counter'],
- ));
- }
+ foreach ($sql as $row) {
+ $template->assign_vars(array(
+ 'CRON_ID' => $row['cron_id'],
+ 'CRON_ACTIVE' => $row['cron_active'],
+ 'CRON_TITLE' => $row['cron_title'],
+ 'CRON_SCRIPT' => $row['cron_script'],
+ 'SCHEDULE' => $row['schedule'] ? $lang['SCHEDULE'][$row['schedule']] : '',
+ 'RUN_DAY' => $row['run_day'],
+ 'RUN_TIME' => $row['run_time'],
+ 'RUN_ORDER' => $row['run_order'],
+ 'LAST_RUN' => $row['last_run'],
+ 'NEXT_RUN' => $row['next_run'],
+ 'RUN_INTERVAL' => $row['run_interval'],
+ 'LOG_ENABLED' => $row['log_enabled'],
+ 'LOG_FILE' => $row['log_file'],
+ 'LOG_SQL_QUERIES' => $row['log_sql_queries'],
+ 'DISABLE_BOARD' => $row['disable_board'],
+ 'RUN_COUNTER' => $row['run_counter'],
+ ));
+ }
- $run_day = array($lang['DELTA_TIME']['INTERVALS']['mday'][0] => 0);
- for ($i = 1; $i <= 28; $i++)
- {
- $run_day[$i] = $i;
- }
+ $run_day = array($lang['DELTA_TIME']['INTERVALS']['mday'][0] => 0);
+ for ($i = 1; $i <= 28; $i++) {
+ $run_day[$i] = $i;
+ }
- $schedule = array($lang['SCHEDULE']['select'] => 0);
- foreach ($lang['SCHEDULE'] as $type => $key)
- {
- $schedule[$key] = $type;
- }
+ $schedule = array($lang['SCHEDULE']['select'] => 0);
+ foreach ($lang['SCHEDULE'] as $type => $key) {
+ $schedule[$key] = $type;
+ }
- $template->assign_vars(array(
- 'TPL_CRON_EDIT' => true,
- 'S_CRON_ACTION' => 'admin_cron.php',
- 'S_MODE' => 'edit',
- 'SCHEDULE' => build_select('schedule', $schedule, $row['schedule']),
- 'RUN_DAY' => build_select('run_day', $run_day, $row['run_day']),
- 'L_CRON_EDIT_HEAD' => $lang['CRON_EDIT_HEAD_EDIT'],
- ));
- break;
+ $template->assign_vars(array(
+ 'TPL_CRON_EDIT' => true,
+ 'S_CRON_ACTION' => 'admin_cron.php',
+ 'S_MODE' => 'edit',
+ 'SCHEDULE' => build_select('schedule', $schedule, $row['schedule']),
+ 'RUN_DAY' => build_select('run_day', $run_day, $row['run_day']),
+ 'L_CRON_EDIT_HEAD' => $lang['CRON_EDIT_HEAD_EDIT'],
+ ));
+ break;
- case 'add':
- $run_day = array($lang['DELTA_TIME']['INTERVALS']['mday'][0] => 0);
- for ($i = 1; $i <= 28; $i++)
- {
- $run_day[$i] = $i;
- }
+ case 'add':
+ $run_day = array($lang['DELTA_TIME']['INTERVALS']['mday'][0] => 0);
+ for ($i = 1; $i <= 28; $i++) {
+ $run_day[$i] = $i;
+ }
- $schedule = array();
- foreach ($lang['SCHEDULE'] as $type => $key)
- {
- $schedule[$key] = $type;
- }
+ $schedule = [];
+ foreach ($lang['SCHEDULE'] as $type => $key) {
+ $schedule[$key] = $type;
+ }
- $template->assign_vars(array(
- 'TPL_CRON_EDIT' => true,
- 'S_CRON_ACTION' => 'admin_cron.php',
- 'S_MODE' => 'add',
- 'SCHEDULE' => build_select('schedule', $schedule, 'select', null, null),
- 'RUN_DAY' => build_select('run_day', $run_day, 0, null, null),
- 'L_CRON_EDIT_HEAD' => $lang['CRON_EDIT_HEAD_ADD'],
- 'CRON_ID' => 'none',
- 'CRON_ACTIVE' => 1,
- 'CRON_TITLE' => '',
- 'CRON_SCRIPT' => '',
- 'RUN_TIME' => '',
- 'RUN_ORDER' => 255,
- 'LAST_RUN' => '0000-00-00 00:00:00',
- 'NEXT_RUN' => '0000-00-00 00:00:00',
- 'RUN_INTERVAL' => '',
- 'LOG_ENABLED' => 0,
- 'LOG_FILE' => '',
- 'LOG_SQL_QUERIES' => 0,
- 'DISABLE_BOARD' => 0,
- 'RUN_COUNTER' => 0,
- ));
- break;
+ $template->assign_vars(array(
+ 'TPL_CRON_EDIT' => true,
+ 'S_CRON_ACTION' => 'admin_cron.php',
+ 'S_MODE' => 'add',
+ 'SCHEDULE' => build_select('schedule', $schedule, 'select', null, null),
+ 'RUN_DAY' => build_select('run_day', $run_day, 0, null, null),
+ 'CRON_ID' => '',
+ 'CRON_ACTIVE' => 1,
+ 'CRON_TITLE' => '',
+ 'CRON_SCRIPT' => '',
+ 'RUN_TIME' => '',
+ 'RUN_ORDER' => 255,
+ 'LAST_RUN' => '1900-01-01 00:00:00',
+ 'NEXT_RUN' => '1900-01-01 00:00:00',
+ 'RUN_INTERVAL' => '',
+ 'LOG_ENABLED' => 0,
+ 'LOG_FILE' => '',
+ 'LOG_SQL_QUERIES' => 0,
+ 'DISABLE_BOARD' => 0,
+ 'RUN_COUNTER' => 0,
+ ));
+ break;
- case 'delete':
- delete_jobs($job_id);
- bb_die($lang['JOB_REMOVED'] . ' ' . sprintf($lang['CLICK_RETURN_JOBS'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '));
- break;
+ case 'delete':
+ \TorrentPier\Legacy\Admin\Cron::delete_jobs($job_id);
+ bb_die($lang['JOB_REMOVED'] . ' ' . sprintf($lang['CLICK_RETURN_JOBS'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '));
+ break;
}
-if ($submit)
-{
- if ($_POST['mode'] == 'list')
- {
- if ($cron_action == 'run' && $jobs)
- {
- run_jobs($jobs);
- }
- else if ($cron_action == 'delete' && $jobs)
- {
- delete_jobs($jobs);
- }
- else if (($cron_action == 'disable' || $cron_action == 'enable') && $jobs)
- {
- toggle_active($jobs, $cron_action);
- }
- redirect('admin/'.basename(__FILE__) . '?mode=list');
- }
- else if (validate_cron_post($_POST) == 1)
- {
- if ($_POST['mode'] == 'edit')
- {
- update_cron_job($_POST);
- }
- else if ($_POST['mode'] == 'add')
- {
- insert_cron_job($_POST);
- }
- else bb_die('Mode error');
+if ($submit) {
+ $mode2 = $_POST['mode'] ?? '';
+ if ($mode2 == 'list') {
+ if ($cron_action == 'run' && $jobs) {
+ \TorrentPier\Legacy\Admin\Cron::run_jobs($jobs);
+ } elseif ($cron_action == 'delete' && $jobs) {
+ \TorrentPier\Legacy\Admin\Cron::delete_jobs($jobs);
+ } elseif (($cron_action == 'disable' || $cron_action == 'enable') && $jobs) {
+ \TorrentPier\Legacy\Admin\Cron::toggle_active($jobs, $cron_action);
+ }
+ redirect('admin/' . basename(__FILE__) . '?mode=list');
+ } elseif (\TorrentPier\Legacy\Admin\Cron::validate_cron_post($_POST) == 1) {
+ if ($mode2 == 'edit') {
+ \TorrentPier\Legacy\Admin\Cron::update_cron_job($_POST);
+ } elseif ($mode2 == 'add') {
+ \TorrentPier\Legacy\Admin\Cron::insert_cron_job($_POST);
+ } else {
+ bb_die("Invalid mode: $mode2");
+ }
- redirect('admin/'.basename(__FILE__) . '?mode=list');
- }
- else
- {
- bb_die(validate_cron_post($_POST));
- }
+ redirect('admin/' . basename(__FILE__) . '?mode=list');
+ } else {
+ bb_die(\TorrentPier\Legacy\Admin\Cron::validate_cron_post($_POST));
+ }
}
-print_page('admin_cron.tpl', 'admin');
\ No newline at end of file
+print_page('admin_cron.tpl', 'admin');
diff --git a/admin/admin_disallow.php b/admin/admin_disallow.php
index 6fe2ef3b9..bdf424dcf 100644
--- a/admin/admin_disallow.php
+++ b/admin/admin_disallow.php
@@ -1,95 +1,86 @@
escape($disallowed_user) . "')";
+ $result = DB()->sql_query($sql);
+ if (!$result) {
+ bb_die('Could not add disallowed user');
+ }
+ $message = $lang['DISALLOW_SUCCESSFUL'];
+ }
- if ($disallowed_user == '')
- {
- bb_die($lang['FIELDS_EMPTY']);
- }
- if( !validate_username($disallowed_user) )
- {
- $message = $lang['DISALLOWED_ALREADY'];
- }
- else
- {
- $sql = "INSERT INTO " . BB_DISALLOW . " (disallow_username) VALUES('" . DB()->escape($disallowed_user) . "')";
- $result = DB()->sql_query( $sql );
- if (!$result)
- {
- bb_die('Could not add disallowed user');
- }
- $message = $lang['DISALLOW_SUCCESSFUL'];
- }
+ $message .= ' ' . sprintf($lang['CLICK_RETURN_DISALLOWADMIN'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' ');
- $message .= ' '. sprintf($lang['CLICK_RETURN_DISALLOWADMIN'], '', ' ') . ' '. sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' ');
+ bb_die($message);
+} elseif (isset($_POST['delete_name'])) {
+ $disallowed_id = isset($_POST['disallowed_id']) ? (int)$_POST['disallowed_id'] : (int)$_GET['disallowed_id'];
- bb_die($message);
-}
-elseif (isset($_POST['delete_name']))
-{
- $disallowed_id = (isset($_POST['disallowed_id']) ) ? intval( $_POST['disallowed_id'] ) : intval( $_GET['disallowed_id']);
+ if (!empty($disallowed_id)) {
+ $sql = 'DELETE FROM ' . BB_DISALLOW . " WHERE disallow_id = $disallowed_id";
+ $result = DB()->sql_query($sql);
+ if (!$result) {
+ bb_die('Could not removed disallowed user');
+ }
- $sql = "DELETE FROM " . BB_DISALLOW . " WHERE disallow_id = $disallowed_id";
- $result = DB()->sql_query($sql);
- if (!$result)
- {
- bb_die('Could not removed disallowed user');
- }
-
- $message .= $lang['DISALLOWED_DELETED'] .' '. sprintf($lang['CLICK_RETURN_DISALLOWADMIN'], '', ' ') .' '. sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' ');
-
- bb_die($message);
+ $message .= $lang['DISALLOWED_DELETED'] . ' ' . sprintf($lang['CLICK_RETURN_DISALLOWADMIN'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' ');
+ bb_die($message);
+ }
}
-//
-// Grab the current list of disallowed usernames...
-//
-$sql = "SELECT * FROM " . BB_DISALLOW;
+/**
+ * Grab the current list of disallowed usernames
+ */
+$sql = 'SELECT * FROM ' . BB_DISALLOW;
$result = DB()->sql_query($sql);
-if (!$result)
-{
- bb_die('Could not get disallowed users');
+if (!$result) {
+ bb_die('Could not get disallowed users');
}
$disallowed = DB()->sql_fetchrowset($result);
-//
-// Ok now generate the info for the template, which will be put out no matter
-// what mode we are in.
-//
+/**
+ * Now generate the info for the template, which will be put out no matter what mode we are in
+ */
$disallow_select = '';
-if (count($disallowed) <= 0)
-{
- $disallow_select .= '' . $lang['NO_DISALLOWED'] . ' ';
-}
-else
-{
- for ($i = 0; $i < count($disallowed); $i++)
- {
- $disallow_select .= '' . $disallowed[$i]['disallow_username'] . ' ';
- }
+if (count($disallowed) <= 0) {
+ $disallow_select .= '' . $lang['NO_DISALLOWED'] . ' ';
+} else {
+ for ($i = 0, $iMax = count($disallowed); $i < $iMax; $i++) {
+ $disallow_select .= '' . $disallowed[$i]['disallow_username'] . ' ';
+ }
}
$disallow_select .= ' ';
-$template->assign_vars(array(
- 'S_DISALLOW_SELECT' => $disallow_select,
- 'S_FORM_ACTION' => 'admin_disallow.php',
-));
+$template->assign_vars([
+ 'S_DISALLOW_SELECT' => $disallow_select,
+ 'S_FORM_ACTION' => 'admin_disallow.php',
+]);
-print_page('admin_disallow.tpl', 'admin');
\ No newline at end of file
+print_page('admin_disallow.tpl', 'admin');
diff --git a/admin/admin_extensions.php b/admin/admin_extensions.php
index d36b997c7..639bbc8a6 100644
--- a/admin/admin_extensions.php
+++ b/admin/admin_extensions.php
@@ -1,36 +1,35 @@
update('attach_extensions');
}
-require('./pagestart.php');
-function update_attach_extensions () {
- $GLOBALS['datastore']->update('attach_extensions');
-}
register_shutdown_function('update_attach_extensions');
-if (($attach_config['upload_dir'][0] == '/') || (($attach_config['upload_dir'][0] != '/') && ($attach_config['upload_dir'][1] == ':')))
-{
- $upload_dir = $attach_config['upload_dir'];
-}
-else
-{
- $upload_dir = BB_ROOT . $attach_config['upload_dir'];
+if (($attach_config['upload_dir'][0] == '/') || (($attach_config['upload_dir'][0] != '/') && ($attach_config['upload_dir'][1] == ':'))) {
+ $upload_dir = $attach_config['upload_dir'];
+} else {
+ $upload_dir = BB_ROOT . $attach_config['upload_dir'];
}
-include(ATTACH_DIR .'includes/functions_selects.php');
-
-// Check if the language got included
-if (!isset($lang['TEST_SETTINGS_SUCCESSFUL']))
-{
- // include_once is used within the function
- include_attach_lang();
-}
+include ATTACH_DIR . '/includes/functions_selects.php';
// Init Vars
$types_download = array(INLINE_LINK, PHYSICAL_LINK);
@@ -43,738 +42,636 @@ $size = get_var('size', '');
$mode = get_var('mode', '');
$e_mode = get_var('e_mode', '');
-$submit = (isset($_POST['submit'])) ? TRUE : FALSE;
+$error = false;
+$add_forum = isset($_POST['add_forum']);
+$delete_forum = isset($_POST['del_forum']);
+$submit = isset($_POST['submit']);
-// Get Attachment Config
-$attach_config = array();
-
-$sql = 'SELECT * FROM '. BB_ATTACH_CONFIG;
-
-if (!($result = DB()->sql_query($sql)))
-{
- bb_die('Could not query attachment information');
+// Check for demo mode
+if (IN_DEMO_MODE && ($submit || $add_forum || $delete_forum)) {
+ bb_die($lang['CANT_EDIT_IN_DEMO_MODE']);
}
-while ($row = DB()->sql_fetchrow($result))
-{
- $attach_config[$row['config_name']] = trim($row['config_value']);
+// Get Attachment Config
+$attach_config = [];
+
+$sql = 'SELECT * FROM ' . BB_ATTACH_CONFIG;
+
+if (!($result = DB()->sql_query($sql))) {
+ bb_die('Could not query attachment information');
+}
+
+while ($row = DB()->sql_fetchrow($result)) {
+ $attach_config[$row['config_name']] = trim($row['config_value']);
}
DB()->sql_freeresult($result);
// Extension Management
-if ($submit && $mode == 'extensions')
-{
- // Change Extensions ?
- $extension_change_list = get_var('extension_change_list', array(0));
- $extension_explain_list = get_var('extension_explain_list', array(''));
- $group_select_list = get_var('group_select', array(0));
+if ($submit && $mode == 'extensions') {
+ // Change Extensions ?
+ $extension_change_list = get_var('extension_change_list', array(0));
+ $extension_explain_list = get_var('extension_explain_list', array(''));
+ $group_select_list = get_var('group_select', array(0));
- // Generate correct Change List
- $extensions = array();
+ // Generate correct Change List
+ $extensions = [];
- for ($i = 0; $i < sizeof($extension_change_list); $i++)
- {
- $extensions['_' . $extension_change_list[$i]]['comment'] = $extension_explain_list[$i];
- $extensions['_' . $extension_change_list[$i]]['group_id'] = intval($group_select_list[$i]);
- }
+ for ($i = 0, $iMax = count($extension_change_list); $i < $iMax; $i++) {
+ $extensions['_' . $extension_change_list[$i]]['comment'] = $extension_explain_list[$i];
+ $extensions['_' . $extension_change_list[$i]]['group_id'] = (int)$group_select_list[$i];
+ }
- $sql = 'SELECT * FROM ' . BB_EXTENSIONS . ' ORDER BY ext_id';
- if (!($result = DB()->sql_query($sql)))
- {
- bb_die('Could not get extension informations #1');
- }
+ $sql = 'SELECT * FROM ' . BB_EXTENSIONS . ' ORDER BY ext_id';
+ if (!($result = DB()->sql_query($sql))) {
+ bb_die('Could not get extension informations #1');
+ }
- $num_rows = DB()->num_rows($result);
- $extension_row = DB()->sql_fetchrowset($result);
- DB()->sql_freeresult($result);
+ $num_rows = DB()->num_rows($result);
+ $extension_row = DB()->sql_fetchrowset($result);
+ DB()->sql_freeresult($result);
- if ($num_rows > 0)
- {
- for ($i = 0; $i < sizeof($extension_row); $i++)
- {
- if ($extension_row[$i]['comment'] != $extensions['_' . $extension_row[$i]['ext_id']]['comment'] || intval($extension_row[$i]['group_id']) != intval($extensions['_' . $extension_row[$i]['ext_id']]['group_id']))
- {
- $sql_ary = array(
- 'comment' => (string) $extensions['_' . $extension_row[$i]['ext_id']]['comment'],
- 'group_id' => (int) $extensions['_' . $extension_row[$i]['ext_id']]['group_id']
- );
+ if ($num_rows > 0) {
+ for ($i = 0, $iMax = count($extension_row); $i < $iMax; $i++) {
+ if ($extension_row[$i]['comment'] != $extensions['_' . $extension_row[$i]['ext_id']]['comment'] || (int)$extension_row[$i]['group_id'] != (int)$extensions['_' . $extension_row[$i]['ext_id']]['group_id']) {
+ $sql_ary = array(
+ 'comment' => (string)$extensions['_' . $extension_row[$i]['ext_id']]['comment'],
+ 'group_id' => (int)$extensions['_' . $extension_row[$i]['ext_id']]['group_id']
+ );
- $sql = 'UPDATE ' . BB_EXTENSIONS . ' SET ' . attach_mod_sql_build_array('UPDATE', $sql_ary) . '
- WHERE ext_id = ' . (int) $extension_row[$i]['ext_id'];
+ $sql = 'UPDATE ' . BB_EXTENSIONS . ' SET ' . DB()->build_array('UPDATE', $sql_ary) . '
+ WHERE ext_id = ' . (int)$extension_row[$i]['ext_id'];
- if (!DB()->sql_query($sql))
- {
- bb_die('Could not update extension informations');
- }
- }
- }
- }
+ if (!DB()->sql_query($sql)) {
+ bb_die('Could not update extension informations');
+ }
+ }
+ }
+ }
- // Delete Extension?
- $extension_id_list = get_var('extension_id_list', array(0));
+ // Delete Extension?
+ $extension_id_list = get_var('extension_id_list', array(0));
- $extension_id_sql = implode(', ', $extension_id_list);
+ $extension_id_sql = implode(', ', $extension_id_list);
- if ($extension_id_sql != '')
- {
- $sql = 'DELETE FROM ' . BB_EXTENSIONS . ' WHERE ext_id IN (' . $extension_id_sql . ')';
+ if ($extension_id_sql != '') {
+ $sql = 'DELETE FROM ' . BB_EXTENSIONS . ' WHERE ext_id IN (' . $extension_id_sql . ')';
- if( !$result = DB()->sql_query($sql) )
- {
- bb_die('Could not delete extensions');
- }
- }
+ if (!$result = DB()->sql_query($sql)) {
+ bb_die('Could not delete extensions');
+ }
+ }
- // Add Extension ?
- $extension = get_var('add_extension', '');
- $extension_explain = get_var('add_extension_explain', '');
- $extension_group = get_var('add_group_select', 0);
- $add = ( isset($_POST['add_extension_check']) ) ? TRUE : FALSE;
+ // Add Extension ?
+ $extension = get_var('add_extension', '');
+ $extension_explain = get_var('add_extension_explain', '');
+ $extension_group = get_var('add_group_select', 0);
+ $add = isset($_POST['add_extension_check']);
- if ($extension != '' && $add)
- {
- $template->assign_vars(array(
- 'ADD_EXTENSION' => $extension,
- 'ADD_EXTENSION_EXPLAIN' => $extension_explain,
- ));
+ if ($extension != '' && $add) {
+ $template->assign_vars(array(
+ 'ADD_EXTENSION' => $extension,
+ 'ADD_EXTENSION_EXPLAIN' => $extension_explain,
+ ));
- if (!@$error)
- {
- // check extension
- $sql = 'SELECT extension FROM ' . BB_EXTENSIONS;
+ if (!$error) {
+ // check extension
+ $sql = 'SELECT extension FROM ' . BB_EXTENSIONS;
- if (!($result = DB()->sql_query($sql)))
- {
- bb_die('Could not query extensions');
- }
+ if (!($result = DB()->sql_query($sql))) {
+ bb_die('Could not query extensions');
+ }
- $row = DB()->sql_fetchrowset($result);
- $num_rows = DB()->num_rows($result);
- DB()->sql_freeresult($result);
+ $row = DB()->sql_fetchrowset($result);
+ $num_rows = DB()->num_rows($result);
+ DB()->sql_freeresult($result);
- if ($num_rows > 0)
- {
- for ($i = 0; $i < $num_rows; $i++)
- {
- if (strtolower(trim($row[$i]['extension'])) == strtolower(trim($extension)))
- {
- $error = TRUE;
- if( isset($error_msg) )
- {
- $error_msg .= ' ';
- }
- $error_msg .= sprintf($lang['EXTENSION_EXIST'], strtolower(trim($extension)));
- }
- }
- }
+ if ($num_rows > 0) {
+ for ($i = 0; $i < $num_rows; $i++) {
+ if (strtolower(trim($row[$i]['extension'])) == strtolower(trim($extension))) {
+ $error = true;
+ if (isset($error_msg)) {
+ $error_msg .= ' ';
+ }
+ $error_msg .= sprintf($lang['EXTENSION_EXIST'], strtolower(trim($extension)));
+ }
+ }
+ }
- if (!@$error)
- {
- $sql_ary = array(
- 'group_id' => (int) $extension_group,
- 'extension' => (string) strtolower($extension),
- 'comment' => (string) $extension_explain
- );
+ if (!$error) {
+ $sql_ary = array(
+ 'group_id' => (int)$extension_group,
+ 'extension' => (string)strtolower($extension),
+ 'comment' => (string)$extension_explain
+ );
- $sql = 'INSERT INTO ' . BB_EXTENSIONS . ' ' . attach_mod_sql_build_array('INSERT', $sql_ary);
+ $sql = 'INSERT INTO ' . BB_EXTENSIONS . ' ' . DB()->build_array('INSERT', $sql_ary);
- if (!DB()->sql_query($sql))
- {
- bb_die('Could not add extension');
- }
+ if (!DB()->sql_query($sql)) {
+ bb_die('Could not add extension');
+ }
+ }
+ }
+ }
- }
- }
- }
-
- if (!@$error)
- {
- bb_die($lang['ATTACH_CONFIG_UPDATED'] . ' ' . sprintf($lang['CLICK_RETURN_ATTACH_CONFIG'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '));
- }
+ if (!$error) {
+ bb_die($lang['ATTACH_CONFIG_UPDATED'] . ' ' . sprintf($lang['CLICK_RETURN_ATTACH_CONFIG'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '));
+ }
}
-if ($mode == 'extensions')
-{
- // Extensions
- $template->assign_vars(array(
- 'TPL_ATTACH_EXTENSIONS' => true,
- 'S_CANCEL_ACTION' => 'admin_extensions.php?mode=extensions',
- 'S_ATTACH_ACTION' => 'admin_extensions.php?mode=extensions',
- ));
+if ($mode == 'extensions') {
+ // Extensions
+ $template->assign_vars(array(
+ 'TPL_ATTACH_EXTENSIONS' => true,
+ 'S_CANCEL_ACTION' => 'admin_extensions.php?mode=extensions',
+ 'S_ATTACH_ACTION' => 'admin_extensions.php?mode=extensions',
+ ));
- if ($submit)
- {
- $template->assign_vars(array(
- 'S_ADD_GROUP_SELECT' => group_select('add_group_select', $extension_group))
- );
- }
- else
- {
- $template->assign_vars(array(
- 'S_ADD_GROUP_SELECT' => group_select('add_group_select'))
- );
- }
+ if ($submit) {
+ $template->assign_vars(array(
+ 'S_ADD_GROUP_SELECT' => group_select('add_group_select', $extension_group))
+ );
+ } else {
+ $template->assign_vars(array(
+ 'S_ADD_GROUP_SELECT' => group_select('add_group_select'))
+ );
+ }
- $sql = 'SELECT * FROM ' . BB_EXTENSIONS . ' ORDER BY group_id';
+ $sql = 'SELECT * FROM ' . BB_EXTENSIONS . ' ORDER BY group_id';
- if (!($result = DB()->sql_query($sql)))
- {
- bb_die('Could not get extension informations #2');
- }
+ if (!($result = DB()->sql_query($sql))) {
+ bb_die('Could not get extension informations #2');
+ }
- $extension_row = DB()->sql_fetchrowset($result);
- $num_extension_row = DB()->num_rows($result);
- DB()->sql_freeresult($result);
+ $extension_row = DB()->sql_fetchrowset($result);
+ $num_extension_row = DB()->num_rows($result);
+ DB()->sql_freeresult($result);
- if ($num_extension_row > 0)
- {
- $extension_row = sort_multi_array($extension_row, 'group_name', 'ASC');
-
- for ($i = 0; $i < $num_extension_row; $i++)
- {
- if ($submit)
- {
- $template->assign_block_vars('extension_row', array(
- 'EXT_ID' => $extension_row[$i]['ext_id'],
- 'EXTENSION' => $extension_row[$i]['extension'],
- 'EXTENSION_EXPLAIN' => $extension_explain_list[$i],
- 'S_GROUP_SELECT' => group_select('group_select[]', $group_select_list[$i]))
- );
- }
- else
- {
- $template->assign_block_vars('extension_row', array(
- 'EXT_ID' => $extension_row[$i]['ext_id'],
- 'EXTENSION' => $extension_row[$i]['extension'],
- 'EXTENSION_EXPLAIN' => $extension_row[$i]['comment'],
- 'S_GROUP_SELECT' => group_select('group_select[]', $extension_row[$i]['group_id']))
- );
- }
- }
- }
+ if ($num_extension_row > 0) {
+ $extension_row = sort_multi_array($extension_row, 'group_id');
+ for ($i = 0; $i < $num_extension_row; $i++) {
+ if ($submit) {
+ $template->assign_block_vars('extension_row', array(
+ 'EXT_ID' => $extension_row[$i]['ext_id'],
+ 'EXTENSION' => $extension_row[$i]['extension'],
+ 'EXTENSION_EXPLAIN' => $extension_explain_list[$i],
+ 'S_GROUP_SELECT' => group_select('group_select[]', $group_select_list[$i]))
+ );
+ } else {
+ $template->assign_block_vars('extension_row', array(
+ 'EXT_ID' => $extension_row[$i]['ext_id'],
+ 'EXTENSION' => $extension_row[$i]['extension'],
+ 'EXTENSION_EXPLAIN' => $extension_row[$i]['comment'],
+ 'S_GROUP_SELECT' => group_select('group_select[]', $extension_row[$i]['group_id']))
+ );
+ }
+ }
+ }
}
// Extension Groups
-if ($submit && $mode == 'groups')
-{
- // Change Extension Groups ?
- $group_change_list = get_var('group_change_list', array(0));
- $extension_group_list = get_var('extension_group_list', array(''));
- $group_allowed_list = get_var('allowed_list', array(0));
- $download_mode_list = get_var('download_mode_list', array(0));
- $category_list = get_var('category_list', array(0));
- $upload_icon_list = get_var('upload_icon_list', array(''));
- $filesize_list = get_var('max_filesize_list', array(0));
- $size_select_list = get_var('size_select_list', array(''));
+if ($submit && $mode == 'groups') {
+ // Change Extension Groups ?
+ $group_change_list = get_var('group_change_list', array(0));
+ $extension_group_list = get_var('extension_group_list', array(''));
+ $group_allowed_list = get_var('allowed_list', array(0));
+ $download_mode_list = get_var('download_mode_list', array(0));
+ $category_list = get_var('category_list', array(0));
+ $upload_icon_list = get_var('upload_icon_list', array(''));
+ $filesize_list = get_var('max_filesize_list', array(0));
+ $size_select_list = get_var('size_select_list', array(''));
- $allowed_list = array();
+ $allowed_list = [];
- for ($i = 0; $i < sizeof($group_allowed_list); $i++)
- {
- for ($j = 0; $j < sizeof($group_change_list); $j++)
- {
- if ($group_allowed_list[$i] == $group_change_list[$j])
- {
- $allowed_list[$j] = 1;
- }
- }
- }
+ foreach ($group_allowed_list as $iValue) {
+ for ($j = 0, $jMax = count($group_change_list); $j < $jMax; $j++) {
+ if ($iValue == $group_change_list[$j]) {
+ $allowed_list[$j] = 1;
+ }
+ }
+ }
- for ($i = 0; $i < sizeof($group_change_list); $i++)
- {
- $allowed = (isset($allowed_list[$i])) ? 1 : 0;
+ for ($i = 0, $iMax = count($group_change_list); $i < $iMax; $i++) {
+ $allowed = isset($allowed_list[$i]) ? 1 : 0;
- $filesize_list[$i] = ($size_select_list[$i] == 'kb') ? round($filesize_list[$i] * 1024) : ( ($size_select_list[$i] == 'mb') ? round($filesize_list[$i] * 1048576) : $filesize_list[$i] );
+ $filesize_list[$i] = ($size_select_list[$i] == 'kb') ? round($filesize_list[$i] * 1024) : (($size_select_list[$i] == 'mb') ? round($filesize_list[$i] * 1048576) : $filesize_list[$i]);
- $sql_ary = array(
- 'group_name' => (string) $extension_group_list[$i],
- 'cat_id' => (int) $category_list[$i],
- 'allow_group' => (int) $allowed,
- 'download_mode' => (int) $download_mode_list[$i],
- 'upload_icon' => (string) $upload_icon_list[$i],
- 'max_filesize' => (int) $filesize_list[$i]
- );
+ $sql_ary = array(
+ 'group_name' => (string)$extension_group_list[$i],
+ 'cat_id' => (int)$category_list[$i],
+ 'allow_group' => (int)$allowed,
+ 'download_mode' => (int)$download_mode_list[$i],
+ 'upload_icon' => (string)$upload_icon_list[$i],
+ 'max_filesize' => (int)$filesize_list[$i]
+ );
- $sql = 'UPDATE ' . BB_EXTENSION_GROUPS . ' SET ' . attach_mod_sql_build_array('UPDATE', $sql_ary) . '
- WHERE group_id = ' . (int) $group_change_list[$i];
+ $sql = 'UPDATE ' . BB_EXTENSION_GROUPS . ' SET ' . DB()->build_array('UPDATE', $sql_ary) . '
+ WHERE group_id = ' . (int)$group_change_list[$i];
- if (!(DB()->sql_query($sql)))
- {
- bb_die('Could not update extension groups informations');
- }
- }
+ if (!DB()->sql_query($sql)) {
+ bb_die('Could not update extension groups informations');
+ }
+ }
- // Delete Extension Groups
- $group_id_list = get_var('group_id_list', array(0));
+ // Delete Extension Groups
+ $group_id_list = get_var('group_id_list', array(0));
- $group_id_sql = implode(', ', $group_id_list);
+ $group_id_sql = implode(', ', $group_id_list);
- if ($group_id_sql != '')
- {
- $sql = 'DELETE
+ if ($group_id_sql != '') {
+ $sql = 'DELETE
FROM ' . BB_EXTENSION_GROUPS . '
WHERE group_id IN (' . $group_id_sql . ')';
- if (!($result = DB()->sql_query($sql)))
- {
- bb_die('Could not delete extension groups');
- }
+ if (!($result = DB()->sql_query($sql))) {
+ bb_die('Could not delete extension groups');
+ }
- // Set corresponding Extensions to a pending Group
- $sql = 'UPDATE ' . BB_EXTENSIONS . '
+ // Set corresponding Extensions to a pending Group
+ $sql = 'UPDATE ' . BB_EXTENSIONS . '
SET group_id = 0
WHERE group_id IN (' . $group_id_sql . ')';
- if (!$result = DB()->sql_query($sql))
- {
- bb_die('Could not assign extensions to pending group');
- }
- }
+ if (!$result = DB()->sql_query($sql)) {
+ bb_die('Could not assign extensions to pending group');
+ }
+ }
- // Add Extensions?
- $extension_group = get_var('add_extension_group', '');
- $download_mode = get_var('add_download_mode', 0);
- $cat_id = get_var('add_category', 0);
- $upload_icon = get_var('add_upload_icon', '');
- $filesize = get_var('add_max_filesize', 0);
- $size_select = get_var('add_size_select', '');
+ // Add Extensions?
+ $extension_group = get_var('add_extension_group', '');
+ $download_mode = get_var('add_download_mode', 0);
+ $cat_id = get_var('add_category', 0);
+ $upload_icon = get_var('add_upload_icon', '');
+ $filesize = get_var('add_max_filesize', 0);
+ $size_select = get_var('add_size_select', '');
- $is_allowed = (isset($_POST['add_allowed'])) ? 1 : 0;
- $add = ( isset($_POST['add_extension_group_check']) ) ? TRUE : FALSE;
+ $is_allowed = isset($_POST['add_allowed']) ? 1 : 0;
+ $add = isset($_POST['add_extension_group_check']);
- if ($extension_group != '' && $add)
- {
- // check Extension Group
- $sql = 'SELECT group_name FROM ' . BB_EXTENSION_GROUPS;
+ if ($extension_group != '' && $add) {
+ // check Extension Group
+ $sql = 'SELECT group_name FROM ' . BB_EXTENSION_GROUPS;
- if (!($result = DB()->sql_query($sql)))
- {
- bb_die('Could not query extension groups table');
- }
+ if (!($result = DB()->sql_query($sql))) {
+ bb_die('Could not query extension groups table');
+ }
- $row = DB()->sql_fetchrowset($result);
- $num_rows = DB()->num_rows($result);
- DB()->sql_freeresult($result);
+ $row = DB()->sql_fetchrowset($result);
+ $num_rows = DB()->num_rows($result);
+ DB()->sql_freeresult($result);
- if ($num_rows > 0)
- {
- for ($i = 0; $i < $num_rows; $i++)
- {
- if ($row[$i]['group_name'] == $extension_group)
- {
- $error = TRUE;
- if( isset($error_msg) )
- {
- $error_msg .= ' ';
- }
- $error_msg .= sprintf($lang['EXTENSION_GROUP_EXIST'], $extension_group);
- }
- }
- }
+ if ($num_rows > 0) {
+ for ($i = 0; $i < $num_rows; $i++) {
+ if ($row[$i]['group_name'] == $extension_group) {
+ $error = true;
+ if (isset($error_msg)) {
+ $error_msg .= ' ';
+ }
+ $error_msg .= sprintf($lang['EXTENSION_GROUP_EXIST'], $extension_group);
+ }
+ }
+ }
- if (!@$error)
- {
- $filesize = ($size_select == 'kb') ? round($filesize * 1024) : ( ($size_select == 'mb') ? round($filesize * 1048576) : $filesize );
+ if (!$error) {
+ $filesize = ($size_select == 'kb') ? round($filesize * 1024) : (($size_select == 'mb') ? round($filesize * 1048576) : $filesize);
- $sql_ary = array(
- 'group_name' => (string) $extension_group,
- 'cat_id' => (int) $cat_id,
- 'allow_group' => (int) $is_allowed,
- 'download_mode' => (int) $download_mode,
- 'upload_icon' => (string) $upload_icon,
- 'max_filesize' => (int) $filesize,
- 'forum_permissions' => ''
- );
+ $sql_ary = array(
+ 'group_name' => (string)$extension_group,
+ 'cat_id' => (int)$cat_id,
+ 'allow_group' => (int)$is_allowed,
+ 'download_mode' => (int)$download_mode,
+ 'upload_icon' => (string)$upload_icon,
+ 'max_filesize' => (int)$filesize,
+ 'forum_permissions' => ''
+ );
- $sql = 'INSERT INTO ' . BB_EXTENSION_GROUPS . ' ' . attach_mod_sql_build_array('INSERT', $sql_ary);
+ $sql = 'INSERT INTO ' . BB_EXTENSION_GROUPS . ' ' . DB()->build_array('INSERT', $sql_ary);
- if (!(DB()->sql_query($sql)))
- {
- bb_die('Could not add extension group');
- }
- }
+ if (!DB()->sql_query($sql)) {
+ bb_die('Could not add extension group');
+ }
+ }
+ }
- }
-
- if (!@$error)
- {
- bb_die($lang['ATTACH_CONFIG_UPDATED'] . ' ' . sprintf($lang['CLICK_RETURN_ATTACH_CONFIG'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '));
- }
+ if (!$error) {
+ bb_die($lang['ATTACH_CONFIG_UPDATED'] . ' ' . sprintf($lang['CLICK_RETURN_ATTACH_CONFIG'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '));
+ }
}
-if ($mode == 'groups')
-{
- // Extension Groups
- if (!$size && !$submit)
- {
- $max_add_filesize = $attach_config['max_filesize'];
+if ($mode == 'groups') {
+ // Extension Groups
+ if (!$size && !$submit) {
+ $max_add_filesize = $attach_config['max_filesize'];
- $size = ($max_add_filesize >= 1048576) ? 'mb' : ( ($max_add_filesize >= 1024) ? 'kb' : 'b' );
- }
+ $size = ($max_add_filesize >= 1048576) ? 'mb' : (($max_add_filesize >= 1024) ? 'kb' : 'b');
+ }
- if ($max_add_filesize >= 1048576)
- {
- $max_add_filesize = round($max_add_filesize / 1048576 * 100) / 100;
- }
- else if ( $max_add_filesize >= 1024)
- {
- $max_add_filesize = round($max_add_filesize / 1024 * 100) / 100;
- }
+ if ($max_add_filesize >= 1048576) {
+ $max_add_filesize = round($max_add_filesize / 1048576 * 100) / 100;
+ } elseif ($max_add_filesize >= 1024) {
+ $max_add_filesize = round($max_add_filesize / 1024 * 100) / 100;
+ }
- $viewgroup = get_var(POST_GROUPS_URL, 0);
+ $viewgroup = get_var(POST_GROUPS_URL, 0);
- $template->assign_vars(array(
- 'TPL_ATTACH_EXTENSION_GROUPS' => true,
- 'ADD_GROUP_NAME' => ( isset($submit) ) ? @$extension_group : '',
- 'MAX_FILESIZE' => $max_add_filesize,
- 'S_FILESIZE' => size_select('add_size_select', $size),
- 'S_ADD_DOWNLOAD_MODE' => download_select('add_download_mode'),
- 'S_SELECT_CAT' => category_select('add_category'),
- 'S_CANCEL_ACTION' => 'admin_extensions.php?mode=groups',
- 'S_ATTACH_ACTION' => 'admin_extensions.php?mode=groups',
- ));
+ $template->assign_vars(array(
+ 'TPL_ATTACH_EXTENSION_GROUPS' => true,
+ 'ADD_GROUP_NAME' => $extension_group ?? '',
+ 'MAX_FILESIZE' => $max_add_filesize,
+ 'S_FILESIZE' => size_select('add_size_select', $size),
+ 'S_ADD_DOWNLOAD_MODE' => download_select('add_download_mode'),
+ 'S_SELECT_CAT' => category_select('add_category'),
+ 'S_CANCEL_ACTION' => 'admin_extensions.php?mode=groups',
+ 'S_ATTACH_ACTION' => 'admin_extensions.php?mode=groups',
+ ));
- $sql = 'SELECT * FROM ' . BB_EXTENSION_GROUPS;
+ $sql = 'SELECT * FROM ' . BB_EXTENSION_GROUPS;
- if (!($result = DB()->sql_query($sql)))
- {
- bb_die('Could not get extension group informations');
- }
+ if (!($result = DB()->sql_query($sql))) {
+ bb_die('Could not get extension group informations');
+ }
- $extension_group = DB()->sql_fetchrowset($result);
- $num_extension_group = DB()->num_rows($result);
- DB()->sql_freeresult($result);
+ $extension_group = DB()->sql_fetchrowset($result);
+ $num_extension_group = DB()->num_rows($result);
+ DB()->sql_freeresult($result);
- for ($i = 0; $i < $num_extension_group; $i++)
- {
- // Format the filesize
- if (!$extension_group[$i]['max_filesize'])
- {
- $extension_group[$i]['max_filesize'] = $attach_config['max_filesize'];
- }
+ for ($i = 0; $i < $num_extension_group; $i++) {
+ // Format the filesize
+ if (!$extension_group[$i]['max_filesize']) {
+ $extension_group[$i]['max_filesize'] = $attach_config['max_filesize'];
+ }
- $size_format = ($extension_group[$i]['max_filesize'] >= 1048576) ? 'mb' : ( ($extension_group[$i]['max_filesize'] >= 1024) ? 'kb' : 'b' );
+ $size_format = ($extension_group[$i]['max_filesize'] >= 1048576) ? 'mb' : (($extension_group[$i]['max_filesize'] >= 1024) ? 'kb' : 'b');
- if ( $extension_group[$i]['max_filesize'] >= 1048576)
- {
- $extension_group[$i]['max_filesize'] = round($extension_group[$i]['max_filesize'] / 1048576 * 100) / 100;
- }
- else if($extension_group[$i]['max_filesize'] >= 1024)
- {
- $extension_group[$i]['max_filesize'] = round($extension_group[$i]['max_filesize'] / 1024 * 100) / 100;
- }
+ if ($extension_group[$i]['max_filesize'] >= 1048576) {
+ $extension_group[$i]['max_filesize'] = round($extension_group[$i]['max_filesize'] / 1048576 * 100) / 100;
+ } elseif ($extension_group[$i]['max_filesize'] >= 1024) {
+ $extension_group[$i]['max_filesize'] = round($extension_group[$i]['max_filesize'] / 1024 * 100) / 100;
+ }
- $s_allowed = ($extension_group[$i]['allow_group'] == 1) ? 'checked="checked"' : '';
+ $s_allowed = ($extension_group[$i]['allow_group'] == 1) ? 'checked' : '';
- $template->assign_block_vars('grouprow', array(
- 'GROUP_ID' => $extension_group[$i]['group_id'],
- 'EXTENSION_GROUP' => $extension_group[$i]['group_name'],
- 'UPLOAD_ICON' => $extension_group[$i]['upload_icon'],
+ $template->assign_block_vars('grouprow', array(
+ 'GROUP_ID' => $extension_group[$i]['group_id'],
+ 'EXTENSION_GROUP' => $extension_group[$i]['group_name'],
+ 'UPLOAD_ICON' => $extension_group[$i]['upload_icon'],
- 'S_ALLOW_SELECTED' => $s_allowed,
- 'S_SELECT_CAT' => category_select('category_list[]', $extension_group[$i]['group_id']),
- 'S_DOWNLOAD_MODE' => download_select('download_mode_list[]', $extension_group[$i]['group_id']),
- 'S_FILESIZE' => size_select('size_select_list[]', $size_format),
+ 'S_ALLOW_SELECTED' => $s_allowed,
+ 'S_SELECT_CAT' => category_select('category_list[]', $extension_group[$i]['group_id']),
+ 'S_DOWNLOAD_MODE' => download_select('download_mode_list[]', $extension_group[$i]['group_id']),
+ 'S_FILESIZE' => size_select('size_select_list[]', $size_format),
- 'MAX_FILESIZE' => $extension_group[$i]['max_filesize'],
- 'CAT_BOX' => ( $viewgroup == $extension_group[$i]['group_id'] ) ? '+' : '-',
- 'U_VIEWGROUP' => ( $viewgroup == $extension_group[$i]['group_id'] ) ? "admin_extensions.php?mode=groups" : "admin_extensions.php?mode=groups&" . POST_GROUPS_URL . "=" . $extension_group[$i]['group_id'],
- 'U_FORUM_PERMISSIONS' => "admin_extensions.php?mode=$mode&e_mode=perm&e_group=" . $extension_group[$i]['group_id'],
- ));
+ 'MAX_FILESIZE' => $extension_group[$i]['max_filesize'],
+ 'CAT_BOX' => ($viewgroup == $extension_group[$i]['group_id']) ? '-' : '+',
+ 'U_VIEWGROUP' => ($viewgroup == $extension_group[$i]['group_id']) ? 'admin_extensions.php?mode=groups' : 'admin_extensions.php?mode=groups&' . POST_GROUPS_URL . '=' . $extension_group[$i]['group_id'],
+ 'U_FORUM_PERMISSIONS' => "admin_extensions.php?mode=$mode&e_mode=perm&e_group=" . $extension_group[$i]['group_id'],
+ ));
- if ($viewgroup && $viewgroup == $extension_group[$i]['group_id'])
- {
- $sql = 'SELECT comment, extension FROM ' . BB_EXTENSIONS . ' WHERE group_id = ' . (int) $viewgroup;
+ if ($viewgroup && $viewgroup == $extension_group[$i]['group_id']) {
+ $sql = 'SELECT comment, extension FROM ' . BB_EXTENSIONS . ' WHERE group_id = ' . (int)$viewgroup;
- if (!$result = DB()->sql_query($sql))
- {
- bb_die('Could not get extension informations #3');
- }
+ if (!$result = DB()->sql_query($sql)) {
+ bb_die('Could not get extension informations #3');
+ }
- $extension = DB()->sql_fetchrowset($result);
- $num_extension = DB()->num_rows($result);
- DB()->sql_freeresult($result);
+ $extension = DB()->sql_fetchrowset($result);
+ $num_extension = DB()->num_rows($result);
+ DB()->sql_freeresult($result);
- for ($j = 0; $j < $num_extension; $j++)
- {
- $template->assign_block_vars('grouprow.extensionrow', array(
- 'EXPLANATION' => $extension[$j]['comment'],
- 'EXTENSION' => $extension[$j]['extension'])
- );
- }
- }
- }
+ for ($j = 0; $j < $num_extension; $j++) {
+ $template->assign_block_vars('grouprow.extensionrow', array(
+ 'EXPLANATION' => $extension[$j]['comment'],
+ 'EXTENSION' => $extension[$j]['extension'])
+ );
+ }
+ }
+ }
}
-if ($e_mode == 'perm')
-{
- $group = get_var('e_group', 0);
+if ($e_mode == 'perm') {
+ $group = get_var('e_group', 0);
- $add_forum = (isset($_POST['add_forum'])) ? TRUE : FALSE;
- $delete_forum = (isset($_POST['del_forum'])) ? TRUE : FALSE;
-
- if (isset($_POST['close_perm']))
- {
- $e_mode = '';
- }
+ if (isset($_POST['close_perm'])) {
+ $e_mode = '';
+ }
}
// Add Forums
-if (@$add_forum && $e_mode == 'perm' && $group)
-{
- $add_forums_list = get_var('entries', array(0));
- $add_all_forums = FALSE;
+if ($add_forum && $e_mode == 'perm' && $group) {
+ $add_forums_list = get_var('entries', array(0));
+ $add_all_forums = false;
- for ($i = 0; $i < sizeof($add_forums_list); $i++)
- {
- if ($add_forums_list[$i] == 0)
- {
- $add_all_forums = TRUE;
- }
- }
+ foreach ($add_forums_list as $iValue) {
+ if ($iValue == 0) {
+ $add_all_forums = true;
+ }
+ }
- // If we add ALL FORUMS, we are able to overwrite the Permissions
- if ($add_all_forums)
- {
- $sql = 'UPDATE ' . BB_EXTENSION_GROUPS . " SET forum_permissions = '' WHERE group_id = " . (int) $group;
- if (!($result = DB()->sql_query($sql)))
- {
- bb_die('Could not update permissions #1');
- }
- }
+ // If we add ALL FORUMS, we are able to overwrite the Permissions
+ if ($add_all_forums) {
+ $sql = 'UPDATE ' . BB_EXTENSION_GROUPS . " SET forum_permissions = '' WHERE group_id = " . (int)$group;
+ if (!($result = DB()->sql_query($sql))) {
+ bb_die('Could not update permissions #1');
+ }
+ }
- // Else we have to add Permissions
- if (!$add_all_forums)
- {
- $sql = 'SELECT forum_permissions
+ // Else we have to add Permissions
+ if (!$add_all_forums) {
+ $sql = 'SELECT forum_permissions
FROM ' . BB_EXTENSION_GROUPS . '
- WHERE group_id = ' . intval($group) . '
+ WHERE group_id = ' . (int)$group . '
LIMIT 1';
- if (!($result = DB()->sql_query($sql)))
- {
- bb_die('Could not get group permissions from ' . BB_EXTENSION_GROUPS);
- }
+ if (!($result = DB()->sql_query($sql))) {
+ bb_die('Could not get group permissions from ' . BB_EXTENSION_GROUPS);
+ }
- $row = DB()->sql_fetchrow($result);
- DB()->sql_freeresult($result);
+ $row = DB()->sql_fetchrow($result);
+ DB()->sql_freeresult($result);
- if (trim($row['forum_permissions']) == '')
- {
- $auth_p = array();
- }
- else
- {
- $auth_p = auth_unpack($row['forum_permissions']);
- }
+ if (trim($row['forum_permissions']) == '') {
+ $auth_p = [];
+ } else {
+ $auth_p = auth_unpack($row['forum_permissions']);
+ }
- // Generate array for Auth_Pack, do not add doubled forums
- for ($i = 0; $i < sizeof($add_forums_list); $i++)
- {
- if (!in_array($add_forums_list[$i], $auth_p))
- {
- $auth_p[] = $add_forums_list[$i];
- }
- }
+ // Generate array for Auth_Pack, do not add doubled forums
+ foreach ($add_forums_list as $i => $iValue) {
+ if (!in_array($add_forums_list[$i], $auth_p)) {
+ $auth_p[] = $iValue;
+ }
+ }
- $auth_bitstream = auth_pack($auth_p);
+ $auth_bitstream = auth_pack($auth_p);
- $sql = 'UPDATE ' . BB_EXTENSION_GROUPS . " SET forum_permissions = '" . attach_mod_sql_escape($auth_bitstream) . "' WHERE group_id = " . (int) $group;
-
- if (!($result = DB()->sql_query($sql)))
- {
- bb_die('Could not update permissions #2');
- }
- }
+ $sql = 'UPDATE ' . BB_EXTENSION_GROUPS . " SET forum_permissions = '" . DB()->escape($auth_bitstream) . "' WHERE group_id = " . (int)$group;
+ if (!($result = DB()->sql_query($sql))) {
+ bb_die('Could not update permissions #2');
+ }
+ }
}
// Delete Forums
-if (@$delete_forum && $e_mode == 'perm' && $group)
-{
- $delete_forums_list = get_var('entries', array(0));
+if ($delete_forum && $e_mode == 'perm' && $group) {
+ $delete_forums_list = get_var('entries', array(0));
- // Get the current Forums
- $sql = 'SELECT forum_permissions
+ // Get the current Forums
+ $sql = 'SELECT forum_permissions
FROM ' . BB_EXTENSION_GROUPS . '
- WHERE group_id = ' . intval($group) . '
+ WHERE group_id = ' . (int)$group . '
LIMIT 1';
- if (!($result = DB()->sql_query($sql)))
- {
- bb_die('Could not get group permissions from ' . BB_EXTENSION_GROUPS);
- }
+ if (!($result = DB()->sql_query($sql))) {
+ bb_die('Could not get group permissions from ' . BB_EXTENSION_GROUPS);
+ }
- $row = DB()->sql_fetchrow($result);
- DB()->sql_freeresult($result);
+ $row = DB()->sql_fetchrow($result);
+ DB()->sql_freeresult($result);
- $auth_p2 = auth_unpack(trim($row['forum_permissions']));
- $auth_p = array();
+ $auth_p2 = auth_unpack(trim($row['forum_permissions']));
+ $auth_p = [];
- // Generate array for Auth_Pack, delete the chosen ones
- for ($i = 0; $i < sizeof($auth_p2); $i++)
- {
- if (!in_array($auth_p2[$i], $delete_forums_list))
- {
- $auth_p[] = $auth_p2[$i];
- }
- }
+ // Generate array for Auth_Pack, delete the chosen ones
+ foreach ($auth_p2 as $i => $iValue) {
+ if (!in_array($auth_p2[$i], $delete_forums_list)) {
+ $auth_p[] = $iValue;
+ }
+ }
- $auth_bitstream = (sizeof($auth_p) > 0) ? auth_pack($auth_p) : '';
+ $auth_bitstream = (count($auth_p) > 0) ? auth_pack($auth_p) : '';
- $sql = 'UPDATE ' . BB_EXTENSION_GROUPS . " SET forum_permissions = '" . attach_mod_sql_escape($auth_bitstream) . "' WHERE group_id = " . (int) $group;
+ $sql = 'UPDATE ' . BB_EXTENSION_GROUPS . " SET forum_permissions = '" . DB()->escape($auth_bitstream) . "' WHERE group_id = " . (int)$group;
- if (!($result = DB()->sql_query($sql)))
- {
- bb_die('Could not update permissions #3');
- }
+ if (!($result = DB()->sql_query($sql))) {
+ bb_die('Could not update permissions #3');
+ }
}
// Display the Group Permissions Box for configuring it
-if ($e_mode == 'perm' && $group)
-{
- $sql = 'SELECT group_name, forum_permissions
+if ($e_mode == 'perm' && $group) {
+ $sql = 'SELECT group_name, forum_permissions
FROM ' . BB_EXTENSION_GROUPS . '
- WHERE group_id = ' . intval($group) . '
+ WHERE group_id = ' . (int)$group . '
LIMIT 1';
- if (!($result = DB()->sql_query($sql)))
- {
- bb_die('Could not get group name from ' . BB_EXTENSION_GROUPS);
- }
+ if (!($result = DB()->sql_query($sql))) {
+ bb_die('Could not get group name from ' . BB_EXTENSION_GROUPS);
+ }
- $row = DB()->sql_fetchrow($result);
- DB()->sql_freeresult($result);
+ $row = DB()->sql_fetchrow($result);
+ DB()->sql_freeresult($result);
- $group_name = $row['group_name'];
- $allowed_forums = trim($row['forum_permissions']);
+ $group_name = $row['group_name'];
+ $allowed_forums = trim($row['forum_permissions']);
- $forum_perm = array();
+ $forum_perm = [];
- if ($allowed_forums == '')
- {
- $forum_perm[0]['forum_id'] = 0;
- $forum_perm[0]['forum_name'] = $lang['PERM_ALL_FORUMS'];
- }
- else
- {
- $forum_p = array();
- $act_id = 0;
- $forum_p = auth_unpack($allowed_forums);
- $sql = "SELECT forum_id, forum_name FROM " . BB_FORUMS . " WHERE forum_id IN (" . implode(', ', $forum_p) . ")";
- if (!($result = DB()->sql_query($sql)))
- {
- bb_die('Could not get forum names');
- }
+ if ($allowed_forums == '') {
+ $forum_perm[0]['forum_id'] = 0;
+ $forum_perm[0]['forum_name'] = $lang['PERM_ALL_FORUMS'];
+ } else {
+ $forum_p = [];
+ $act_id = 0;
+ $forum_p = auth_unpack($allowed_forums);
+ $sql = 'SELECT forum_id, forum_name FROM ' . BB_FORUMS . ' WHERE forum_id IN (' . implode(', ', $forum_p) . ')';
+ if (!($result = DB()->sql_query($sql))) {
+ bb_die('Could not get forum names');
+ }
- while ($row = DB()->sql_fetchrow($result))
- {
- $forum_perm[$act_id]['forum_id'] = $row['forum_id'];
- $forum_perm[$act_id]['forum_name'] = $row['forum_name'];
- $act_id++;
- }
- }
+ while ($row = DB()->sql_fetchrow($result)) {
+ $forum_perm[$act_id]['forum_id'] = $row['forum_id'];
+ $forum_perm[$act_id]['forum_name'] = $row['forum_name'];
+ $act_id++;
+ }
+ }
- for ($i = 0; $i < sizeof($forum_perm); $i++)
- {
- $template->assign_block_vars('allow_option_values', array(
- 'VALUE' => $forum_perm[$i]['forum_id'],
- 'OPTION' => htmlCHR($forum_perm[$i]['forum_name']))
- );
- }
+ for ($i = 0, $iMax = count($forum_perm); $i < $iMax; $i++) {
+ $template->assign_block_vars('allow_option_values', array(
+ 'VALUE' => $forum_perm[$i]['forum_id'],
+ 'OPTION' => htmlCHR($forum_perm[$i]['forum_name']))
+ );
+ }
- $template->assign_vars(array(
- 'TPL_ATTACH_EXTENSION_GROUPS_PERMISSIONS' => true,
- 'L_GROUP_PERMISSIONS_TITLE' => sprintf($lang['GROUP_PERMISSIONS_TITLE_ADMIN'], trim($group_name)),
- 'A_PERM_ACTION' => "admin_extensions.php?mode=groups&e_mode=perm&e_group=$group",
- ));
+ $template->assign_vars(array(
+ 'TPL_ATTACH_EXTENSION_GROUPS_PERMISSIONS' => true,
+ 'L_GROUP_PERMISSIONS_TITLE' => sprintf($lang['GROUP_PERMISSIONS_TITLE_ADMIN'], trim($group_name)),
+ 'A_PERM_ACTION' => "admin_extensions.php?mode=groups&e_mode=perm&e_group=$group",
+ ));
- $forum_option_values = array(0 => $lang['PERM_ALL_FORUMS']);
+ $forum_option_values = array(0 => $lang['PERM_ALL_FORUMS']);
- $sql = "SELECT forum_id, forum_name FROM " . BB_FORUMS;
+ $sql = 'SELECT forum_id, forum_name FROM ' . BB_FORUMS;
- if (!($result = DB()->sql_query($sql)))
- {
- bb_die('Could not get forums #1');
- }
+ if (!($result = DB()->sql_query($sql))) {
+ bb_die('Could not get forums #1');
+ }
- while ($row = DB()->sql_fetchrow($result))
- {
- $forum_option_values[intval($row['forum_id'])] = $row['forum_name'];
- }
- DB()->sql_freeresult($result);
+ while ($row = DB()->sql_fetchrow($result)) {
+ $forum_option_values[(int)$row['forum_id']] = $row['forum_name'];
+ }
+ DB()->sql_freeresult($result);
- foreach ($forum_option_values as $value => $option)
- {
- $template->assign_block_vars('forum_option_values', array(
- 'VALUE' => $value,
- 'OPTION' => htmlCHR($option))
- );
- }
+ foreach ($forum_option_values as $value => $option) {
+ $template->assign_block_vars('forum_option_values', array(
+ 'VALUE' => $value,
+ 'OPTION' => htmlCHR($option))
+ );
+ }
- $empty_perm_forums = array();
+ $empty_perm_forums = [];
- $sql = "SELECT forum_id, forum_name FROM " . BB_FORUMS . " WHERE auth_attachments < " . AUTH_ADMIN;
+ $sql = 'SELECT forum_id, forum_name FROM ' . BB_FORUMS . ' WHERE auth_attachments < ' . AUTH_ADMIN;
- if (!($f_result = DB()->sql_query($sql)))
- {
- bb_die('Could not get forums #2');
- }
+ if (!($f_result = DB()->sql_query($sql))) {
+ bb_die('Could not get forums #2');
+ }
- while ($row = DB()->sql_fetchrow($f_result))
- {
- $forum_id = $row['forum_id'];
+ while ($row = DB()->sql_fetchrow($f_result)) {
+ $forum_id = $row['forum_id'];
- $sql = "SELECT forum_permissions
- FROM " . BB_EXTENSION_GROUPS . "
+ $sql = 'SELECT forum_permissions
+ FROM ' . BB_EXTENSION_GROUPS . '
WHERE allow_group = 1
- ORDER BY group_name ASC";
+ ORDER BY group_name ASC';
- if (!($result = DB()->sql_query($sql)))
- {
- bb_die('Could not query extension groups');
- }
+ if (!($result = DB()->sql_query($sql))) {
+ bb_die('Could not query extension groups');
+ }
- $rows = DB()->sql_fetchrowset($result);
- $num_rows = DB()->num_rows($result);
- DB()->sql_freeresult($result);
+ $rows = DB()->sql_fetchrowset($result);
+ $num_rows = DB()->num_rows($result);
+ DB()->sql_freeresult($result);
- $found_forum = FALSE;
+ $found_forum = false;
- for ($i = 0; $i < $num_rows; $i++)
- {
- $allowed_forums = auth_unpack(trim($rows[$i]['forum_permissions']));
- if (in_array($forum_id, $allowed_forums) || trim($rows[$i]['forum_permissions']) == '')
- {
- $found_forum = TRUE;
- break;
- }
- }
+ for ($i = 0; $i < $num_rows; $i++) {
+ $allowed_forums = auth_unpack(trim($rows[$i]['forum_permissions']));
+ if (in_array($forum_id, $allowed_forums) || trim($rows[$i]['forum_permissions']) == '') {
+ $found_forum = true;
+ break;
+ }
+ }
- if (!$found_forum)
- {
- $empty_perm_forums[$forum_id] = $row['forum_name'];
- }
- }
- DB()->sql_freeresult($f_result);
+ if (!$found_forum) {
+ $empty_perm_forums[$forum_id] = $row['forum_name'];
+ }
+ }
+ DB()->sql_freeresult($f_result);
- $message = '';
+ $message = '';
- foreach ($empty_perm_forums as $forum_id => $forum_name)
- {
- $message .= ( $message == '' ) ? $forum_name : ' ' . $forum_name;
- }
+ foreach ($empty_perm_forums as $forum_id => $forum_name) {
+ $message .= ($message == '') ? $forum_name : ' ' . $forum_name;
+ }
- if (sizeof($empty_perm_forums) > 0)
- {
- $template->assign_vars(array('ERROR_MESSAGE' => $lang['NOTE_ADMIN_EMPTY_GROUP_PERMISSIONS'] . $message));
- }
+ if (count($empty_perm_forums) > 0) {
+ $template->assign_vars(array('ERROR_MESSAGE' => $lang['NOTE_ADMIN_EMPTY_GROUP_PERMISSIONS'] . $message));
+ }
}
-if (@$error)
-{
- $template->assign_vars(array('ERROR_MESSAGE' => $error_msg));
+if ($error) {
+ $template->assign_vars(array('ERROR_MESSAGE' => $error_msg));
}
-print_page('admin_extensions.tpl', 'admin');
\ No newline at end of file
+print_page('admin_extensions.tpl', 'admin');
diff --git a/admin/admin_forum_prune.php b/admin/admin_forum_prune.php
index 86e8968e3..97a3a539b 100644
--- a/admin/admin_forum_prune.php
+++ b/admin/admin_forum_prune.php
@@ -1,60 +1,61 @@
fetch_rowset($sql) as $i => $row)
- {
- $pruned_topics = topic_delete('prune', $row['forum_id'], $prunetime, !empty($_POST['prune_all_topic_types']));
- $pruned_total += $pruned_topics;
- $prune_performed = true;
+ foreach (DB()->fetch_rowset($sql) as $i => $row) {
+ $pruned_topics = \TorrentPier\Legacy\Admin\Common::topic_delete('prune', $row['forum_id'], $prunetime, !empty($_POST['prune_all_topic_types']));
+ $pruned_total += $pruned_topics;
+ $prune_performed = true;
- $template->assign_block_vars('pruned', array(
- 'ROW_CLASS' => !($i % 2) ? 'row1' : 'row2',
- 'FORUM_NAME' => htmlCHR($row['forum_name']),
- 'PRUNED_TOPICS' => $pruned_topics,
- ));
- }
- if (!$prune_performed)
- {
- bb_die($lang['NONE_SELECTED']);
- }
- if (!$pruned_total)
- {
- bb_die($lang['NO_SEARCH_MATCH']);
- }
+ $template->assign_block_vars('pruned', [
+ 'ROW_CLASS' => !($i % 2) ? 'row1' : 'row2',
+ 'FORUM_NAME' => htmlCHR($row['forum_name']),
+ 'PRUNED_TOPICS' => $pruned_topics
+ ]);
+ }
+ if (!$prune_performed) {
+ bb_die($lang['NONE_SELECTED']);
+ }
+ if (!$pruned_total) {
+ bb_die($lang['NO_SEARCH_MATCH']);
+ }
}
-$template->assign_vars(array(
- 'PRUNED_TOTAL' => $pruned_total,
- 'S_PRUNE_ACTION' => basename(__FILE__),
- 'SEL_FORUM' => get_forum_select('admin', 'f[]', null, 65, 16, '', $all_forums),
-));
+$template->assign_vars([
+ 'PRUNED_TOTAL' => $pruned_total,
+ 'S_PRUNE_ACTION' => basename(__FILE__),
+ 'SEL_FORUM' => get_forum_select('admin', 'f[]', null, 65, 16, '', $all_forums)
+]);
-print_page('admin_forum_prune.tpl', 'admin');
\ No newline at end of file
+print_page('admin_forum_prune.tpl', 'admin');
diff --git a/admin/admin_forumauth.php b/admin/admin_forumauth.php
index f4798d3dc..fec7aa909 100644
--- a/admin/admin_forumauth.php
+++ b/admin/admin_forumauth.php
@@ -1,252 +1,228 @@
array(AUTH_ALL, AUTH_ALL, AUTH_ALL, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_ALL, AUTH_ALL, AUTH_MOD, AUTH_MOD), // Public
-/* Reg */ 1 => array(AUTH_ALL, AUTH_ALL, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_MOD, AUTH_MOD), // Registered
-/* Reg [Hid] */ 2 => array(AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_MOD, AUTH_MOD), // Registered [Hidden]
-/* Priv */ 3 => array(AUTH_REG, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_MOD, AUTH_MOD), // Private
-/* Priv [Hid] */ 4 => array(AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_MOD, AUTH_MOD), // Private [Hidden]
-/* MOD */ 5 => array(AUTH_REG, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD), // Moderators
-/* MOD [Hid] */ 6 => array(AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD), // Moderators [Hidden]
-);
+$simple_auth_ary = [
+ 0 => [AUTH_ALL, AUTH_ALL, AUTH_ALL, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_ALL, AUTH_ALL, AUTH_MOD, AUTH_MOD], // Public
+ 1 => [AUTH_ALL, AUTH_ALL, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_MOD, AUTH_MOD], // Registered
+ 2 => [AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_MOD, AUTH_MOD], // Registered [Hidden]
+ 3 => [AUTH_REG, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_MOD, AUTH_MOD], // Private
+ 4 => [AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_MOD, AUTH_MOD], // Private [Hidden]
+ 5 => [AUTH_REG, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD], // Moderators
+ 6 => [AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD], // Moderators [Hidden]
+];
-$simple_auth_types = array(
- $lang['PUBLIC'],
- $lang['REGISTERED'],
- $lang['REGISTERED'] .' ['. $lang['HIDDEN'] .']',
- $lang['PRIVATE'],
- $lang['PRIVATE'] .' ['. $lang['HIDDEN'] .']',
- $lang['MODERATORS'],
- $lang['MODERATORS'] .' ['. $lang['HIDDEN'] .']',
-);
+$simple_auth_types = [
+ $lang['PUBLIC'],
+ $lang['REGISTERED'],
+ $lang['REGISTERED'] . ' [' . $lang['HIDDEN'] . ']',
+ $lang['PRIVATE'],
+ $lang['PRIVATE'] . ' [' . $lang['HIDDEN'] . ']',
+ $lang['MODERATORS'],
+ $lang['MODERATORS'] . ' [' . $lang['HIDDEN'] . ']',
+];
-$field_names = array();
-foreach ($forum_auth_fields as $auth_type)
-{
- $field_names[$auth_type] = $lang[strtoupper($auth_type)];
+$field_names = [];
+foreach ($forum_auth_fields as $auth_type) {
+ $field_names[$auth_type] = $lang[strtoupper($auth_type)];
}
-$forum_auth_levels = array('ALL', 'REG', 'PRIVATE', 'MOD', 'ADMIN');
-$forum_auth_const = array(AUTH_ALL, AUTH_REG, AUTH_ACL, AUTH_MOD, AUTH_ADMIN);
+$forum_auth_levels = ['ALL', 'REG', 'PRIVATE', 'MOD', 'ADMIN'];
+$forum_auth_const = [AUTH_ALL, AUTH_REG, AUTH_ACL, AUTH_MOD, AUTH_ADMIN];
-if (@$_REQUEST[POST_FORUM_URL])
-{
- $forum_id = (int) $_REQUEST[POST_FORUM_URL];
- $forum_sql = "WHERE forum_id = $forum_id";
-}
-else
-{
- unset($forum_id);
- $forum_sql = '';
+if (isset($_REQUEST[POST_FORUM_URL])) {
+ $forum_id = (int)$_REQUEST[POST_FORUM_URL];
+ $forum_sql = "WHERE forum_id = $forum_id";
+} else {
+ unset($forum_id);
+ $forum_sql = '';
}
-if( isset($_GET['adv']) )
-{
- $adv = intval($_GET['adv']);
-}
-else
-{
- unset($adv);
+if (isset($_GET['adv'])) {
+ $adv = (int)$_GET['adv'];
+} else {
+ unset($adv);
}
-//
-// Start program proper
-//
-if( isset($_POST['submit']) )
-{
- $sql = '';
+$submit = isset($_POST['submit']);
- if(!empty($forum_id))
- {
- if(isset($_POST['simpleauth']))
- {
- $simple_ary = $simple_auth_ary[intval($_POST['simpleauth'])];
-
- for($i = 0; $i < count($simple_ary); $i++)
- {
- $sql .= ( ( $sql != '' ) ? ', ' : '' ) . $forum_auth_fields[$i] . ' = ' . $simple_ary[$i];
- }
-
- if (is_array($simple_ary))
- {
- $sql = "UPDATE " . BB_FORUMS . " SET $sql WHERE forum_id = $forum_id";
- }
- }
- else
- {
- for ($i = 0; $i < count($forum_auth_fields); $i++)
- {
- $value = intval($_POST[$forum_auth_fields[$i]]);
-
- if ($forum_auth_fields[$i] == 'auth_vote')
- {
- if ($_POST['auth_vote'] == AUTH_ALL)
- {
- $value = AUTH_REG;
- }
- }
-
- $sql .= ( ( $sql != '' ) ? ', ' : '' ) .$forum_auth_fields[$i] . ' = ' . $value;
- }
-
- $sql = "UPDATE " . BB_FORUMS . " SET $sql WHERE forum_id = $forum_id";
- }
-
- if ($sql != '')
- {
- if (!DB()->sql_query($sql))
- {
- bb_die('Could not update auth table');
- }
- }
-
- $forum_sql = '';
- $adv = 0;
- }
-
- $datastore->update('cat_forums');
- bb_die($lang['FORUM_AUTH_UPDATED'] . ' ' . sprintf($lang['CLICK_RETURN_FORUMAUTH'], '', " "));
-
-} // End of submit
-
-//
-// Get required information, either all forums if
-// no id was specified or just the requsted if it
-// was
-//
-$forum_rows = DB()->fetch_rowset("SELECT * FROM ". BB_FORUMS ." $forum_sql");
-
-if (empty($forum_id))
-{
- // Output the selection table if no forum id was specified
- $template->assign_vars(array(
- 'TPL_AUTH_SELECT_FORUM' => true,
- 'S_AUTH_ACTION' => 'admin_forumauth.php',
- 'S_AUTH_SELECT' => get_forum_select('admin', 'f', null, 80),
- ));
-
-}
-else
-{
- // Output the authorisation details if an id was specified
- $forum_name = $forum_rows[0]['forum_name'];
-
- @reset($simple_auth_ary);
- while (list($key, $auth_levels) = each($simple_auth_ary))
- {
- $matched = 1;
- for ($k = 0; $k < count($auth_levels); $k++)
- {
- $matched_type = $key;
-
- if ($forum_rows[0][$forum_auth_fields[$k]] != $auth_levels[$k])
- {
- $matched = 0;
- }
- }
-
- if ( $matched )
- {
- break;
- }
- }
-
- //
- // If we didn't get a match above then we
- // automatically switch into 'advanced' mode
- //
- if ( !isset($adv) && !$matched )
- {
- $adv = 1;
- }
-
- $s_column_span = 0;
-
- if (empty($adv))
- {
- $simple_auth = '';
-
- for($j = 0; $j < count($simple_auth_types); $j++)
- {
- $selected = ( $matched_type == $j ) ? ' selected="selected"' : '';
- $simple_auth .= '' . $simple_auth_types[$j] . ' ';
- }
-
- $simple_auth .= ' ';
-
- $template->assign_block_vars('forum_auth', array(
- 'CELL_TITLE' => $lang['SIMPLE_MODE'],
- 'S_AUTH_LEVELS_SELECT' => $simple_auth,
- ));
-
- $s_column_span++;
- }
- else
- {
- //
- // Output values of individual
- // fields
- //
- for ($j = 0; $j < count($forum_auth_fields); $j++)
- {
- $custom_auth[$j] = ' ';
-
- for ($k = 0; $k < count($forum_auth_levels); $k++)
- {
- $selected = ( $forum_rows[0][$forum_auth_fields[$j]] == $forum_auth_const[$k] ) ? ' selected="selected"' : '';
- $custom_auth[$j] .= '' . $lang['FORUM_' . strtoupper($forum_auth_levels[$k])] . ' ';
- }
- $custom_auth[$j] .= ' ';
-
- $cell_title = $field_names[$forum_auth_fields[$j]];
-
- $template->assign_block_vars('forum_auth', array(
- 'CELL_TITLE' => $cell_title,
- 'S_AUTH_LEVELS_SELECT' => $custom_auth[$j],
- ));
-
- $s_column_span++;
- }
- }
-
- $adv_mode = ( empty($adv) ) ? '1' : '0';
- $switch_mode = "admin_forumauth.php?f=$forum_id&adv=$adv_mode";
- $switch_mode_text = ( empty($adv) ) ? $lang['ADVANCED_MODE'] : $lang['SIMPLE_MODE'];
- $u_switch_mode = '' . $switch_mode_text . ' ';
-
- $s_hidden_fields = ' ';
-
- $template->assign_vars(array(
- 'TPL_EDIT_FORUM_AUTH' => true,
- 'FORUM_NAME' => htmlCHR($forum_name),
- 'U_SWITCH_MODE' => $u_switch_mode,
- 'S_FORUMAUTH_ACTION' => 'admin_forumauth.php',
- 'S_COLUMN_SPAN' => $s_column_span,
- 'S_HIDDEN_FIELDS' => $s_hidden_fields,
- ));
+// Check for demo mode
+if (IN_DEMO_MODE && $submit) {
+ bb_die($lang['CANT_EDIT_IN_DEMO_MODE']);
}
-print_page('admin_forumauth.tpl', 'admin');
\ No newline at end of file
+/**
+ * Start program proper
+ */
+if ($submit) {
+ $sql = '';
+
+ if (!empty($forum_id)) {
+ if (isset($_POST['simpleauth'])) {
+ $simple_ary = $simple_auth_ary[(int)$_POST['simpleauth']];
+
+ for ($i = 0, $iMax = count($simple_ary); $i < $iMax; $i++) {
+ $sql .= (($sql != '') ? ', ' : '') . $forum_auth_fields[$i] . ' = ' . $simple_ary[$i];
+ }
+
+ if (is_array($simple_ary)) {
+ $sql = 'UPDATE ' . BB_FORUMS . " SET $sql WHERE forum_id = $forum_id";
+ }
+ } else {
+ for ($i = 0, $iMax = count($forum_auth_fields); $i < $iMax; $i++) {
+ $value = (int)$_POST[$forum_auth_fields[$i]];
+
+ if ($forum_auth_fields[$i] == 'auth_vote') {
+ if ($_POST['auth_vote'] == AUTH_ALL) {
+ $value = AUTH_REG;
+ }
+ }
+
+ $sql .= (($sql != '') ? ', ' : '') . $forum_auth_fields[$i] . ' = ' . $value;
+ }
+
+ $sql = 'UPDATE ' . BB_FORUMS . " SET $sql WHERE forum_id = $forum_id";
+ }
+
+ if ($sql != '') {
+ if (!DB()->sql_query($sql)) {
+ bb_die('Could not update auth table');
+ }
+ }
+
+ $forum_sql = '';
+ $adv = 0;
+ }
+
+ $datastore->update('cat_forums');
+ CACHE('bb_cache')->rm();
+ bb_die($lang['FORUM_AUTH_UPDATED'] . ' ' . sprintf($lang['CLICK_RETURN_FORUMAUTH'], '', ' '));
+}
+
+/**
+ * Get required information
+ */
+$forum_rows = DB()->fetch_rowset('SELECT * FROM ' . BB_FORUMS . " $forum_sql");
+
+if (empty($forum_id)) {
+ // Output the selection table if no forum id was specified
+ $template->assign_vars([
+ 'TPL_AUTH_SELECT_FORUM' => true,
+ 'S_AUTH_ACTION' => 'admin_forumauth.php',
+ 'S_AUTH_SELECT' => get_forum_select('admin', 'f', null, 80),
+ ]);
+} else {
+ // Output the authorisation details if an id was specified
+ $forum_name = reset($forum_rows)['forum_name'];
+
+ reset($simple_auth_ary);
+ foreach ($simple_auth_ary as $key => $auth_levels) {
+ $matched = 1;
+ for ($k = 0, $kMax = count($auth_levels); $k < $kMax; $k++) {
+ $matched_type = $key;
+
+ if ($forum_rows[0][$forum_auth_fields[$k]] != $auth_levels[$k]) {
+ $matched = 0;
+ }
+ }
+
+ if ($matched) {
+ break;
+ }
+ }
+
+ //
+ // If we didn't get a match above then we
+ // automatically switch into 'advanced' mode
+ //
+ if (!isset($adv) && !$matched) {
+ $adv = 1;
+ }
+
+ $s_column_span = 0;
+
+ if (empty($adv)) {
+ $simple_auth = '';
+
+ for ($j = 0, $jMax = count($simple_auth_types); $j < $jMax; $j++) {
+ $selected = ($matched_type == $j) ? ' selected' : '';
+ $simple_auth .= '' . $simple_auth_types[$j] . ' ';
+ }
+
+ $simple_auth .= ' ';
+
+ $template->assign_block_vars('forum_auth', [
+ 'CELL_TITLE' => $lang['SIMPLE_MODE'],
+ 'S_AUTH_LEVELS_SELECT' => $simple_auth,
+ ]);
+
+ $s_column_span++;
+ } else {
+ // Output values of individual fields
+ for ($j = 0, $jMax = count($forum_auth_fields); $j < $jMax; $j++) {
+ $custom_auth[$j] = ' ';
+
+ for ($k = 0, $kMax = count($forum_auth_levels); $k < $kMax; $k++) {
+ $selected = ($forum_rows[0][$forum_auth_fields[$j]] == $forum_auth_const[$k]) ? ' selected' : '';
+ $custom_auth[$j] .= '' . $lang['FORUM_' . strtoupper($forum_auth_levels[$k])] . ' ';
+ }
+ $custom_auth[$j] .= ' ';
+
+ $cell_title = $field_names[$forum_auth_fields[$j]];
+
+ $template->assign_block_vars('forum_auth', [
+ 'CELL_TITLE' => $cell_title,
+ 'S_AUTH_LEVELS_SELECT' => $custom_auth[$j],
+ ]);
+
+ $s_column_span++;
+ }
+ }
+
+ $adv_mode = empty($adv) ? '1' : '0';
+ $switch_mode = "admin_forumauth.php?" . POST_FORUM_URL . "=$forum_id&adv=$adv_mode";
+ $switch_mode_text = empty($adv) ? $lang['ADVANCED_MODE'] : $lang['SIMPLE_MODE'];
+ $u_switch_mode = '' . $switch_mode_text . ' ';
+
+ $s_hidden_fields = ' ';
+
+ $template->assign_vars([
+ 'TPL_EDIT_FORUM_AUTH' => true,
+ 'FORUM_NAME' => htmlCHR($forum_name),
+ 'U_VIEWFORUM' => BB_ROOT . FORUM_URL . $forum_id,
+ 'U_SWITCH_MODE' => $u_switch_mode,
+ 'S_FORUMAUTH_ACTION' => 'admin_forumauth.php',
+ 'S_COLUMN_SPAN' => $s_column_span,
+ 'S_HIDDEN_FIELDS' => $s_hidden_fields,
+ ]);
+}
+
+print_page('admin_forumauth.tpl', 'admin');
diff --git a/admin/admin_forumauth_list.php b/admin/admin_forumauth_list.php
index b8c8a7188..37c49d251 100644
--- a/admin/admin_forumauth_list.php
+++ b/admin/admin_forumauth_list.php
@@ -1,175 +1,160 @@
array(AUTH_ALL, AUTH_ALL, AUTH_ALL, AUTH_ALL, AUTH_REG, AUTH_REG, AUTH_MOD, AUTH_MOD, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_ALL), // Public
-/* Reg */ 1 => array(AUTH_ALL, AUTH_ALL, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_MOD, AUTH_MOD, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG), // Registered
-/* Reg [Hid] */ 2 => array(AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_MOD, AUTH_MOD, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG), // Registered [Hidden]
-/* Priv */ 3 => array(AUTH_REG, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_MOD, AUTH_MOD, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL), // Private
-/* Priv [Hid] */ 4 => array(AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_MOD, AUTH_MOD, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL), // Private [Hidden]
-/* MOD */ 5 => array(AUTH_REG, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD), // Moderators
-/* MOD [Hid] */ 6 => array(AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD), // Moderators [Hidden]
-);
+$simple_auth_ary = [
+ 0 => [AUTH_ALL, AUTH_ALL, AUTH_ALL, AUTH_ALL, AUTH_REG, AUTH_REG, AUTH_MOD, AUTH_MOD, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_ALL], // Public
+ 1 => [AUTH_ALL, AUTH_ALL, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_MOD, AUTH_MOD, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG], // Registered
+ 2 => [AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_MOD, AUTH_MOD, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG], // Registered [Hidden]
+ 3 => [AUTH_REG, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_MOD, AUTH_MOD, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL], // Private
+ 4 => [AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_MOD, AUTH_MOD, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL], // Private [Hidden]
+ 5 => [AUTH_REG, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD], // Moderators
+ 6 => [AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD], // Moderators [Hidden]
+];
-$simple_auth_types = array(
- $lang['PUBLIC'],
- $lang['REGISTERED'],
- $lang['REGISTERED'] .' ['. $lang['HIDDEN'] .']',
- $lang['PRIVATE'],
- $lang['PRIVATE'] .' ['. $lang['HIDDEN'] .']',
- $lang['MODERATORS'],
- $lang['MODERATORS'] .' ['. $lang['HIDDEN'] .']',
-);
+$simple_auth_types = [
+ $lang['PUBLIC'],
+ $lang['REGISTERED'],
+ $lang['REGISTERED'] . ' [' . $lang['HIDDEN'] . ']',
+ $lang['PRIVATE'],
+ $lang['PRIVATE'] . ' [' . $lang['HIDDEN'] . ']',
+ $lang['MODERATORS'],
+ $lang['MODERATORS'] . ' [' . $lang['HIDDEN'] . ']',
+];
-$forum_auth_fields = array(
- 'auth_view',
- 'auth_read',
- 'auth_reply',
- 'auth_edit',
- 'auth_delete',
- 'auth_vote',
- 'auth_pollcreate',
- 'auth_attachments',
- 'auth_download',
- 'auth_post',
- 'auth_sticky',
- 'auth_announce',
-);
+$forum_auth_fields = [
+ 'auth_view',
+ 'auth_read',
+ 'auth_reply',
+ 'auth_edit',
+ 'auth_delete',
+ 'auth_vote',
+ 'auth_pollcreate',
+ 'auth_attachments',
+ 'auth_download',
+ 'auth_post',
+ 'auth_sticky',
+ 'auth_announce',
+];
-$field_names = array();
-foreach ($forum_auth_fields as $auth_type)
-{
- $field_names[$auth_type] = $lang[strtoupper($auth_type)];
+$field_names = [];
+foreach ($forum_auth_fields as $auth_type) {
+ $field_names[$auth_type] = $lang[strtoupper($auth_type)];
}
-$forum_auth_levels = array('ALL', 'REG', 'PRIVATE', 'MOD', 'ADMIN');
-$forum_auth_const = array(AUTH_ALL, AUTH_REG, AUTH_ACL, AUTH_MOD, AUTH_ADMIN);
+$forum_auth_levels = ['ALL', 'REG', 'PRIVATE', 'MOD', 'ADMIN'];
+$forum_auth_const = [AUTH_ALL, AUTH_REG, AUTH_ACL, AUTH_MOD, AUTH_ADMIN];
-if(isset($_GET[POST_FORUM_URL]) || isset($_POST[POST_FORUM_URL]))
-{
- $forum_id = (isset($_POST[POST_FORUM_URL])) ? intval($_POST[POST_FORUM_URL]) : intval($_GET[POST_FORUM_URL]);
- $forum_sql = "AND forum_id = $forum_id";
-}
-else
-{
- unset($forum_id);
- $forum_sql = '';
+if (isset($_GET[POST_FORUM_URL]) || isset($_POST[POST_FORUM_URL])) {
+ $forum_id = isset($_POST[POST_FORUM_URL]) ? (int)$_POST[POST_FORUM_URL] : (int)$_GET[POST_FORUM_URL];
+ $forum_sql = "AND forum_id = $forum_id";
+} else {
+ unset($forum_id);
+ $forum_sql = '';
}
-if(isset($_GET[POST_CAT_URL]) || isset($_POST[POST_CAT_URL]))
-{
- $cat_id = (isset($_POST[POST_CAT_URL])) ? intval($_POST[POST_CAT_URL]) : intval($_GET[POST_CAT_URL]);
- $cat_sql = "AND c.cat_id = $cat_id";
-}
-else
-{
- unset($cat_id);
- $cat_sql = '';
+if (isset($_GET[POST_CAT_URL]) || isset($_POST[POST_CAT_URL])) {
+ $cat_id = isset($_POST[POST_CAT_URL]) ? (int)$_POST[POST_CAT_URL] : (int)$_GET[POST_CAT_URL];
+ $cat_sql = "AND c.cat_id = $cat_id";
+} else {
+ unset($cat_id);
+ $cat_sql = '';
}
-if( isset($_GET['adv']) )
-{
- $adv = intval($_GET['adv']);
-}
-else
-{
- unset($adv);
+if (isset($_GET['adv'])) {
+ $adv = (int)$_GET['adv'];
+} else {
+ unset($adv);
}
-//
-// Start program proper
-//
-if( isset($_POST['submit']) )
-{
- $sql = '';
+$submit = isset($_POST['submit']);
- if(!empty($forum_id))
- {
- if(isset($_POST['simpleauth']))
- {
- $simple_ary = $simple_auth_ary[intval($_POST['simpleauth'])];
+// Check for demo mode
+if (IN_DEMO_MODE && $submit) {
+ bb_die($lang['CANT_EDIT_IN_DEMO_MODE']);
+}
- for($i = 0; $i < count($simple_ary); $i++)
- {
- $sql .= ( ( $sql != '' ) ? ', ' : '' ) . $forum_auth_fields[$i] . ' = ' . $simple_ary[$i];
- }
+/**
+ * Start program proper
+ */
+if ($submit) {
+ $sql = '';
- if (is_array($simple_ary))
- {
- $sql = "UPDATE " . BB_FORUMS . " SET $sql WHERE forum_id = $forum_id";
- }
- }
- else
- {
- for($i = 0; $i < count($forum_auth_fields); $i++)
- {
- $value = intval($_POST[$forum_auth_fields[$i]]);
+ if (!empty($forum_id)) {
+ if (isset($_POST['simpleauth'])) {
+ $simple_ary = $simple_auth_ary[(int)$_POST['simpleauth']];
- if ( $forum_auth_fields[$i] == 'auth_vote' )
- {
- if ( $_POST['auth_vote'] == AUTH_ALL )
- {
- $value = AUTH_REG;
- }
- }
+ for ($i = 0, $iMax = count($simple_ary); $i < $iMax; $i++) {
+ $sql .= (($sql != '') ? ', ' : '') . $forum_auth_fields[$i] . ' = ' . $simple_ary[$i];
+ }
- $sql .= ( ( $sql != '' ) ? ', ' : '' ) .$forum_auth_fields[$i] . ' = ' . $value;
- }
+ if (is_array($simple_ary)) {
+ $sql = 'UPDATE ' . BB_FORUMS . " SET $sql WHERE forum_id = $forum_id";
+ }
+ } else {
+ for ($i = 0, $iMax = count($forum_auth_fields); $i < $iMax; $i++) {
+ $value = (int)$_POST[$forum_auth_fields[$i]];
- $sql = "UPDATE " . BB_FORUMS . " SET $sql WHERE forum_id = $forum_id";
- }
+ if ($forum_auth_fields[$i] == 'auth_vote') {
+ if ($_POST['auth_vote'] == AUTH_ALL) {
+ $value = AUTH_REG;
+ }
+ }
- if ($sql != '')
- {
- if (!DB()->sql_query($sql))
- {
- bb_die('Could not update auth table #1');
- }
- }
+ $sql .= (($sql != '') ? ', ' : '') . $forum_auth_fields[$i] . ' = ' . $value;
+ }
- $forum_sql = '';
- $adv = 0;
- }
- elseif (!empty($cat_id))
- {
- for ($i = 0; $i < count($forum_auth_fields); $i++)
- {
- $value = intval($_POST[$forum_auth_fields[$i]]);
+ $sql = 'UPDATE ' . BB_FORUMS . " SET $sql WHERE forum_id = $forum_id";
+ }
- if ($forum_auth_fields[$i] == 'auth_vote')
- {
- if ( $_POST['auth_vote'] == AUTH_ALL )
- {
- $value = AUTH_REG;
- }
- }
+ if ($sql != '') {
+ if (!DB()->sql_query($sql)) {
+ bb_die('Could not update auth table #1');
+ }
+ }
- $sql .= ( ( $sql != '' ) ? ', ' : '' ) .$forum_auth_fields[$i] . ' = ' . $value;
- }
+ $forum_sql = '';
+ $adv = 0;
+ } elseif (!empty($cat_id)) {
+ for ($i = 0, $iMax = count($forum_auth_fields); $i < $iMax; $i++) {
+ $value = (int)$_POST[$forum_auth_fields[$i]];
- $sql = "UPDATE " . BB_FORUMS . " SET $sql WHERE cat_id = $cat_id";
+ if ($forum_auth_fields[$i] == 'auth_vote') {
+ if ($_POST['auth_vote'] == AUTH_ALL) {
+ $value = AUTH_REG;
+ }
+ }
- if ($sql != '')
- {
- if (!DB()->sql_query($sql))
- {
- bb_die('Could not update auth table #2');
- }
- }
+ $sql .= (($sql != '') ? ', ' : '') . $forum_auth_fields[$i] . ' = ' . $value;
+ }
- $cat_sql = '';
- }
+ $sql = 'UPDATE ' . BB_FORUMS . " SET $sql WHERE cat_id = $cat_id";
- $datastore->update('cat_forums');
- bb_die($lang['FORUM_AUTH_UPDATED'] . ' ' . sprintf($lang['CLICK_RETURN_FORUMAUTH'], '', " "));
+ if ($sql != '') {
+ if (!DB()->sql_query($sql)) {
+ bb_die('Could not update auth table #2');
+ }
+ }
+ $cat_sql = '';
+ }
+
+ $datastore->update('cat_forums');
+ CACHE('bb_cache')->rm();
+ bb_die($lang['FORUM_AUTH_UPDATED'] . ' ' . sprintf($lang['CLICK_RETURN_FORUMAUTH'], '', ' '));
} // End of submit
//
@@ -177,187 +162,166 @@ if( isset($_POST['submit']) )
// no id was specified or just the requsted forum
// or category if it was
//
-$sql = "SELECT f.*
- FROM " . BB_FORUMS . " f, " . BB_CATEGORIES . " c
+$sql = 'SELECT f.*
+ FROM ' . BB_FORUMS . ' f, ' . BB_CATEGORIES . " c
WHERE c.cat_id = f.cat_id
$forum_sql $cat_sql
ORDER BY c.cat_order ASC, f.forum_order ASC";
-if (!($result = DB()->sql_query($sql)))
-{
- bb_die('Could not obtain forum list');
+if (!($result = DB()->sql_query($sql))) {
+ bb_die('Could not obtain forum list');
}
$forum_rows = DB()->sql_fetchrowset($result);
DB()->sql_freeresult($result);
-if( empty($forum_id) && empty($cat_id) )
-{
- //
- // Output the summary list if no forum id was
- // specified
- //
- $template->assign_vars(array(
- 'TPL_AUTH_FORUM_LIST' => true,
- 'S_COLUMN_SPAN' => count($forum_auth_fields)+1,
- ));
+if (empty($forum_id) && empty($cat_id)) {
+ //
+ // Output the summary list if no forum id was
+ // specified
+ //
+ $template->assign_vars(array(
+ 'TPL_AUTH_FORUM_LIST' => true,
+ 'S_COLUMN_SPAN' => count($forum_auth_fields) + 1,
+ ));
- for ($i = 0; $iassign_block_vars('forum_auth_titles', array(
- 'CELL_TITLE' => $field_names[$forum_auth_fields[$i]],
- ));
- }
+ for ($i = 0, $iMax = count($forum_auth_fields); $i < $iMax; $i++) {
+ $template->assign_block_vars('forum_auth_titles', array(
+ 'CELL_TITLE' => $field_names[$forum_auth_fields[$i]],
+ ));
+ }
- // Obtain the category list
- $sql = "SELECT c.cat_id, c.cat_title, c.cat_order
- FROM " . BB_CATEGORIES . " c
- ORDER BY c.cat_order";
- if (!($result = DB()->sql_query($sql)))
- {
- bb_die('Could not query categories list #1');
- }
+ // Obtain the category list
+ $sql = 'SELECT c.cat_id, c.cat_title, c.cat_order
+ FROM ' . BB_CATEGORIES . ' c
+ ORDER BY c.cat_order';
+ if (!($result = DB()->sql_query($sql))) {
+ bb_die('Could not query categories list #1');
+ }
- $category_rows = DB()->sql_fetchrowset($result);
- $cat_count = count($category_rows);
+ $category_rows = DB()->sql_fetchrowset($result);
+ $cat_count = count($category_rows);
- for ($i=0; $i<$cat_count; $i++)
- {
- $cat_id = $category_rows[$i]['cat_id'];
+ for ($i = 0; $i < $cat_count; $i++) {
+ $cat_id = $category_rows[$i]['cat_id'];
- $template->assign_block_vars('cat_row', array(
- 'CAT_NAME' => htmlCHR($category_rows[$i]['cat_title']),
- 'CAT_URL' => 'admin_forumauth_list.php'.'?'.POST_CAT_URL.'='.$category_rows[$i]['cat_id'])
- );
+ $template->assign_block_vars('cat_row', array(
+ 'CAT_NAME' => htmlCHR($category_rows[$i]['cat_title']),
+ 'CAT_URL' => 'admin_forumauth_list.php' . '?' . POST_CAT_URL . '=' . $category_rows[$i]['cat_id'])
+ );
- for ($j=0; $jassign_block_vars('cat_row.forum_row', array(
- 'ROW_CLASS' => !($j % 2) ? 'row4' : 'row5',
- 'FORUM_NAME' => ''. htmlCHR($forum_rows[$j]['forum_name']) .' ',
- 'IS_SUBFORUM' => $forum_rows[$j]['forum_parent'],
- ));
+ for ($j = 0, $jMax = count($forum_rows); $j < $jMax; $j++) {
+ if ($cat_id == $forum_rows[$j]['cat_id']) {
+ $template->assign_block_vars('cat_row.forum_row', array(
+ 'ROW_CLASS' => !($j % 2) ? 'row4' : 'row5',
+ 'FORUM_NAME' => '' . htmlCHR($forum_rows[$j]['forum_name']) . ' ',
+ 'IS_SUBFORUM' => $forum_rows[$j]['forum_parent'],
+ ));
- for ($k=0; $kassign_block_vars('cat_row.forum_row.forum_auth_data', array(
- 'CELL_VALUE' => $lang['FORUM_' . $item_auth_level],
- 'AUTH_EXPLAIN' => sprintf($lang[strtoupper('FORUM_AUTH_LIST_EXPLAIN_' . $forum_auth_fields[$k])], $lang[strtoupper('FORUM_AUTH_LIST_EXPLAIN_' . $item_auth_level)]))
- );
- }
- }
- }
- }
-}
-else
-{
- //
- // output the authorisation details if an category id was
- // specified
- //
+ for ($k = 0, $kMax = count($forum_auth_fields); $k < $kMax; $k++) {
+ $item_auth_value = $forum_rows[$j][$forum_auth_fields[$k]];
+ for ($l = 0, $lMax = count($forum_auth_const); $l < $lMax; $l++) {
+ if ($item_auth_value == $forum_auth_const[$l]) {
+ $item_auth_level = $forum_auth_levels[$l];
+ break;
+ }
+ }
+ $template->assign_block_vars('cat_row.forum_row.forum_auth_data', array(
+ 'CELL_VALUE' => $lang['FORUM_' . $item_auth_level],
+ 'AUTH_EXPLAIN' => sprintf($lang[strtoupper('FORUM_AUTH_LIST_EXPLAIN_' . $forum_auth_fields[$k])], $lang[strtoupper('FORUM_AUTH_LIST_EXPLAIN_' . $item_auth_level)]))
+ );
+ }
+ }
+ }
+ }
+} else {
+ //
+ // output the authorisation details if an category id was
+ // specified
+ //
- //
- // first display the current details for all forums
- // in the category
- //
- for ($i = 0; $iassign_block_vars('forum_auth_titles', array(
- 'CELL_TITLE' => $field_names[$forum_auth_fields[$i]],
- ));
- }
+ //
+ // first display the current details for all forums
+ // in the category
+ //
+ for ($i = 0, $iMax = count($forum_auth_fields); $i < $iMax; $i++) {
+ $template->assign_block_vars('forum_auth_titles', array(
+ 'CELL_TITLE' => $field_names[$forum_auth_fields[$i]],
+ ));
+ }
- // obtain the category list
- $sql = "SELECT c.cat_id, c.cat_title, c.cat_order
- FROM " . BB_CATEGORIES . " c
+ // obtain the category list
+ $sql = 'SELECT c.cat_id, c.cat_title, c.cat_order
+ FROM ' . BB_CATEGORIES . " c
WHERE c.cat_id = $cat_id
ORDER BY c.cat_order";
- if (!($result = DB()->sql_query($sql)))
- {
- bb_die('Could not query categories list #2');
- }
+ if (!($result = DB()->sql_query($sql))) {
+ bb_die('Could not query categories list #2');
+ }
- $category_rows = DB()->sql_fetchrowset($result);
+ $category_rows = DB()->sql_fetchrowset($result);
- $cat_id = $category_rows[0]['cat_id'];
- $cat_name = $category_rows[0]['cat_title'];
+ $cat_id = reset($category_rows)['cat_id'];
+ $cat_name = reset($category_rows)['cat_title'];
- $template->assign_block_vars('cat_row', array(
- 'CAT_NAME' => htmlCHR($cat_name),
- 'CAT_URL' => 'admin_forumauth_list.php?'. POST_CAT_URL .'='. $cat_id)
- );
+ $template->assign_block_vars('cat_row', array(
+ 'CAT_NAME' => htmlCHR($cat_name),
+ 'CAT_URL' => 'admin_forumauth_list.php?' . POST_CAT_URL . '=' . $cat_id)
+ );
- for ($j=0; $jassign_block_vars('cat_row.forum_row', array(
- 'ROW_CLASS' => !($j % 2) ? 'row4' : 'row5',
- 'FORUM_NAME' => ''. htmlCHR($forum_rows[$j]['forum_name']) .' ',
- 'IS_SUBFORUM' => $forum_rows[$j]['forum_parent'],
- ));
+ for ($j = 0, $jMax = count($forum_rows); $j < $jMax; $j++) {
+ if ($cat_id == $forum_rows[$j]['cat_id']) {
+ $template->assign_block_vars('cat_row.forum_row', array(
+ 'ROW_CLASS' => !($j % 2) ? 'row4' : 'row5',
+ 'FORUM_NAME' => '' . htmlCHR($forum_rows[$j]['forum_name']) . ' ',
+ 'IS_SUBFORUM' => $forum_rows[$j]['forum_parent'],
+ ));
- for ($k=0; $kassign_block_vars('cat_row.forum_row.forum_auth_data', array(
- 'CELL_VALUE' => $lang['FORUM_' . $item_auth_level],
- 'AUTH_EXPLAIN' => sprintf($lang[strtoupper('FORUM_AUTH_LIST_EXPLAIN_' . $forum_auth_fields[$k])], $lang[strtoupper('FORUM_AUTH_LIST_EXPLAIN_' . $item_auth_level)]))
- );
- }
- }
- }
+ for ($k = 0, $kMax = count($forum_auth_fields); $k < $kMax; $k++) {
+ $item_auth_value = $forum_rows[$j][$forum_auth_fields[$k]];
+ for ($l = 0, $lMax = count($forum_auth_const); $l < $lMax; $l++) {
+ if ($item_auth_value == $forum_auth_const[$l]) {
+ $item_auth_level = $forum_auth_levels[$l];
+ break;
+ }
+ }
+ $template->assign_block_vars('cat_row.forum_row.forum_auth_data', array(
+ 'CELL_VALUE' => $lang['FORUM_' . $item_auth_level],
+ 'AUTH_EXPLAIN' => sprintf($lang[strtoupper('FORUM_AUTH_LIST_EXPLAIN_' . $forum_auth_fields[$k])], $lang[strtoupper('FORUM_AUTH_LIST_EXPLAIN_' . $item_auth_level)]))
+ );
+ }
+ }
+ }
- //
- // next generate the information to allow the permissions to be changed
- // note: we always read from the first forum in the category
- //
- for($j = 0; $j < count($forum_auth_fields); $j++)
- {
- $custom_auth[$j] = '';
+ //
+ // next generate the information to allow the permissions to be changed
+ // note: we always read from the first forum in the category
+ //
+ for ($j = 0, $jMax = count($forum_auth_fields); $j < $jMax; $j++) {
+ $custom_auth[$j] = '';
- for($k = 0; $k < count($forum_auth_levels); $k++)
- {
- $selected = ( !empty($forum_rows) && $forum_rows[0][$forum_auth_fields[$j]] == $forum_auth_const[$k] ) ? ' selected="selected"' : '';
- $custom_auth[$j] .= '' . $lang['FORUM_' . $forum_auth_levels[$k]] . ' ';
- }
- $custom_auth[$j] .= ' ';
+ for ($k = 0, $kMax = count($forum_auth_levels); $k < $kMax; $k++) {
+ $selected = (!empty($forum_rows) && $forum_rows[0][$forum_auth_fields[$j]] == $forum_auth_const[$k]) ? ' selected' : '';
+ $custom_auth[$j] .= '' . $lang['FORUM_' . $forum_auth_levels[$k]] . ' ';
+ }
+ $custom_auth[$j] .= ' ';
- $template->assign_block_vars('forum_auth_data', array(
- 'S_AUTH_LEVELS_SELECT' => $custom_auth[$j])
- );
- }
+ $template->assign_block_vars('forum_auth_data', array(
+ 'S_AUTH_LEVELS_SELECT' => $custom_auth[$j])
+ );
+ }
- //
- // finally pass any remaining items to the template
- //
- $s_hidden_fields = ' ';
+ //
+ // finally pass any remaining items to the template
+ //
+ $s_hidden_fields = ' ';
- $template->assign_vars(array(
- 'TPL_AUTH_CAT' => true,
- 'CAT_NAME' => htmlCHR($cat_name),
- 'S_FORUMAUTH_ACTION' => 'admin_forumauth_list.php',
- 'S_COLUMN_SPAN' => count($forum_auth_fields) + 1,
- 'S_HIDDEN_FIELDS' => $s_hidden_fields,
- ));
+ $template->assign_vars(array(
+ 'TPL_AUTH_CAT' => true,
+ 'CAT_NAME' => htmlCHR($cat_name),
+ 'S_FORUMAUTH_ACTION' => 'admin_forumauth_list.php',
+ 'S_COLUMN_SPAN' => count($forum_auth_fields) + 1,
+ 'S_HIDDEN_FIELDS' => $s_hidden_fields,
+ ));
}
-print_page('admin_forumauth_list.tpl', 'admin');
\ No newline at end of file
+print_page('admin_forumauth_list.tpl', 'admin');
diff --git a/admin/admin_forums.php b/admin/admin_forums.php
index eb2c56ae4..8a195bb64 100644
--- a/admin/admin_forums.php
+++ b/admin/admin_forums.php
@@ -1,302 +1,286 @@
AUTH_ALL,
- 'auth_read' => AUTH_ALL,
- 'auth_post' => AUTH_REG,
- 'auth_reply' => AUTH_REG,
- 'auth_edit' => AUTH_REG,
- 'auth_delete' => AUTH_REG,
- 'auth_sticky' => AUTH_MOD,
- 'auth_announce' => AUTH_MOD,
- 'auth_vote' => AUTH_REG,
- 'auth_pollcreate' => AUTH_REG,
- 'auth_attachments' => AUTH_REG,
- 'auth_download' => AUTH_REG,
-);
+$default_forum_auth = [
+ 'auth_view' => AUTH_ALL,
+ 'auth_read' => AUTH_ALL,
+ 'auth_post' => AUTH_REG,
+ 'auth_reply' => AUTH_REG,
+ 'auth_edit' => AUTH_REG,
+ 'auth_delete' => AUTH_REG,
+ 'auth_sticky' => AUTH_MOD,
+ 'auth_announce' => AUTH_MOD,
+ 'auth_vote' => AUTH_REG,
+ 'auth_pollcreate' => AUTH_REG,
+ 'auth_attachments' => AUTH_REG,
+ 'auth_download' => AUTH_REG,
+];
-$mode = (@$_REQUEST['mode']) ? (string) $_REQUEST['mode'] : '';
+$mode = isset($_REQUEST['mode']) ? (string)$_REQUEST['mode'] : '';
$cat_forums = get_cat_forums();
-if ($orphan_sf_sql = get_orphan_sf())
-{
- fix_orphan_sf($orphan_sf_sql, TRUE);
+if ($orphan_sf_sql = get_orphan_sf()) {
+ fix_orphan_sf($orphan_sf_sql, true);
}
$forum_parent = $cat_id = 0;
$forumname = '';
-if (isset($_REQUEST['addforum']) || isset($_REQUEST['addcategory']))
-{
- $mode = (isset($_REQUEST['addforum'])) ? "addforum" : "addcat";
+if (isset($_REQUEST['addforum']) || isset($_REQUEST['addcategory'])) {
+ $mode = isset($_REQUEST['addforum']) ? 'addforum' : 'addcat';
- if ($mode == 'addforum' && isset($_POST['addforum']) && isset($_POST['forumname']) && is_array($_POST['addforum']))
- {
- $req_cat_id = array_keys($_POST['addforum']);
- $cat_id = $req_cat_id[0];
- $forumname = stripslashes($_POST['forumname'][$cat_id]);
- }
+ if (isset($_POST['addforum'], $_POST['forumname']) && $mode == 'addforum' && is_array($_POST['addforum'])) {
+ $req_cat_id = array_keys($_POST['addforum']);
+ $cat_id = reset($req_cat_id);
+ $forumname = stripslashes($_POST['forumname'][$cat_id]);
+ }
+}
+
+// Check for demo mode
+if (IN_DEMO_MODE && in_array($mode, ['deletecat', 'deleteforum'])) {
+ bb_die($lang['CANT_EDIT_IN_DEMO_MODE']);
}
$show_main_page = false;
-if ($mode)
-{
- switch ($mode)
- {
- case 'addforum':
- case 'editforum':
- //
- // Show form to create/modify a forum
- //
- if ($mode == 'editforum')
- {
- // $newmode determines if we are going to INSERT or UPDATE after posting?
+if ($mode) {
+ switch ($mode) {
+ case 'addforum':
+ case 'editforum':
+ //
+ // Show form to create/modify a forum
+ //
+ if ($mode == 'editforum') {
+ // $newmode determines if we are going to INSERT or UPDATE after posting?
- $l_title = $lang['EDIT_FORUM'];
- $newmode = 'modforum';
- $buttonvalue = $lang['UPDATE'];
+ $l_title = $lang['EDIT_FORUM'];
+ $newmode = 'modforum';
+ $buttonvalue = $lang['UPDATE'];
- $forum_id = intval($_GET[POST_FORUM_URL]);
+ $forum_id = (int)$_GET[POST_FORUM_URL];
- $row = get_info('forum', $forum_id);
+ $row = get_info('forum', $forum_id);
- $cat_id = $row['cat_id'];
- $forumname = $row['forum_name'];
- $forumdesc = $row['forum_desc'];
- $forumstatus = $row['forum_status'];
- $forum_display_sort = $row['forum_display_sort'];
- $forum_display_order = $row['forum_display_order'];
- $forum_parent = $row['forum_parent'];
- $show_on_index = $row['show_on_index'];
- $prune_days = $row['prune_days'];
- $forum_tpl_id = $row['forum_tpl_id'];
- $allow_reg_tracker = $row['allow_reg_tracker'];
- $allow_porno_topic = $row['allow_porno_topic'];
- $self_moderated = $row['self_moderated'];
- }
- else
- {
- $l_title = $lang['CREATE_FORUM'];
- $newmode = 'createforum';
- $buttonvalue = $lang['CREATE_FORUM'];
+ $cat_id = $row['cat_id'];
+ $forumname = $row['forum_name'];
+ $forumdesc = $row['forum_desc'];
+ $forumstatus = $row['forum_status'];
+ $forum_display_sort = $row['forum_display_sort'];
+ $forum_display_order = $row['forum_display_order'];
+ $forum_parent = $row['forum_parent'];
+ $show_on_index = $row['show_on_index'];
+ $prune_days = $row['prune_days'];
+ $forum_tpl_id = $row['forum_tpl_id'];
+ $allow_reg_tracker = $row['allow_reg_tracker'];
+ $allow_porno_topic = $row['allow_porno_topic'];
+ $self_moderated = $row['self_moderated'];
+ } else {
+ $l_title = $lang['CREATE_FORUM'];
+ $newmode = 'createforum';
+ $buttonvalue = $lang['CREATE_FORUM'];
- $forumdesc = '';
- $forumstatus = FORUM_UNLOCKED;
- $forum_display_sort = 0;
- $forum_display_order = 0;
- $forum_id = '';
- $show_on_index = 1;
- $prune_days = 0;
- $forum_tpl_id = 0;
- $allow_reg_tracker = 0;
- $allow_porno_topic = 0;
- $self_moderated = 0;
- }
+ $forumdesc = '';
+ $forumstatus = FORUM_UNLOCKED;
+ $forum_display_sort = 0;
+ $forum_display_order = 0;
+ $forum_id = '';
+ $show_on_index = 1;
+ $prune_days = 0;
+ $forum_tpl_id = 0;
+ $allow_reg_tracker = 0;
+ $allow_porno_topic = 0;
+ $self_moderated = 0;
+ }
- if (isset($_REQUEST['forum_parent']))
- {
- $forum_parent = intval($_REQUEST['forum_parent']);
+ if (isset($_REQUEST['forum_parent'])) {
+ $forum_parent = (int)$_REQUEST['forum_parent'];
- if ($parent = get_forum_data($forum_parent))
- {
- $cat_id = $parent['cat_id'];
- }
- }
- else if (isset($_REQUEST['c']))
- {
- $cat_id = (int) $_REQUEST['c'];
- }
+ if ($parent = get_forum_data($forum_parent)) {
+ $cat_id = $parent['cat_id'];
+ }
+ } elseif (isset($_REQUEST[POST_CAT_URL])) {
+ $cat_id = (int)$_REQUEST[POST_CAT_URL];
+ }
- $catlist = get_list('category', $cat_id, TRUE);
- $forumlocked = $forumunlocked = '';
+ $catlist = get_list('category', $cat_id, true);
+ $forumlocked = $forumunlocked = '';
- $forumstatus == ( FORUM_LOCKED ) ? $forumlocked = 'selected="selected"' : $forumunlocked = 'selected="selected"';
+ $forumstatus == FORUM_LOCKED ? $forumlocked = 'selected' : $forumunlocked = 'selected';
- $statuslist = '' . $lang['STATUS_UNLOCKED'] . ' \n';
- $statuslist .= '' . $lang['STATUS_LOCKED'] . ' \n';
+ $statuslist = '' . $lang['STATUS_UNLOCKED'] . ' \n';
+ $statuslist .= '' . $lang['STATUS_LOCKED'] . ' \n';
- $forum_display_sort_list = get_forum_display_sort_option($forum_display_sort, 'list', 'sort');
- $forum_display_order_list = get_forum_display_sort_option($forum_display_order, 'list', 'order');
+ $forum_display_sort_list = get_forum_display_sort_option($forum_display_sort, 'list', 'sort');
+ $forum_display_order_list = get_forum_display_sort_option($forum_display_order, 'list', 'order');
- $s_hidden_fields = ' ';
+ $s_hidden_fields = ' ';
- $s_parent = ' '. $lang['SF_NO_PARENT'] .' \n';
- $sel_forum = ($forum_parent && !isset($_REQUEST['forum_parent'])) ? $forum_id : $forum_parent;
- $s_parent .= sf_get_list('forum', $forum_id, $sel_forum);
+ $s_parent = ' ' . $lang['SF_NO_PARENT'] . ' \n';
+ $sel_forum = ($forum_parent && !isset($_REQUEST['forum_parent'])) ? $forum_id : $forum_parent;
+ $s_parent .= sf_get_list('forum', $forum_id, $sel_forum);
- $template->assign_vars(array(
- 'TPL_EDIT_FORUM' => true,
+ $template->assign_vars(array(
+ 'TPL_EDIT_FORUM' => true,
- 'S_FORUM_DISPLAY_SORT_LIST' => $forum_display_sort_list,
- 'S_FORUM_DISPLAY_ORDER_LIST' => $forum_display_order_list,
- 'S_FORUM_ACTION' => 'admin_forums.php',
- 'S_HIDDEN_FIELDS' => $s_hidden_fields,
- 'S_SUBMIT_VALUE' => $buttonvalue,
- 'S_CAT_LIST' => $catlist,
- 'S_STATUS_LIST' => $statuslist,
+ 'S_FORUM_DISPLAY_SORT_LIST' => $forum_display_sort_list,
+ 'S_FORUM_DISPLAY_ORDER_LIST' => $forum_display_order_list,
+ 'S_FORUM_ACTION' => 'admin_forums.php',
+ 'S_HIDDEN_FIELDS' => $s_hidden_fields,
+ 'S_SUBMIT_VALUE' => $buttonvalue,
+ 'S_CAT_LIST' => $catlist,
+ 'S_STATUS_LIST' => $statuslist,
- 'SHOW_ON_INDEX' => $show_on_index,
- 'S_PARENT_FORUM' => $s_parent,
- 'CAT_LIST_CLASS' => ($forum_parent) ? 'hidden' : '',
- 'SHOW_ON_INDEX_CLASS' => (!$forum_parent) ? 'hidden' : '',
- 'TPL_SELECT' => get_select('forum_tpl', $forum_tpl_id, 'html', $lang['TEMPLATE_DISABLE']),
- 'ALLOW_REG_TRACKER' => build_select('allow_reg_tracker', array($lang['DISALLOWED'] => 0, $lang['ALLOWED'] => 1), $allow_reg_tracker),
- 'ALLOW_PORNO_TOPIC' => build_select('allow_porno_topic', array($lang['NONE'] => 0, $lang['YES'] => 1), $allow_porno_topic),
- 'SELF_MODERATED' => build_select('self_moderated', array($lang['NONE'] => 0, $lang['YES'] => 1), $self_moderated),
+ 'SHOW_ON_INDEX' => $show_on_index,
+ 'S_PARENT_FORUM' => $s_parent,
+ 'CAT_LIST_CLASS' => $forum_parent ? 'hidden' : '',
+ 'SHOW_ON_INDEX_CLASS' => (!$forum_parent) ? 'hidden' : '',
+ 'TPL_SELECT' => get_select('forum_tpl', $forum_tpl_id, 'html', $lang['TEMPLATE_DISABLE']),
+ 'ALLOW_REG_TRACKER' => build_select('allow_reg_tracker', array($lang['DISALLOWED'] => 0, $lang['ALLOWED'] => 1), $allow_reg_tracker),
+ 'ALLOW_PORNO_TOPIC' => build_select('allow_porno_topic', array($lang['NONE'] => 0, $lang['YES'] => 1), $allow_porno_topic),
+ 'SELF_MODERATED' => build_select('self_moderated', array($lang['NONE'] => 0, $lang['YES'] => 1), $self_moderated),
- 'L_FORUM_TITLE' => $l_title,
+ 'L_FORUM_TITLE' => $l_title,
- 'PRUNE_DAYS' => $prune_days,
- 'FORUM_NAME' => htmlCHR($forumname),
- 'DESCRIPTION' => htmlCHR($forumdesc),
- ));
- break;
+ 'PRUNE_DAYS' => $prune_days,
+ 'FORUM_NAME' => htmlCHR($forumname),
+ 'DESCRIPTION' => htmlCHR($forumdesc),
+ ));
+ break;
- case 'createforum':
- //
- // Create a forum in the DB
- //
- $cat_id = intval($_POST[POST_CAT_URL]);
- $forum_name = (string) $_POST['forumname'];
- $forum_desc = (string) $_POST['forumdesc'];
- $forum_status = intval($_POST['forumstatus']);
+ case 'createforum':
+ //
+ // Create a forum in the DB
+ //
+ $cat_id = (int)$_POST[POST_CAT_URL];
+ $forum_name = (string)$_POST['forumname'];
+ $forum_desc = (string)$_POST['forumdesc'];
+ $forum_status = (int)$_POST['forumstatus'];
- $prune_days = intval($_POST['prune_days']);
+ $prune_days = (int)$_POST['prune_days'];
- $forum_parent = ($_POST['forum_parent'] != -1) ? intval($_POST['forum_parent']) : 0;
- $show_on_index = ($forum_parent) ? intval($_POST['show_on_index']) : 1;
+ $forum_parent = ($_POST['forum_parent'] != -1) ? (int)$_POST['forum_parent'] : 0;
+ $show_on_index = $forum_parent ? (int)$_POST['show_on_index'] : 1;
- $forum_display_sort = intval($_POST['forum_display_sort']);
- $forum_display_order = intval($_POST['forum_display_order']);
+ $forum_display_sort = (int)$_POST['forum_display_sort'];
+ $forum_display_order = (int)$_POST['forum_display_order'];
- $forum_tpl_id = (int) $_POST['forum_tpl_select'];
- $allow_reg_tracker = (int) $_POST['allow_reg_tracker'];
- $allow_porno_topic = (int) $_POST['allow_porno_topic'];
- $self_moderated = (int) $_POST['self_moderated'];
+ $forum_tpl_id = (int)$_POST['forum_tpl_select'];
+ $allow_reg_tracker = (int)$_POST['allow_reg_tracker'];
+ $allow_porno_topic = (int)$_POST['allow_porno_topic'];
+ $self_moderated = (int)$_POST['self_moderated'];
- if (!$forum_name)
- {
- bb_die('Can not create a forum without a name');
- }
+ if (!$forum_name) {
+ bb_die('Can not create a forum without a name');
+ }
- if ($forum_parent)
- {
- if (!$parent = get_forum_data($forum_parent))
- {
- bb_die('Parent forum with id '. $forum_parent .' not found');
- }
+ if ($forum_parent) {
+ if (!$parent = get_forum_data($forum_parent)) {
+ bb_die('Parent forum with id ' . $forum_parent . ' not found');
+ }
- $cat_id = $parent['cat_id'];
- $forum_parent = ($parent['forum_parent']) ? $parent['forum_parent'] : $parent['forum_id'];
- $forum_order = $parent['forum_order'] + 5;
- }
- else
- {
- $max_order = get_max_forum_order($cat_id);
- $forum_order = $max_order + 5;
- }
+ $cat_id = $parent['cat_id'];
+ $forum_parent = $parent['forum_parent'] ?: $parent['forum_id'];
+ $forum_order = $parent['forum_order'] + 5;
+ } else {
+ $max_order = get_max_forum_order($cat_id);
+ $forum_order = $max_order + 5;
+ }
- // Default permissions of public forum
- $field_sql = $value_sql = '';
+ // Default permissions of public forum
+ $field_sql = $value_sql = '';
- foreach ($default_forum_auth as $field => $value)
- {
- $field_sql .= ", $field";
- $value_sql .= ", $value";
- }
+ foreach ($default_forum_auth as $field => $value) {
+ $field_sql .= ", $field";
+ $value_sql .= ", $value";
+ }
- $forum_name_sql = DB()->escape($forum_name);
- $forum_desc_sql = DB()->escape($forum_desc);
+ $forum_name_sql = DB()->escape($forum_name);
+ $forum_desc_sql = DB()->escape($forum_desc);
- $columns = ' forum_name, cat_id, forum_desc, forum_order, forum_status, prune_days, forum_parent, show_on_index, forum_display_sort, forum_display_order, forum_tpl_id, allow_reg_tracker, allow_porno_topic, self_moderated'. $field_sql;
- $values = "'$forum_name_sql', $cat_id, '$forum_desc_sql', $forum_order, $forum_status, $prune_days, $forum_parent, $show_on_index, $forum_display_sort, $forum_display_order, $forum_tpl_id, $allow_reg_tracker, $allow_porno_topic, $self_moderated". $value_sql;
+ $columns = ' forum_name, cat_id, forum_desc, forum_order, forum_status, prune_days, forum_parent, show_on_index, forum_display_sort, forum_display_order, forum_tpl_id, allow_reg_tracker, allow_porno_topic, self_moderated' . $field_sql;
+ $values = "'$forum_name_sql', $cat_id, '$forum_desc_sql', $forum_order, $forum_status, $prune_days, $forum_parent, $show_on_index, $forum_display_sort, $forum_display_order, $forum_tpl_id, $allow_reg_tracker, $allow_porno_topic, $self_moderated" . $value_sql;
- DB()->query("INSERT INTO ". BB_FORUMS ." ($columns) VALUES ($values)");
+ DB()->query('INSERT INTO ' . BB_FORUMS . " ($columns) VALUES ($values)");
- renumber_order('forum', $cat_id);
- $datastore->update('cat_forums');
- CACHE('bb_cache')->rm();
+ renumber_order('forum', $cat_id);
+ $datastore->update('cat_forums');
+ CACHE('bb_cache')->rm();
- bb_die($lang['FORUMS_UPDATED'] . ' ' . sprintf($lang['CLICK_RETURN_FORUMADMIN'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '));
+ bb_die($lang['FORUMS_UPDATED'] . ' ' . sprintf($lang['CLICK_RETURN_FORUMADMIN'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '));
- break;
+ break;
- case 'modforum':
- //
- // Modify a forum in the DB
- //
- $cat_id = intval($_POST[POST_CAT_URL]);
- $forum_id = intval($_POST[POST_FORUM_URL]);
- $forum_name = (string) $_POST['forumname'];
- $forum_desc = (string) $_POST['forumdesc'];
- $forum_status = intval($_POST['forumstatus']);
- $prune_days = intval($_POST['prune_days']);
+ case 'modforum':
+ //
+ // Modify a forum in the DB
+ //
+ $cat_id = (int)$_POST[POST_CAT_URL];
+ $forum_id = (int)$_POST[POST_FORUM_URL];
+ $forum_name = (string)$_POST['forumname'];
+ $forum_desc = (string)$_POST['forumdesc'];
+ $forum_status = (int)$_POST['forumstatus'];
+ $prune_days = (int)$_POST['prune_days'];
- $forum_parent = ($_POST['forum_parent'] != -1) ? intval($_POST['forum_parent']) : 0;
- $show_on_index = ($forum_parent) ? intval($_POST['show_on_index']) : 1;
+ $forum_parent = ($_POST['forum_parent'] != -1) ? (int)$_POST['forum_parent'] : 0;
+ $show_on_index = $forum_parent ? (int)$_POST['show_on_index'] : 1;
- $forum_display_order = intval($_POST['forum_display_order']);
- $forum_display_sort = intval($_POST['forum_display_sort']);
- $forum_tpl_id = (int) $_POST['forum_tpl_select'];
- $allow_reg_tracker = (int) $_POST['allow_reg_tracker'];
- $allow_porno_topic = (int) $_POST['allow_porno_topic'];
- $self_moderated = (int) $_POST['self_moderated'];
+ $forum_display_order = (int)$_POST['forum_display_order'];
+ $forum_display_sort = (int)$_POST['forum_display_sort'];
+ $forum_tpl_id = (int)$_POST['forum_tpl_select'];
+ $allow_reg_tracker = (int)$_POST['allow_reg_tracker'];
+ $allow_porno_topic = (int)$_POST['allow_porno_topic'];
+ $self_moderated = (int)$_POST['self_moderated'];
- $forum_data = get_forum_data($forum_id);
- $old_cat_id = $forum_data['cat_id'];
- $forum_order = $forum_data['forum_order'];
+ $forum_data = get_forum_data($forum_id);
+ $old_cat_id = $forum_data['cat_id'];
+ $forum_order = $forum_data['forum_order'];
- if (!$forum_name)
- {
- bb_die('Can not modify a forum without a name');
- }
+ if (!$forum_name) {
+ bb_die('Can not modify a forum without a name');
+ }
- if ($forum_parent)
- {
- if (!$parent = get_forum_data($forum_parent))
- {
- bb_die('Parent forum with id '. $forum_parent .' not found');
- }
+ if ($forum_parent) {
+ if (!$parent = get_forum_data($forum_parent)) {
+ bb_die('Parent forum with id ' . $forum_parent . ' not found');
+ }
- $cat_id = $parent['cat_id'];
- $forum_parent = ($parent['forum_parent']) ? $parent['forum_parent'] : $parent['forum_id'];
- $forum_order = $parent['forum_order'] + 5;
+ $cat_id = $parent['cat_id'];
+ $forum_parent = $parent['forum_parent'] ?: $parent['forum_id'];
+ $forum_order = $parent['forum_order'] + 5;
- if ($forum_id == $forum_parent)
- {
- bb_die('Ambiguous forum ID. Please select other parent forum');
- }
- }
- else if ($cat_id != $old_cat_id)
- {
- $max_order = get_max_forum_order($cat_id);
- $forum_order = $max_order + 5;
- }
- else if ($forum_data['forum_parent'])
- {
- $old_parent = $forum_data['forum_parent'];
- $forum_order = $cat_forums[$old_cat_id]['f'][$old_parent]['forum_order'] - 5;
- }
+ if ($forum_id == $forum_parent) {
+ bb_die('Ambiguous forum ID. Please select other parent forum');
+ }
+ } elseif ($cat_id != $old_cat_id) {
+ $max_order = get_max_forum_order($cat_id);
+ $forum_order = $max_order + 5;
+ } elseif ($forum_data['forum_parent']) {
+ $old_parent = $forum_data['forum_parent'];
+ $forum_order = $cat_forums[$old_cat_id]['f'][$old_parent]['forum_order'] - 5;
+ }
- $forum_name_sql = DB()->escape($forum_name);
- $forum_desc_sql = DB()->escape($forum_desc);
+ $forum_name_sql = DB()->escape($forum_name);
+ $forum_desc_sql = DB()->escape($forum_desc);
- DB()->query("
- UPDATE ". BB_FORUMS ." SET
+ DB()->query('
+ UPDATE ' . BB_FORUMS . " SET
forum_name = '$forum_name_sql',
cat_id = $cat_id,
forum_desc = '$forum_desc_sql',
@@ -314,905 +298,894 @@ if ($mode)
WHERE forum_id = $forum_id
");
- if ($cat_id != $old_cat_id)
- {
- change_sf_cat($forum_id, $cat_id, $forum_order);
- renumber_order('forum', $cat_id);
- }
+ if ($cat_id != $old_cat_id) {
+ change_sf_cat($forum_id, $cat_id, $forum_order);
+ renumber_order('forum', $cat_id);
+ }
- renumber_order('forum', $old_cat_id);
+ renumber_order('forum', $old_cat_id);
- $cat_forums = get_cat_forums();
- $fix = fix_orphan_sf();
- $datastore->update('cat_forums');
- CACHE('bb_cache')->rm();
+ $cat_forums = get_cat_forums();
+ $fix = fix_orphan_sf();
+ $datastore->update('cat_forums');
+ CACHE('bb_cache')->rm();
- $message = $lang['FORUMS_UPDATED'] . ' ';
- $message .= ($fix) ? "$fix " : '';
- $message .= sprintf($lang['CLICK_RETURN_FORUMADMIN'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' ');
- bb_die($message);
+ $message = $lang['FORUMS_UPDATED'] . ' ';
+ $message .= $fix ? "$fix " : '';
+ $message .= sprintf($lang['CLICK_RETURN_FORUMADMIN'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' ');
+ bb_die($message);
- break;
+ break;
- case 'addcat':
- //
- // Create a category in the DB
- //
- if (!$new_cat_title = trim($_POST['categoryname']))
- {
- bb_die('Category name is empty');
- }
+ case 'addcat':
+ //
+ // Create a category in the DB
+ //
+ if (!$new_cat_title = trim($_POST['categoryname'])) {
+ bb_die($lang['CATEGORY_NAME_EMPTY']);
+ }
- check_name_dup('cat', $new_cat_title);
+ check_name_dup('cat', $new_cat_title);
- $order = DB()->fetch_row("SELECT MAX(cat_order) AS max_order FROM ". BB_CATEGORIES);
+ $order = DB()->fetch_row('SELECT MAX(cat_order) AS max_order FROM ' . BB_CATEGORIES);
- $args = DB()->build_array('INSERT', array(
- 'cat_title' => (string) $new_cat_title,
- 'cat_order' => (int) $order['max_order'] + 10,
- ));
+ $args = DB()->build_array('INSERT', array(
+ 'cat_title' => (string)$new_cat_title,
+ 'cat_order' => (int)$order['max_order'] + 10,
+ ));
- DB()->query("INSERT INTO ". BB_CATEGORIES . $args);
+ DB()->query('INSERT INTO ' . BB_CATEGORIES . $args);
- $datastore->update('cat_forums');
- CACHE('bb_cache')->rm();
+ $datastore->update('cat_forums');
+ CACHE('bb_cache')->rm();
- bb_die($lang['FORUMS_UPDATED'] . ' ' . sprintf($lang['CLICK_RETURN_FORUMADMIN'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '));
+ bb_die($lang['FORUMS_UPDATED'] . ' ' . sprintf($lang['CLICK_RETURN_FORUMADMIN'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '));
- break;
+ break;
- case 'editcat':
- //
- // Show form to edit a category
- //
- $cat_id = (int) $_GET['c'];
- $cat_info = get_info('category', $cat_id);
+ case 'editcat':
+ //
+ // Show form to edit a category
+ //
+ $cat_id = (int)$_GET[POST_CAT_URL];
+ $cat_info = get_info('category', $cat_id);
- $hidden_fields = array(
- 'mode' => 'modcat',
- 'c' => $cat_id,
- );
+ $hidden_fields = array(
+ 'mode' => 'modcat',
+ POST_CAT_URL => $cat_id,
+ );
- $template->assign_vars(array(
- 'TPL_EDIT_CATEGORY' => true,
- 'CAT_TITLE' => htmlCHR($cat_info['cat_title']),
- 'S_HIDDEN_FIELDS' => build_hidden_fields($hidden_fields),
- 'S_SUBMIT_VALUE' => $lang['UPDATE'],
- 'S_FORUM_ACTION' => "admin_forums.php",
- ));
+ $template->assign_vars(array(
+ 'TPL_EDIT_CATEGORY' => true,
+ 'CAT_TITLE' => htmlCHR($cat_info['cat_title']),
+ 'S_HIDDEN_FIELDS' => build_hidden_fields($hidden_fields),
+ 'S_SUBMIT_VALUE' => $lang['UPDATE'],
+ 'S_FORUM_ACTION' => 'admin_forums.php',
+ ));
- break;
+ break;
- case 'modcat':
- //
- // Modify a category in the DB
- //
- if (!$new_cat_title = trim($_POST['cat_title']))
- {
- bb_die('Category name is empty');
- }
+ case 'modcat':
+ //
+ // Modify a category in the DB
+ //
+ if (!$new_cat_title = trim($_POST['cat_title'])) {
+ bb_die($lang['CATEGORY_NAME_EMPTY']);
+ }
- $cat_id = (int) $_POST['c'];
+ $cat_id = (int)$_POST[POST_CAT_URL];
- $row = get_info('category', $cat_id);
- $cur_cat_title = $row['cat_title'];
+ $row = get_info('category', $cat_id);
+ $cur_cat_title = $row['cat_title'];
- if ($cur_cat_title && $cur_cat_title !== $new_cat_title)
- {
- check_name_dup('cat', $new_cat_title);
+ if ($cur_cat_title && $cur_cat_title !== $new_cat_title) {
+ check_name_dup('cat', $new_cat_title);
- $new_cat_title_sql = DB()->escape($new_cat_title);
+ $new_cat_title_sql = DB()->escape($new_cat_title);
- DB()->query("
- UPDATE ". BB_CATEGORIES ." SET
+ DB()->query('
+ UPDATE ' . BB_CATEGORIES . " SET
cat_title = '$new_cat_title_sql'
WHERE cat_id = $cat_id
");
- }
+ }
- $datastore->update('cat_forums');
- CACHE('bb_cache')->rm();
+ $datastore->update('cat_forums');
+ CACHE('bb_cache')->rm();
- bb_die($lang['FORUMS_UPDATED'] . ' ' . sprintf($lang['CLICK_RETURN_FORUMADMIN'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '));
+ bb_die($lang['FORUMS_UPDATED'] . ' ' . sprintf($lang['CLICK_RETURN_FORUMADMIN'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '));
- break;
+ break;
- case 'deleteforum':
- //
- // Show form to delete a forum
- //
- $forum_id = (int) $_GET['f'];
+ case 'deleteforum':
+ //
+ // Show form to delete a forum
+ //
+ $forum_id = (int)$_GET[POST_FORUM_URL];
- $move_to_options = ''. $lang['DELETE_ALL_POSTS'] .' ';
- $move_to_options .= sf_get_list('forum', $forum_id, 0);
+ $move_to_options = '' . $lang['DELETE_ALL_POSTS'] . ' ';
+ $move_to_options .= sf_get_list('forum', $forum_id, 0);
- $foruminfo = get_info('forum', $forum_id);
+ $foruminfo = get_info('forum', $forum_id);
- $hidden_fields = array(
- 'mode' => 'movedelforum',
- 'from_id' => $forum_id,
- );
+ $hidden_fields = array(
+ 'mode' => 'movedelforum',
+ 'from_id' => $forum_id,
+ );
- $template->assign_vars(array(
- 'TPL_DELETE_FORUM' => true,
+ $template->assign_vars(array(
+ 'TPL_DELETE_FORUM' => true,
- 'WHAT_TO_DELETE' => htmlCHR($foruminfo['forum_name']),
- 'DELETE_TITLE' => $lang['FORUM_DELETE'],
- 'CAT_FORUM_NAME' => $lang['FORUM_NAME'],
+ 'WHAT_TO_DELETE' => htmlCHR($foruminfo['forum_name']),
+ 'DELETE_TITLE' => $lang['FORUM_DELETE'],
+ 'CAT_FORUM_NAME' => $lang['FORUM_NAME'],
- 'S_HIDDEN_FIELDS' => build_hidden_fields($hidden_fields),
- 'S_FORUM_ACTION' => "admin_forums.php",
- 'MOVE_TO_OPTIONS' => $move_to_options,
- 'S_SUBMIT_VALUE' => $lang['MOVE_AND_DELETE'],
- ));
+ 'S_HIDDEN_FIELDS' => build_hidden_fields($hidden_fields),
+ 'S_FORUM_ACTION' => 'admin_forums.php',
+ 'MOVE_TO_OPTIONS' => $move_to_options,
+ 'S_SUBMIT_VALUE' => $lang['MOVE_AND_DELETE'],
+ ));
- break;
+ break;
- case 'movedelforum':
- //
- // Move or delete a forum in the DB
- //
- $from_id = (int) $_POST['from_id'];
- $to_id = (int) $_POST['to_id'];
+ case 'movedelforum':
+ //
+ // Move or delete a forum in the DB
+ //
+ $from_id = (int)$_POST['from_id'];
+ $to_id = (int)$_POST['to_id'];
- if ($to_id == -1)
- {
- // Delete everything from forum
- topic_delete('prune', $from_id, 0, true);
- }
- else
- {
- // Move all posts
- $sql = "SELECT * FROM ". BB_FORUMS ." WHERE forum_id IN($from_id, $to_id)";
- $result = DB()->query($sql);
+ if ($to_id == -1) {
+ // Delete everything from forum
+ \TorrentPier\Legacy\Admin\Common::topic_delete('prune', $from_id, 0, true);
+ $datastore->update('stats');
+ } else {
+ // Move all posts
+ $sql = 'SELECT * FROM ' . BB_FORUMS . " WHERE forum_id IN($from_id, $to_id)";
+ $result = DB()->query($sql);
- if (DB()->num_rows($result) != 2)
- {
- bb_die('Ambiguous forum ID');
- }
+ if (DB()->num_rows($result) != 2) {
+ bb_die('Ambiguous forum ID');
+ }
- DB()->query("UPDATE ". BB_TOPICS ." SET forum_id = $to_id WHERE forum_id = $from_id");
- DB()->query("UPDATE ". BB_BT_TORRENTS ." SET forum_id = $to_id WHERE forum_id = $from_id");
+ DB()->query('UPDATE ' . BB_TOPICS . " SET forum_id = $to_id WHERE forum_id = $from_id");
+ DB()->query('UPDATE ' . BB_BT_TORRENTS . " SET forum_id = $to_id WHERE forum_id = $from_id");
- $row = DB()->fetch_row("SELECT MIN(post_id) AS start_id, MAX(post_id) AS finish_id FROM ". BB_POSTS);
- $start_id = (int) $row['start_id'];
- $finish_id = (int) $row['finish_id'];
- $per_cycle = 10000;
- while (true)
- {
- set_time_limit(600);
- $end_id = $start_id + $per_cycle - 1;
- DB()->query("
- UPDATE ". BB_POSTS ." SET forum_id = $to_id WHERE post_id BETWEEN $start_id AND $end_id AND forum_id = $from_id
+ $row = DB()->fetch_row('SELECT MIN(post_id) AS start_id, MAX(post_id) AS finish_id FROM ' . BB_POSTS);
+ $start_id = (int)$row['start_id'];
+ $finish_id = (int)$row['finish_id'];
+ $per_cycle = 10000;
+ while (true) {
+ set_time_limit(600);
+ $end_id = $start_id + $per_cycle - 1;
+ DB()->query('
+ UPDATE ' . BB_POSTS . " SET forum_id = $to_id WHERE post_id BETWEEN $start_id AND $end_id AND forum_id = $from_id
");
- if ($end_id > $finish_id)
- {
- break;
- }
- $start_id += $per_cycle;
- }
+ if ($end_id > $finish_id) {
+ break;
+ }
+ $start_id += $per_cycle;
+ }
- sync('forum', $to_id);
- }
+ \TorrentPier\Legacy\Admin\Common::sync('forum', $to_id);
+ }
- DB()->query("DELETE FROM ". BB_FORUMS ." WHERE forum_id = $from_id");
- DB()->query("DELETE FROM ". BB_AUTH_ACCESS ." WHERE forum_id = $from_id");
- DB()->query("DELETE FROM ". BB_AUTH_ACCESS_SNAP ." WHERE forum_id = $from_id");
+ DB()->query('DELETE FROM ' . BB_FORUMS . " WHERE forum_id = $from_id");
+ DB()->query('DELETE FROM ' . BB_AUTH_ACCESS . " WHERE forum_id = $from_id");
+ DB()->query('DELETE FROM ' . BB_AUTH_ACCESS_SNAP . " WHERE forum_id = $from_id");
- $cat_forums = get_cat_forums();
- fix_orphan_sf();
- update_user_level('all');
- $datastore->update('cat_forums');
- CACHE('bb_cache')->rm();
+ $cat_forums = get_cat_forums();
+ fix_orphan_sf();
+ \TorrentPier\Legacy\Group::update_user_level('all');
+ $datastore->update('cat_forums');
+ CACHE('bb_cache')->rm();
- bb_die($lang['FORUMS_UPDATED'] . ' ' . sprintf($lang['CLICK_RETURN_FORUMADMIN'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '));
+ bb_die($lang['FORUMS_UPDATED'] . ' ' . sprintf($lang['CLICK_RETURN_FORUMADMIN'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '));
- break;
+ break;
- case 'deletecat':
- // Show form to delete a category
- $cat_id = (int) $_GET['c'];
- $catinfo = get_info('category', $cat_id);
- $categories_count = $catinfo['number'];
+ case 'deletecat':
+ // Show form to delete a category
+ $cat_id = (int)$_GET[POST_CAT_URL];
+ $catinfo = get_info('category', $cat_id);
+ $categories_count = $catinfo['number'];
- if ($categories_count == 1)
- {
- $row = DB()->fetch_row("SELECT COUNT(*) AS forums_count FROM ". BB_FORUMS);
+ if ($categories_count == 1) {
+ $row = DB()->fetch_row('SELECT COUNT(*) AS forums_count FROM ' . BB_FORUMS);
- if ($row['forums_count'] > 0)
- {
- bb_die($lang['MUST_DELETE_FORUMS']);
- }
- else
- {
- $template->assign_var('NOWHERE_TO_MOVE', $lang['NOWHERE_TO_MOVE']);
- }
- }
+ if ($row['forums_count'] > 0) {
+ bb_die($lang['MUST_DELETE_FORUMS']);
+ } else {
+ $template->assign_var('NOWHERE_TO_MOVE', $lang['NOWHERE_TO_MOVE']);
+ }
+ }
- $hidden_fields = array(
- 'mode' => 'movedelcat',
- 'from_id' => $cat_id,
- );
+ $hidden_fields = array(
+ 'mode' => 'movedelcat',
+ 'from_id' => $cat_id,
+ );
- $template->assign_vars(array(
- 'TPL_DELETE_FORUM' => true,
+ $template->assign_vars(array(
+ 'TPL_DELETE_FORUM' => true,
- 'WHAT_TO_DELETE' => htmlCHR($catinfo['cat_title']),
- 'DELETE_TITLE' => $lang['CATEGORY_DELETE'],
- 'CAT_FORUM_NAME' => $lang['CATEGORY'],
+ 'WHAT_TO_DELETE' => htmlCHR($catinfo['cat_title']),
+ 'DELETE_TITLE' => $lang['CATEGORY_DELETE'],
+ 'CAT_FORUM_NAME' => $lang['CATEGORY'],
- 'S_HIDDEN_FIELDS' => build_hidden_fields($hidden_fields),
- 'S_FORUM_ACTION' => "admin_forums.php",
- 'MOVE_TO_OPTIONS' => get_list('category', $cat_id, 0),
- 'S_SUBMIT_VALUE' => $lang['MOVE_AND_DELETE'],
- ));
+ 'S_HIDDEN_FIELDS' => build_hidden_fields($hidden_fields),
+ 'S_FORUM_ACTION' => 'admin_forums.php',
+ 'MOVE_TO_OPTIONS' => get_list('category', $cat_id, 0),
+ 'S_SUBMIT_VALUE' => $lang['MOVE_AND_DELETE'],
+ ));
- break;
+ break;
- case 'movedelcat':
- // Move or delete a category in the DB
- $from_id = (int) $_POST['from_id'];
- $to_id = (int) $_POST['to_id'];
+ case 'movedelcat':
+ // Move or delete a category in the DB
+ $from_id = (int)$_POST['from_id'];
+ $to_id = (int)$_POST['to_id'] ?? -1;
- if ($from_id == $to_id || !cat_exists($from_id) || !cat_exists($to_id))
- {
- bb_die('Bad input');
- }
+ if ($to_id === -1) {
+ bb_die($lang['NOWHERE_TO_MOVE']);
+ }
- $order_shear = get_max_forum_order($to_id) + 10;
+ if ($from_id == $to_id || !cat_exists($from_id) || !cat_exists($to_id)) {
+ bb_die('Bad input');
+ }
- DB()->query("
- UPDATE ". BB_FORUMS ." SET
+ $order_shear = get_max_forum_order($to_id) + 10;
+
+ DB()->query('
+ UPDATE ' . BB_FORUMS . " SET
cat_id = $to_id,
forum_order = forum_order + $order_shear
WHERE cat_id = $from_id
");
- DB()->query("DELETE FROM ". BB_CATEGORIES ." WHERE cat_id = $from_id");
+ DB()->query('DELETE FROM ' . BB_CATEGORIES . " WHERE cat_id = $from_id");
- renumber_order('forum', $to_id);
- $cat_forums = get_cat_forums();
- $fix = fix_orphan_sf();
- $datastore->update('cat_forums');
- CACHE('bb_cache')->rm();
+ renumber_order('forum', $to_id);
+ $cat_forums = get_cat_forums();
+ $fix = fix_orphan_sf();
+ $datastore->update('cat_forums');
+ CACHE('bb_cache')->rm();
- $message = $lang['FORUMS_UPDATED'] . ' ';
- $message .= ($fix) ? "$fix " : '';
- $message .= sprintf($lang['CLICK_RETURN_FORUMADMIN'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' ');
- bb_die($message);
+ $message = $lang['FORUMS_UPDATED'] . ' ';
+ $message .= $fix ? "$fix " : '';
+ $message .= sprintf($lang['CLICK_RETURN_FORUMADMIN'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' ');
+ bb_die($message);
- break;
+ break;
- case 'forum_order':
- // Change order of forums
- $move = intval($_GET['move']);
- $forum_id = intval($_GET[POST_FORUM_URL]);
+ case 'forum_order':
+ // Change order of forums
+ $move = (int)$_GET['move'];
+ $forum_id = (int)$_GET[POST_FORUM_URL];
- $forum_info = get_info('forum', $forum_id);
- renumber_order('forum', $forum_info['cat_id']);
+ $forum_info = get_info('forum', $forum_id);
+ renumber_order('forum', $forum_info['cat_id']);
- $cat_id = $forum_info['cat_id'];
+ $cat_id = $forum_info['cat_id'];
- $move_down_forum_id = FALSE;
- $forums = $cat_forums[$cat_id]['f_ord'];
- $forum_order = $forum_info['forum_order'];
- $prev_forum = (isset($forums[$forum_order - 10])) ? $forums[$forum_order - 10] : FALSE;
- $next_forum = (isset($forums[$forum_order + 10])) ? $forums[$forum_order + 10] : FALSE;
+ $move_down_forum_id = false;
+ $forums = $cat_forums[$cat_id]['f_ord'];
+ $forum_order = $forum_info['forum_order'];
+ $prev_forum = $forums[$forum_order - 10] ?? false;
+ $next_forum = $forums[$forum_order + 10] ?? false;
- // move selected forum ($forum_id) UP
- if ($move < 0 && $prev_forum)
- {
- if ($forum_info['forum_parent'] && $prev_forum['forum_parent'] != $forum_info['forum_parent'])
- {
- $show_main_page = true;
- break;
- }
- else if ($move_down_forum_id = get_prev_root_forum_id($forums, $forum_order))
- {
- $move_up_forum_id = $forum_id;
- $move_down_ord_val = (get_sf_count($forum_id) + 1) * 10;
- $move_up_ord_val = ((get_sf_count($move_down_forum_id) + 1) * 10) + $move_down_ord_val;
- $move_down_forum_order = $cat_forums[$cat_id]['f'][$move_down_forum_id]['forum_order'];
- }
- }
- // move selected forum ($forum_id) DOWN
- else if ($move > 0 && $next_forum)
- {
- if ($forum_info['forum_parent'] && $next_forum['forum_parent'] != $forum_info['forum_parent'])
- {
- $show_main_page = true;
- break;
- }
- else if ($move_up_forum_id = get_next_root_forum_id($forums, $forum_order))
- {
- $move_down_forum_id = $forum_id;
- $move_down_forum_order = $forum_order;
- $move_down_ord_val = (get_sf_count($move_up_forum_id) + 1) * 10;
- $move_up_ord_val = ((get_sf_count($move_down_forum_id) + 1) * 10) + $move_down_ord_val;
- }
- }
- else
- {
- $show_main_page = true;
- break;
- }
+ // move selected forum ($forum_id) UP
+ if ($move < 0 && $prev_forum) {
+ if ($forum_info['forum_parent'] && $prev_forum['forum_parent'] != $forum_info['forum_parent']) {
+ $show_main_page = true;
+ break;
+ }
- if ($forum_info['forum_parent'])
- {
- DB()->query("
- UPDATE ". BB_FORUMS ." SET
+ if ($move_down_forum_id = get_prev_root_forum_id($forums, $forum_order)) {
+ $move_up_forum_id = $forum_id;
+ $move_down_ord_val = (get_sf_count($forum_id) + 1) * 10;
+ $move_up_ord_val = ((get_sf_count($move_down_forum_id) + 1) * 10) + $move_down_ord_val;
+ $move_down_forum_order = $cat_forums[$cat_id]['f'][$move_down_forum_id]['forum_order'];
+ }
+ } // move selected forum ($forum_id) DOWN
+ elseif ($move > 0 && $next_forum) {
+ if ($forum_info['forum_parent'] && $next_forum['forum_parent'] != $forum_info['forum_parent']) {
+ $show_main_page = true;
+ break;
+ }
+
+ if ($move_up_forum_id = get_next_root_forum_id($forums, $forum_order)) {
+ $move_down_forum_id = $forum_id;
+ $move_down_forum_order = $forum_order;
+ $move_down_ord_val = (get_sf_count($move_up_forum_id) + 1) * 10;
+ $move_up_ord_val = ((get_sf_count($move_down_forum_id) + 1) * 10) + $move_down_ord_val;
+ }
+ } else {
+ $show_main_page = true;
+ break;
+ }
+
+ if ($forum_info['forum_parent']) {
+ DB()->query('
+ UPDATE ' . BB_FORUMS . " SET
forum_order = forum_order + $move
WHERE forum_id = $forum_id
");
- }
- else if ($move_down_forum_id)
- {
- DB()->query("
- UPDATE ". BB_FORUMS ." SET
+ } elseif ($move_down_forum_id) {
+ DB()->query('
+ UPDATE ' . BB_FORUMS . " SET
forum_order = forum_order + $move_down_ord_val
WHERE cat_id = $cat_id
AND forum_order >= $move_down_forum_order
");
- DB()->query("
- UPDATE ". BB_FORUMS ." SET
+ DB()->query('
+ UPDATE ' . BB_FORUMS . " SET
forum_order = forum_order - $move_up_ord_val
WHERE forum_id = $move_up_forum_id
OR forum_parent = $move_up_forum_id
");
- }
+ }
- renumber_order('forum', $forum_info['cat_id']);
- $datastore->update('cat_forums');
- CACHE('bb_cache')->rm();
+ renumber_order('forum', $forum_info['cat_id']);
+ $datastore->update('cat_forums');
+ CACHE('bb_cache')->rm();
- $show_main_page = true;
- break;
+ $show_main_page = true;
+ break;
- case 'cat_order':
- $move = (int) $_GET['move'];
- $cat_id = (int) $_GET['c'];
+ case 'cat_order':
+ $move = (int)$_GET['move'];
+ $cat_id = (int)$_GET[POST_CAT_URL];
- DB()->query("
- UPDATE ". BB_CATEGORIES ." SET
+ DB()->query('
+ UPDATE ' . BB_CATEGORIES . " SET
cat_order = cat_order + $move
WHERE cat_id = $cat_id
");
- renumber_order('category');
- $datastore->update('cat_forums');
- CACHE('bb_cache')->rm();
+ renumber_order('category');
+ $datastore->update('cat_forums');
+ CACHE('bb_cache')->rm();
- $show_main_page = true;
- break;
+ $show_main_page = true;
+ break;
- case 'forum_sync':
- sync('forum', intval($_GET['f']));
- $datastore->update('cat_forums');
- CACHE('bb_cache')->rm();
+ case 'forum_sync':
+ \TorrentPier\Legacy\Admin\Common::sync('forum', (int)$_GET[POST_FORUM_URL]);
+ $datastore->update('cat_forums');
+ CACHE('bb_cache')->rm();
- $show_main_page = true;
- break;
+ $show_main_page = true;
+ break;
- default:
- bb_die($lang['NO_MODE']);
-
- break;
- }
+ default:
+ bb_die($lang['NO_MODE']);
+ break;
+ }
}
-if (!$mode || $show_main_page)
-{
- $template->assign_vars(array(
- 'TPL_FORUMS_LIST' => true,
+if (!$mode || $show_main_page) {
+ $template->assign_vars(array(
+ 'TPL_FORUMS_LIST' => true,
- 'S_FORUM_ACTION' => 'admin_forums.php',
- 'L_FORUM_TITLE' => $lang['FORUM_ADMIN_MAIN'],
- ));
+ 'S_FORUM_ACTION' => 'admin_forums.php',
+ 'L_FORUM_TITLE' => $lang['FORUM_ADMIN_MAIN'],
+ ));
- $sql = "SELECT cat_id, cat_title, cat_order FROM " . BB_CATEGORIES . " ORDER BY cat_order";
- if (!$q_categories = DB()->sql_query($sql))
- {
- bb_die('Could not query categories list');
- }
+ $sql = 'SELECT cat_id, cat_title, cat_order FROM ' . BB_CATEGORIES . ' ORDER BY cat_order';
+ if (!$q_categories = DB()->sql_query($sql)) {
+ bb_die('Could not query categories list');
+ }
- if ($total_categories = DB()->num_rows($q_categories))
- {
- $category_rows = DB()->sql_fetchrowset($q_categories);
+ if ($total_categories = DB()->num_rows($q_categories)) {
+ $category_rows = DB()->sql_fetchrowset($q_categories);
- $where_cat_sql = $req_cat_id = '';
+ $where_cat_sql = $req_cat_id = '';
- if ($c =& $_REQUEST['c'])
- {
- if ($c !== 'all')
- {
- $req_cat_id = (int) $c;
- $where_cat_sql = "WHERE cat_id = $req_cat_id";
- }
- else
- {
- $req_cat_id = 'all';
- }
- }
- else
- {
- $where_cat_sql = "WHERE cat_id = '-1'";
- }
+ if ($c =& $_REQUEST[POST_CAT_URL]) {
+ if ($c !== 'all') {
+ $req_cat_id = (int)$c;
+ $where_cat_sql = "WHERE cat_id = $req_cat_id";
+ } else {
+ $req_cat_id = 'all';
+ }
+ } else {
+ $where_cat_sql = "WHERE cat_id = '-1'";
+ }
- $sql = "SELECT * FROM ". BB_FORUMS ." $where_cat_sql ORDER BY cat_id, forum_order";
- if (!$q_forums = DB()->sql_query($sql))
- {
- bb_die('Could not query forums information');
- }
+ $sql = 'SELECT * FROM ' . BB_FORUMS . " $where_cat_sql ORDER BY cat_id, forum_order";
+ if (!$q_forums = DB()->sql_query($sql)) {
+ bb_die('Could not query forums information');
+ }
- if ($total_forums = DB()->num_rows($q_forums))
- {
- $forum_rows = DB()->sql_fetchrowset($q_forums);
- }
+ if ($total_forums = DB()->num_rows($q_forums)) {
+ $forum_rows = DB()->sql_fetchrowset($q_forums);
+ }
- // Okay, let's build the index
- $gen_cat = array();
+ // Okay, let's build the index
+ $gen_cat = [];
- $bgr_class_1 = 'prow1';
- $bgr_class_2 = 'prow2';
- $bgr_class_over = 'prow3';
+ $bgr_class_1 = 'prow1';
+ $bgr_class_2 = 'prow2';
+ $bgr_class_over = 'prow3';
- $template->assign_vars(array(
- 'U_ALL_FORUMS' => 'admin_forums.php?c=all',
- 'FORUMS_COUNT' => $total_forums,
- ));
+ $template->assign_vars(array(
+ 'U_ALL_FORUMS' => 'admin_forums.php?' . POST_CAT_URL . '=all',
+ 'FORUMS_COUNT' => $total_forums,
+ ));
- for ($i = 0; $i < $total_categories; $i++)
- {
- $cat_id = $category_rows[$i]['cat_id'];
+ for ($i = 0; $i < $total_categories; $i++) {
+ $cat_id = $category_rows[$i]['cat_id'];
- $template->assign_block_vars("c", array(
- 'S_ADD_FORUM_SUBMIT' => "addforum[$cat_id]",
- 'S_ADD_FORUM_NAME' => "forumname[$cat_id]",
+ $template->assign_block_vars('c', array(
+ 'S_ADD_FORUM_SUBMIT' => "addforum[$cat_id]",
+ 'S_ADD_FORUM_NAME' => "forumname[$cat_id]",
- 'CAT_ID' => $cat_id,
- 'CAT_DESC' => htmlCHR($category_rows[$i]['cat_title']),
+ 'CAT_ID' => $cat_id,
+ 'CAT_DESC' => htmlCHR($category_rows[$i]['cat_title']),
- 'U_CAT_EDIT' => "admin_forums.php?mode=editcat&c=$cat_id",
- 'U_CAT_DELETE' => "admin_forums.php?mode=deletecat&c=$cat_id",
- 'U_CAT_MOVE_UP' => "admin_forums.php?mode=cat_order&move=-15&c=$cat_id",
- 'U_CAT_MOVE_DOWN' => "admin_forums.php?mode=cat_order&move=15&c=$cat_id",
- 'U_VIEWCAT' => "admin_forums.php?c=$cat_id",
- 'U_CREATE_FORUM' => "admin_forums.php?mode=addforum&c=$cat_id",
- ));
+ 'U_CAT_EDIT' => "admin_forums.php?mode=editcat&" . POST_CAT_URL . "=$cat_id",
+ 'U_CAT_DELETE' => "admin_forums.php?mode=deletecat&" . POST_CAT_URL . "=$cat_id",
+ 'U_CAT_MOVE_UP' => "admin_forums.php?mode=cat_order&move=-15&" . POST_CAT_URL . "=$cat_id",
+ 'U_CAT_MOVE_DOWN' => "admin_forums.php?mode=cat_order&move=15&" . POST_CAT_URL . "=$cat_id",
+ 'U_VIEWCAT' => "admin_forums.php?" . POST_CAT_URL . "=$cat_id",
+ 'U_CREATE_FORUM' => "admin_forums.php?mode=addforum&" . POST_CAT_URL . "=$cat_id",
+ ));
- for ($j = 0; $j < $total_forums; $j++)
- {
- $forum_id = $forum_rows[$j]['forum_id'];
+ for ($j = 0; $j < $total_forums; $j++) {
+ $forum_id = $forum_rows[$j]['forum_id'];
- $bgr_class = (!($j % 2)) ? $bgr_class_2 : $bgr_class_1;
- $row_bgr = " class=\"$bgr_class\" onmouseover=\"this.className='$bgr_class_over';\" onmouseout=\"this.className='$bgr_class';\"";
+ $bgr_class = (!($j % 2)) ? $bgr_class_2 : $bgr_class_1;
+ $row_bgr = " class=\"$bgr_class\" onmouseover=\"this.className='$bgr_class_over';\" onmouseout=\"this.className='$bgr_class';\"";
- if ($forum_rows[$j]['cat_id'] == $cat_id)
- {
+ if ($forum_rows[$j]['cat_id'] == $cat_id) {
+ $template->assign_block_vars('c.f', array(
+ 'FORUM_NAME' => htmlCHR($forum_rows[$j]['forum_name']),
+ 'FORUM_DESC' => htmlCHR($forum_rows[$j]['forum_desc']),
+ 'NUM_TOPICS' => $forum_rows[$j]['forum_topics'],
+ 'NUM_POSTS' => $forum_rows[$j]['forum_posts'],
+ 'PRUNE_DAYS' => !empty($forum_rows[$j]['prune_days']) ? delta_time((TIMENOW - 86400 * $forum_rows[$j]['prune_days']), TIMENOW, 'days') : $lang['DISABLED'],
- $template->assign_block_vars("c.f", array(
- 'FORUM_NAME' => htmlCHR($forum_rows[$j]['forum_name']),
- 'FORUM_DESC' => htmlCHR($forum_rows[$j]['forum_desc']),
- 'NUM_TOPICS' => $forum_rows[$j]['forum_topics'],
- 'NUM_POSTS' => $forum_rows[$j]['forum_posts'],
- 'PRUNE_DAYS' => ($forum_rows[$j]['prune_days']) ? $forum_rows[$j]['prune_days'] : '-',
+ 'ORDER' => $forum_rows[$j]['forum_order'],
+ 'FORUM_ID' => $forum_rows[$j]['forum_id'],
+ 'ROW_BGR' => $row_bgr,
- 'ORDER' => $forum_rows[$j]['forum_order'],
- 'FORUM_ID' => $forum_rows[$j]['forum_id'],
- 'ROW_BGR' => $row_bgr,
-
- 'SHOW_ON_INDEX' => (bool) $forum_rows[$j]['show_on_index'],
- 'FORUM_PARENT' => $forum_rows[$j]['forum_parent'],
- 'SF_PAD' => ($forum_rows[$j]['forum_parent']) ? ' style="padding-left: 20px;" ' : '',
- 'FORUM_NAME_CLASS' => ($forum_rows[$j]['forum_parent']) ? 'genmed' : 'gen',
- 'ADD_SUB_HREF' => "admin_forums.php?mode=addforum&forum_parent={$forum_rows[$j]['forum_id']}",
- 'U_VIEWFORUM' => BB_ROOT ."viewforum.php?f=$forum_id",
- 'U_FORUM_EDIT' => "admin_forums.php?mode=editforum&f=$forum_id",
- 'U_FORUM_PERM' => "admin_forumauth.php?f=$forum_id",
- 'U_FORUM_DELETE' => "admin_forums.php?mode=deleteforum&f=$forum_id",
- 'U_FORUM_MOVE_UP' => "admin_forums.php?mode=forum_order&move=-15&f=$forum_id&c=$req_cat_id",
- 'U_FORUM_MOVE_DOWN' => "admin_forums.php?mode=forum_order&move=15&f=$forum_id&c=$req_cat_id",
- 'U_FORUM_RESYNC' => "admin_forums.php?mode=forum_sync&f=$forum_id",
- ));
-
- }// if ... forumid == catid
- } // for ... forums
- } // for ... categories
- }// if ... total_categories
+ 'SHOW_ON_INDEX' => (bool)$forum_rows[$j]['show_on_index'],
+ 'FORUM_PARENT' => $forum_rows[$j]['forum_parent'],
+ 'SF_PAD' => $forum_rows[$j]['forum_parent'] ? ' style="padding-left: 20px;" ' : '',
+ 'FORUM_NAME_CLASS' => $forum_rows[$j]['forum_parent'] ? 'genmed' : 'gen',
+ 'ADD_SUB_HREF' => !$forum_rows[$j]['forum_parent'] ? "admin_forums.php?mode=addforum&forum_parent={$forum_rows[$j]['forum_id']}" : '',
+ 'U_VIEWFORUM' => BB_ROOT . FORUM_URL . $forum_id,
+ 'U_FORUM_EDIT' => "admin_forums.php?mode=editforum&" . POST_FORUM_URL . "=$forum_id",
+ 'U_FORUM_PERM' => "admin_forumauth.php?" . POST_FORUM_URL . "=$forum_id",
+ 'U_FORUM_DELETE' => "admin_forums.php?mode=deleteforum&" . POST_FORUM_URL . "=$forum_id",
+ 'U_FORUM_MOVE_UP' => "admin_forums.php?mode=forum_order&move=-15&" . POST_FORUM_URL . "=$forum_id&" . POST_CAT_URL . "=$req_cat_id",
+ 'U_FORUM_MOVE_DOWN' => "admin_forums.php?mode=forum_order&move=15&" . POST_FORUM_URL . "=$forum_id&" . POST_CAT_URL . "=$req_cat_id",
+ 'U_FORUM_RESYNC' => "admin_forums.php?mode=forum_sync&" . POST_FORUM_URL . "=$forum_id",
+ ));
+ }
+ }
+ }
+ }
}
print_page('admin_forums.tpl', 'admin');
-// Functions
-function get_info ($mode, $id)
+/**
+ * @param $mode
+ * @param $id
+ * @return mixed
+ */
+function get_info($mode, $id)
{
- switch($mode)
- {
- case 'category':
- $table = BB_CATEGORIES;
- $idfield = 'cat_id';
- break;
+ $table = null;
+ $idfield = null;
+ switch ($mode) {
+ case 'category':
+ $table = BB_CATEGORIES;
+ $idfield = 'cat_id';
+ break;
- case 'forum':
- $table = BB_FORUMS;
- $idfield = 'forum_id';
- break;
+ case 'forum':
+ $table = BB_FORUMS;
+ $idfield = 'forum_id';
+ break;
- default:
- bb_die('Wrong mode for generating select list #1');
- break;
- }
- $sql = "SELECT count(*) as total FROM $table";
- if( !$result = DB()->sql_query($sql) )
- {
- bb_die('Could not get forum / category information #1');
- }
- $count = DB()->sql_fetchrow($result);
- $count = $count['total'];
+ default:
+ bb_die('Wrong mode for generating select list #1');
+ break;
+ }
+ $sql = "SELECT count(*) as total FROM $table";
+ if (!$result = DB()->sql_query($sql)) {
+ bb_die('Could not get forum / category information #1');
+ }
+ $count = DB()->sql_fetchrow($result);
+ $count = $count['total'];
- $sql = "SELECT * FROM $table WHERE $idfield = $id";
+ $sql = "SELECT * FROM $table WHERE $idfield = $id";
- if (!$result = DB()->sql_query($sql))
- {
- bb_die('Could not get forum / category information #2');
- }
+ if (!$result = DB()->sql_query($sql)) {
+ bb_die('Could not get forum / category information #2');
+ }
- if (DB()->num_rows($result) != 1)
- {
- bb_die('Forum / category does not exist or multiple forums / categories with ID '. $id);
- }
+ if (DB()->num_rows($result) != 1) {
+ bb_die('Forum / category does not exist or multiple forums / categories with ID ' . $id);
+ }
- $return = DB()->sql_fetchrow($result);
- $return['number'] = $count;
- return $return;
+ $return = DB()->sql_fetchrow($result);
+ $return['number'] = $count;
+ return $return;
}
-function get_list ($mode, $id, $select)
+/**
+ * @param $mode
+ * @param $id
+ * @param $select
+ * @return string
+ */
+function get_list($mode, $id, $select)
{
- switch($mode)
- {
- case 'category':
- $table = BB_CATEGORIES;
- $idfield = 'cat_id';
- $namefield = 'cat_title';
- $order = 'cat_order';
- break;
+ $table = null;
+ $idfield = null;
+ $order = null;
+ $namefield = null;
+ switch ($mode) {
+ case 'category':
+ $table = BB_CATEGORIES;
+ $idfield = 'cat_id';
+ $namefield = 'cat_title';
+ $order = 'cat_order';
+ break;
- case 'forum':
- $table = BB_FORUMS;
- $idfield = 'forum_id';
- $namefield = 'forum_name';
- $order = 'cat_id, forum_order';
- break;
+ case 'forum':
+ $table = BB_FORUMS;
+ $idfield = 'forum_id';
+ $namefield = 'forum_name';
+ $order = 'cat_id, forum_order';
+ break;
- default:
- bb_die('Wrong mode for generating select list #2');
- break;
- }
+ default:
+ bb_die('Wrong mode for generating select list #2');
+ break;
+ }
- $sql = "SELECT * FROM $table";
- if( $select == 0 )
- {
- $sql .= " WHERE $idfield <> $id";
- }
- $sql .= " ORDER BY $order";
+ $sql = "SELECT * FROM $table";
+ if ($select == 0) {
+ $sql .= " WHERE $idfield <> $id";
+ }
+ $sql .= " ORDER BY $order";
- if( !$result = DB()->sql_query($sql) )
- {
- bb_die('Could not get list of categories / forums #1');
- }
+ if (!$result = DB()->sql_query($sql)) {
+ bb_die('Could not get list of categories / forums #1');
+ }
- $catlist = '';
+ $catlist = '';
- while( $row = DB()->sql_fetchrow($result) )
- {
- $s = '';
- if ($row[$idfield] == $id)
- {
- $s = ' selected="selected"';
- }
- $catlist .= ' ' . htmlCHR(str_short($row[$namefield], 60)) . ' \n';
- }
+ while ($row = DB()->sql_fetchrow($result)) {
+ $s = '';
+ if ($row[$idfield] == $id) {
+ $s = ' selected';
+ }
+ $catlist .= ' ' . str_short(htmlCHR($row[$namefield]), 60) . ' \n';
+ }
- return($catlist);
+ return $catlist;
}
-function renumber_order ($mode, $cat = 0)
+/**
+ * @param $mode
+ * @param int $cat
+ */
+function renumber_order($mode, $cat = 0)
{
- switch($mode)
- {
- case 'category':
- $table = BB_CATEGORIES;
- $idfield = 'cat_id';
- $orderfield = 'cat_order';
- $cat = 0;
- break;
+ $table = null;
+ $catfield = null;
+ $orderfield = null;
+ $idfield = null;
+ switch ($mode) {
+ case 'category':
+ $table = BB_CATEGORIES;
+ $idfield = 'cat_id';
+ $orderfield = 'cat_order';
+ $cat = 0;
+ break;
- case 'forum':
- $table = BB_FORUMS;
- $idfield = 'forum_id';
- $orderfield = 'forum_order';
- $catfield = 'cat_id';
- break;
+ case 'forum':
+ $table = BB_FORUMS;
+ $idfield = 'forum_id';
+ $orderfield = 'forum_order';
+ $catfield = 'cat_id';
+ break;
- default:
- bb_die('Wrong mode for generating select list #3');
- break;
- }
+ default:
+ bb_die('Wrong mode for generating select list #3');
+ break;
+ }
- $sql = "SELECT * FROM $table";
- if( $cat != 0)
- {
- $sql .= " WHERE $catfield = $cat";
- }
- $sql .= " ORDER BY $orderfield ASC";
+ $sql = "SELECT * FROM $table";
+ if ($cat != 0) {
+ $sql .= " WHERE $catfield = $cat";
+ }
+ $sql .= " ORDER BY $orderfield ASC";
- if (!$result = DB()->sql_query($sql))
- {
- bb_die('Could not get list of categories / forums #2');
- }
+ if (!$result = DB()->sql_query($sql)) {
+ bb_die('Could not get list of categories / forums #2');
+ }
- $i = 10;
+ $i = 10;
- while ($row = DB()->sql_fetchrow($result))
- {
- $sql = "UPDATE $table SET $orderfield = $i WHERE $idfield = " . $row[$idfield];
- if (!DB()->sql_query($sql))
- {
- bb_die('Could not update order fields');
- }
- $i += 10;
- }
-
- if (!$result = DB()->sql_query($sql))
- {
- bb_die('Could not get list of categories / forums #3');
- }
+ while ($row = DB()->sql_fetchrow($result)) {
+ $sql = "UPDATE $table SET $orderfield = $i WHERE $idfield = " . $row[$idfield];
+ if (!DB()->sql_query($sql)) {
+ bb_die('Could not update order fields');
+ }
+ $i += 10;
+ }
+ if (!$result = DB()->sql_query($sql)) {
+ bb_die('Could not get list of categories / forums #3');
+ }
}
-function get_cat_forums ($cat_id = FALSE)
+/**
+ * @param bool $cat_id
+ * @return array
+ */
+function get_cat_forums($cat_id = false)
{
- $forums = array();
- $where_sql = '';
+ $forums = [];
+ $where_sql = '';
- if ($cat_id = intval($cat_id))
- {
- $where_sql = "AND f.cat_id = $cat_id";
- }
+ if ($cat_id = (int)$cat_id) {
+ $where_sql = "AND f.cat_id = $cat_id";
+ }
- $sql = 'SELECT c.cat_title, f.*
- FROM '. BB_FORUMS .' f, '. BB_CATEGORIES ." c
+ $sql = 'SELECT c.cat_title, f.*
+ FROM ' . BB_FORUMS . ' f, ' . BB_CATEGORIES . " c
WHERE f.cat_id = c.cat_id
$where_sql
ORDER BY c.cat_order, f.cat_id, f.forum_order";
- if (!$result = DB()->sql_query($sql))
- {
- bb_die('Could not get list of categories / forums #4');
- }
+ if (!$result = DB()->sql_query($sql)) {
+ bb_die('Could not get list of categories / forums #4');
+ }
- if ($rowset = DB()->sql_fetchrowset($result))
- {
- foreach ($rowset as $rid => $row)
- {
- $forums[$row['cat_id']]['cat_title'] = $row['cat_title'];
- $forums[$row['cat_id']]['f'][$row['forum_id']] = $row;
- $forums[$row['cat_id']]['f_ord'][$row['forum_order']] = $row;
- }
- }
+ if ($rowset = DB()->sql_fetchrowset($result)) {
+ foreach ($rowset as $rid => $row) {
+ $forums[$row['cat_id']]['cat_title'] = $row['cat_title'];
+ $forums[$row['cat_id']]['f'][$row['forum_id']] = $row;
+ $forums[$row['cat_id']]['f_ord'][$row['forum_order']] = $row;
+ }
+ }
- return $forums;
+ return $forums;
}
-function get_sf_count ($forum_id)
+/**
+ * @param $forum_id
+ * @return int
+ */
+function get_sf_count($forum_id)
{
- global $cat_forums;
+ global $cat_forums;
- $sf_count = 0;
+ $sf_count = 0;
- foreach ($cat_forums as $cid => $c)
- {
- foreach ($c['f'] as $fid => $f)
- {
- if ($f['forum_parent'] == $forum_id)
- {
- $sf_count++;
- }
- }
- }
+ foreach ($cat_forums as $cid => $c) {
+ foreach ($c['f'] as $fid => $f) {
+ if ($f['forum_parent'] == $forum_id) {
+ $sf_count++;
+ }
+ }
+ }
- return $sf_count;
+ return $sf_count;
}
-function get_prev_root_forum_id ($forums, $curr_forum_order)
+/**
+ * @param $forums
+ * @param $curr_forum_order
+ * @return bool
+ */
+function get_prev_root_forum_id($forums, $curr_forum_order)
{
- $i = $curr_forum_order - 10;
+ $i = $curr_forum_order - 10;
- while ($i > 0)
- {
- if (isset($forums[$i]) && !$forums[$i]['forum_parent'])
- {
- return $forums[$i]['forum_id'];
- }
- $i = $i - 10;
- }
+ while ($i > 0) {
+ if (isset($forums[$i]) && !$forums[$i]['forum_parent']) {
+ return $forums[$i]['forum_id'];
+ }
+ $i -= 10;
+ }
- return FALSE;
+ return false;
}
-function get_next_root_forum_id ($forums, $curr_forum_order)
+/**
+ * @param $forums
+ * @param $curr_forum_order
+ * @return bool
+ */
+function get_next_root_forum_id($forums, $curr_forum_order)
{
- $i = $curr_forum_order + 10;
- $limit = (count($forums) * 10) + 10;
+ $i = $curr_forum_order + 10;
+ $limit = (count($forums) * 10) + 10;
- while ($i < $limit)
- {
- if (isset($forums[$i]) && !$forums[$i]['forum_parent'])
- {
- return $forums[$i]['forum_id'];
- }
- $i = $i + 10;
- }
+ while ($i < $limit) {
+ if (isset($forums[$i]) && !$forums[$i]['forum_parent']) {
+ return $forums[$i]['forum_id'];
+ }
+ $i += 10;
+ }
- return FALSE;
+ return false;
}
-function get_orphan_sf ()
+/**
+ * @return string
+ */
+function get_orphan_sf()
{
- global $cat_forums;
+ global $cat_forums;
- $last_root = 0;
- $bad_sf_ary = array();
+ $last_root = 0;
+ $bad_sf_ary = [];
- foreach ($cat_forums as $cid => $c)
- {
- foreach ($c['f'] as $fid => $f)
- {
- if ($f['forum_parent'])
- {
- if ($f['forum_parent'] != $last_root)
- {
- $bad_sf_ary[] = $f['forum_id'];
- }
- }
- else
- {
- $last_root = $f['forum_id'];
- }
- }
- }
+ foreach ($cat_forums as $cid => $c) {
+ foreach ($c['f'] as $fid => $f) {
+ if ($f['forum_parent']) {
+ if ($f['forum_parent'] != $last_root) {
+ $bad_sf_ary[] = $f['forum_id'];
+ }
+ } else {
+ $last_root = $f['forum_id'];
+ }
+ }
+ }
- return implode(',', $bad_sf_ary);
+ return implode(',', $bad_sf_ary);
}
-function fix_orphan_sf ($orphan_sf_sql = '', $show_mess = FALSE)
+/**
+ * @param string $orphan_sf_sql
+ * @param bool $show_mess
+ * @return string
+ */
+function fix_orphan_sf($orphan_sf_sql = '', $show_mess = false)
{
- global $lang;
+ global $lang;
- $done_mess = '';
+ $done_mess = '';
- if (!$orphan_sf_sql)
- {
- $orphan_sf_sql = get_orphan_sf();
- }
+ if (!$orphan_sf_sql) {
+ $orphan_sf_sql = get_orphan_sf();
+ }
- if ($orphan_sf_sql)
- {
- $sql = "UPDATE ". BB_FORUMS ." SET forum_parent = 0, show_on_index = 1 WHERE forum_id IN($orphan_sf_sql)";
+ if ($orphan_sf_sql) {
+ $sql = 'UPDATE ' . BB_FORUMS . " SET forum_parent = 0, show_on_index = 1 WHERE forum_id IN($orphan_sf_sql)";
- if (!DB()->sql_query($sql))
- {
- bb_die('Could not change subforums data');
- }
+ if (!DB()->sql_query($sql)) {
+ bb_die('Could not change subforums data');
+ }
- if ($affectedrows = DB()->affected_rows())
- {
- $done_mess = 'Subforums data corrected. '. $affectedrows .' orphan subforum(s) moved to root level.';
- }
+ if ($affectedrows = DB()->affected_rows()) {
+ $done_mess = 'Subforums data corrected. ' . $affectedrows . ' orphan subforum(s) moved to root level.';
+ }
- if ($show_mess)
- {
- $message = $done_mess .' ';
- $message .= sprintf($lang['CLICK_RETURN_FORUMADMIN'], '', ' ') .' ';
- $message .= sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' ');
- bb_die($message);
- }
- }
+ if ($show_mess) {
+ $message = $done_mess . ' ';
+ $message .= sprintf($lang['CLICK_RETURN_FORUMADMIN'], '', ' ') . ' ';
+ $message .= sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' ');
+ bb_die($message);
+ }
+ }
- return $done_mess;
+ return $done_mess;
}
-function sf_get_list ($mode, $exclude = 0, $select = 0)
+/**
+ * @param $mode
+ * @param int $exclude
+ * @param int $select
+ * @return string
+ */
+function sf_get_list($mode, $exclude = 0, $select = 0)
{
- global $cat_forums, $forum_parent;
+ global $cat_forums, $forum_parent;
- $opt = '';
+ $opt = '';
- if ($mode == 'forum')
- {
- foreach ($cat_forums as $cid => $c)
- {
- $opt .= '';
+ if ($mode == 'forum') {
+ foreach ($cat_forums as $cid => $c) {
+ $opt .= '';
- foreach ($c['f'] as $fid => $f)
- {
- $selected = ($fid == $select) ? HTML_SELECTED : '';
- $disabled = ($fid == $exclude && !$forum_parent) ? HTML_DISABLED : '';
- $style = ($disabled) ? ' style="color: gray" ' : (($fid == $exclude) ? ' style="color: darkred" ' : '');
- $opt .= ''. (($f['forum_parent']) ? HTML_SF_SPACER : '') . htmlCHR(str_short($f['forum_name'], 60)) ." \n";
- }
+ foreach ($c['f'] as $fid => $f) {
+ $selected = ($fid == $select) ? HTML_SELECTED : '';
+ $disabled = ($fid == $exclude && !$forum_parent) ? HTML_DISABLED : '';
+ $style = $disabled ? ' style="color: gray" ' : (($fid == $exclude) ? ' style="color: darkred" ' : '');
+ $opt .= '' . ($f['forum_parent'] ? HTML_SF_SPACER : '') . str_short(htmlCHR($f['forum_name']), 60) . " \n";
+ }
- $opt .= ' ';
- }
- }
+ $opt .= ' ';
+ }
+ }
- return $opt;
+ return $opt;
}
-function get_forum_data ($forum_id)
+/**
+ * @param $forum_id
+ * @return bool
+ */
+function get_forum_data($forum_id)
{
- global $cat_forums;
+ global $cat_forums;
- foreach ($cat_forums as $cid => $c)
- {
- foreach ($c['f'] as $fid => $f)
- {
- if ($fid == $forum_id)
- {
- return $f;
- }
- }
- }
+ foreach ($cat_forums as $cid => $c) {
+ foreach ($c['f'] as $fid => $f) {
+ if ($fid == $forum_id) {
+ return $f;
+ }
+ }
+ }
- return FALSE;
+ return false;
}
-function get_max_forum_order ($cat_id)
+/**
+ * @param $cat_id
+ * @return int
+ */
+function get_max_forum_order($cat_id)
{
- $row = DB()->fetch_row("
+ $row = DB()->fetch_row('
SELECT MAX(forum_order) AS max_forum_order
- FROM ". BB_FORUMS ."
+ FROM ' . BB_FORUMS . "
WHERE cat_id = $cat_id
");
- return intval($row['max_forum_order']);
+ return (int)$row['max_forum_order'];
}
-function check_name_dup ($mode, $name, $die_on_error = true)
+/**
+ * @param $mode
+ * @param $name
+ * @param bool $die_on_error
+ * @return mixed
+ */
+function check_name_dup($mode, $name, $die_on_error = true)
{
- $name_sql = DB()->escape($name);
+ $name_sql = DB()->escape($name);
- if ($mode == 'cat')
- {
- $what_checked = 'category';
- $sql = "SELECT cat_id FROM ". BB_CATEGORIES ." WHERE cat_title = '$name_sql'";
- }
- else
- {
- $what_checked = 'forum';
- $sql = "SELECT forum_id FROM ". BB_FORUMS ." WHERE forum_name = '$name_sql'";
- }
+ if ($mode == 'cat') {
+ $what_checked = 'category';
+ $sql = 'SELECT cat_id FROM ' . BB_CATEGORIES . " WHERE cat_title = '$name_sql'";
+ } else {
+ $what_checked = 'forum';
+ $sql = 'SELECT forum_id FROM ' . BB_FORUMS . " WHERE forum_name = '$name_sql'";
+ }
- $name_is_dup = DB()->fetch_row($sql);
+ $name_is_dup = DB()->fetch_row($sql);
- if ($name_is_dup && $die_on_error)
- {
- bb_die('This '. $what_checked .' name taken, please choose something else');
- }
+ if ($name_is_dup && $die_on_error) {
+ bb_die('This ' . $what_checked . ' name taken, please choose something else');
+ }
- return $name_is_dup;
+ return $name_is_dup;
}
/**
* Change subforums cat_id if parent's cat_id was changed
+ *
+ * @param $parent_id
+ * @param $new_cat_id
+ * @param $order_shear
*/
-function change_sf_cat ($parent_id, $new_cat_id, $order_shear)
+function change_sf_cat($parent_id, $new_cat_id, $order_shear)
{
- DB()->query("
- UPDATE ". BB_FORUMS ." SET
+ DB()->query('
+ UPDATE ' . BB_FORUMS . " SET
cat_id = $new_cat_id,
forum_order = forum_order + $order_shear
WHERE forum_parent = $parent_id
");
-}
\ No newline at end of file
+}
diff --git a/admin/admin_groups.php b/admin/admin_groups.php
index ade36db3a..69361639d 100644
--- a/admin/admin_groups.php
+++ b/admin/admin_groups.php
@@ -1,188 +1,168 @@
$row['group_name'],
- 'group_description' => $row['group_description'],
- 'group_moderator' => $row['group_moderator'],
- 'group_mod_name' => $row['moderator_name'],
- 'group_type' => $row['group_type'],
- 'release_group' => $row['release_group'],
- );
- $mode = 'editgroup';
- $template->assign_block_vars('group_edit', array());
- }
- else if (!empty($_POST['new']))
- {
- $group_info = array(
- 'group_name' => '',
- 'group_description' => '',
- 'group_moderator' => '',
- 'group_mod_name' => '',
- 'group_type' => GROUP_OPEN,
- 'release_group' => 0,
- );
- $mode = 'newgroup';
- }
+if (!empty($_POST['edit']) || !empty($_POST['new'])) {
+ if (!empty($_POST['edit'])) {
+ if (!$row = \TorrentPier\Legacy\Group::get_group_data($group_id)) {
+ bb_die($lang['GROUP_NOT_EXIST']);
+ }
+ $group_info = [
+ 'group_name' => $row['group_name'],
+ 'group_description' => $row['group_description'],
+ 'group_moderator' => $row['group_moderator'],
+ 'group_mod_name' => $row['moderator_name'],
+ 'group_type' => $row['group_type'],
+ 'release_group' => $row['release_group']
+ ];
+ $mode = 'editgroup';
+ $template->assign_block_vars('group_edit', []);
+ } elseif (!empty($_POST['new'])) {
+ $group_info = [
+ 'group_name' => '',
+ 'group_description' => '',
+ 'group_moderator' => '',
+ 'group_mod_name' => '',
+ 'group_type' => GROUP_OPEN,
+ 'release_group' => 0
+ ];
+ $mode = 'newgroup';
+ }
- // Ok, now we know everything about them, let's show the page.
- $s_hidden_fields = '
-
-
+ // Ok, now we know everything about them, let's show the page.
+ $s_hidden_fields = '
+
+
';
- $template->assign_vars(array(
- 'TPL_EDIT_GROUP' => true,
+ $template->assign_vars([
+ 'TPL_EDIT_GROUP' => true,
- 'GROUP_NAME' => stripslashes(htmlspecialchars($group_info['group_name'])),
- 'GROUP_DESCRIPTION' => stripslashes(htmlspecialchars($group_info['group_description'])),
- 'GROUP_MODERATOR' => replace_quote($group_info['group_mod_name']),
- 'T_GROUP_EDIT_DELETE' => ($mode == 'newgroup') ? $lang['CREATE_NEW_GROUP'] : $lang['EDIT_GROUP'],
- 'U_SEARCH_USER' => BB_ROOT ."search.php?mode=searchuser",
- 'S_GROUP_OPEN_TYPE' => GROUP_OPEN,
- 'S_GROUP_CLOSED_TYPE' => GROUP_CLOSED,
- 'S_GROUP_HIDDEN_TYPE' => GROUP_HIDDEN,
- 'S_GROUP_OPEN_CHECKED' => ($group_info['group_type'] == GROUP_OPEN) ? HTML_CHECKED : '',
- 'S_GROUP_CLOSED_CHECKED' => ($group_info['group_type'] == GROUP_CLOSED) ? HTML_CHECKED : '',
- 'S_GROUP_HIDDEN_CHECKED' => ($group_info['group_type'] == GROUP_HIDDEN ) ? HTML_CHECKED : '',
- 'RELEASE_GROUP' => ($group_info['release_group']) ? true : false,
- 'S_GROUP_ACTION' => "admin_groups.php",
- 'S_HIDDEN_FIELDS' => $s_hidden_fields,
- ));
-}
-else if (!empty($_POST['group_update']))
-{
- if (!empty($_POST['group_delete']))
- {
- if (!$group_info = get_group_data($group_id))
- {
- bb_die($lang['GROUP_NOT_EXIST']);
- }
- // Delete Group
- delete_group($group_id);
+ 'GROUP_NAME' => stripslashes(htmlspecialchars($group_info['group_name'])),
+ 'GROUP_DESCRIPTION' => stripslashes(htmlspecialchars($group_info['group_description'])),
+ 'GROUP_MODERATOR' => replace_quote($group_info['group_mod_name']),
+ 'T_GROUP_EDIT_DELETE' => ($mode == 'newgroup') ? $lang['CREATE_NEW_GROUP'] : $lang['EDIT_GROUP'],
+ 'U_SEARCH_USER' => BB_ROOT . 'search.php?mode=searchuser',
+ 'S_GROUP_OPEN_TYPE' => GROUP_OPEN,
+ 'S_GROUP_CLOSED_TYPE' => GROUP_CLOSED,
+ 'S_GROUP_HIDDEN_TYPE' => GROUP_HIDDEN,
+ 'S_GROUP_OPEN_CHECKED' => ($group_info['group_type'] == GROUP_OPEN) ? HTML_CHECKED : '',
+ 'S_GROUP_CLOSED_CHECKED' => ($group_info['group_type'] == GROUP_CLOSED) ? HTML_CHECKED : '',
+ 'S_GROUP_HIDDEN_CHECKED' => ($group_info['group_type'] == GROUP_HIDDEN) ? HTML_CHECKED : '',
+ 'RELEASE_GROUP' => (bool)$group_info['release_group'],
+ 'S_GROUP_ACTION' => 'admin_groups.php',
+ 'S_HIDDEN_FIELDS' => $s_hidden_fields
+ ]);
+} elseif (!empty($_POST['group_update'])) {
+ if (!empty($_POST['group_delete'])) {
+ if (!$group_info = \TorrentPier\Legacy\Group::get_group_data($group_id)) {
+ bb_die($lang['GROUP_NOT_EXIST']);
+ }
+ // Delete Group
+ \TorrentPier\Legacy\Group::delete_group($group_id);
- $message = $lang['DELETED_GROUP'] .' ';
- $message .= sprintf($lang['CLICK_RETURN_GROUPSADMIN'], '', ' ') .' ';
- $message .= sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' ');
+ $message = $lang['DELETED_GROUP'] . ' ';
+ $message .= sprintf($lang['CLICK_RETURN_GROUPSADMIN'], '', ' ') . ' ';
+ $message .= sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' ');
- bb_die($message);
- }
- else
- {
- $group_type = isset($_POST['group_type']) ? intval($_POST['group_type']) : GROUP_OPEN;
- $release_group = isset($_POST['release_group']) ? intval($_POST['release_group']) : 0;
- $group_name = isset($_POST['group_name']) ? trim($_POST['group_name']) : '';
- $group_desc = isset($_POST['group_description']) ? trim($_POST['group_description']) : '';
- $group_moderator = isset($_POST['username']) ? $_POST['username'] : '';
+ bb_die($message);
+ } else {
+ $group_type = isset($_POST['group_type']) ? (int)$_POST['group_type'] : GROUP_OPEN;
+ $release_group = isset($_POST['release_group']) ? (int)$_POST['release_group'] : 0;
+ $group_name = isset($_POST['group_name']) ? trim($_POST['group_name']) : '';
+ $group_desc = isset($_POST['group_description']) ? trim($_POST['group_description']) : '';
+ $group_moderator = $_POST['username'] ?? '';
- if ($group_name === '')
- {
- bb_die($lang['NO_GROUP_NAME']);
- }
- else if ($group_moderator === '')
- {
- bb_die($lang['NO_GROUP_MODERATOR']);
- }
- $this_userdata = get_userdata($group_moderator, true);
+ if ($group_name === '') {
+ bb_die($lang['NO_GROUP_NAME']);
+ } elseif ($group_moderator === '') {
+ bb_die($lang['NO_GROUP_MODERATOR']);
+ }
+ $this_userdata = get_userdata($group_moderator, true);
- if (!$group_moderator = $this_userdata['user_id'])
- {
- bb_die($lang['NO_GROUP_MODERATOR']);
- }
+ if (!$group_moderator = $this_userdata['user_id']) {
+ bb_die($lang['NO_GROUP_MODERATOR']);
+ }
- $sql_ary = array(
- 'group_type' => (int) $group_type,
- 'release_group' => (int) $release_group,
- 'group_name' => (string) $group_name,
- 'group_description' => (string) $group_desc,
- 'group_moderator' => (int) $group_moderator,
- 'group_single_user' => 0,
- );
+ $sql_ary = [
+ 'group_type' => (int)$group_type,
+ 'release_group' => (int)$release_group,
+ 'group_name' => (string)$group_name,
+ 'group_description' => (string)$group_desc,
+ 'group_moderator' => (int)$group_moderator,
+ 'group_single_user' => 0,
+ ];
- if ($mode == "editgroup")
- {
- if (!$group_info = get_group_data($group_id))
- {
- bb_die($lang['GROUP_NOT_EXIST']);
- }
+ if ($mode == 'editgroup') {
+ if (!$group_info = \TorrentPier\Legacy\Group::get_group_data($group_id)) {
+ bb_die($lang['GROUP_NOT_EXIST']);
+ }
- if ($group_info['group_moderator'] != $group_moderator)
- {
- // Create user_group for new group's moderator
- add_user_into_group($group_id, $group_moderator);
- $sql_ary['mod_time'] = TIMENOW;
+ if ($group_info['group_moderator'] != $group_moderator) {
+ // Create user_group for new group's moderator
+ \TorrentPier\Legacy\Group::add_user_into_group($group_id, $group_moderator);
+ $sql_ary['mod_time'] = TIMENOW;
- // Delete old moderator's user_group
- if (isset($_POST['delete_old_moderator']))
- {
- delete_user_group($group_id, $group_info['group_moderator']);
- }
- }
+ // Delete old moderator's user_group
+ if (isset($_POST['delete_old_moderator'])) {
+ \TorrentPier\Legacy\Group::delete_user_group($group_id, $group_info['group_moderator']);
+ }
+ }
- $sql_args = DB()->build_array('UPDATE', $sql_ary);
+ $sql_args = DB()->build_array('UPDATE', $sql_ary);
- // Update group's data
- DB()->query("UPDATE ". BB_GROUPS ." SET $sql_args WHERE group_id = $group_id");
+ // Update group's data
+ DB()->query('UPDATE ' . BB_GROUPS . " SET $sql_args WHERE group_id = $group_id");
- $message = $lang['UPDATED_GROUP'] .' ';
- $message .= sprintf($lang['CLICK_RETURN_GROUPSADMIN'], '', ' ') .' ';
- $message .= sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' ');
+ $message = $lang['UPDATED_GROUP'] . ' ';
+ $message .= sprintf($lang['CLICK_RETURN_GROUPSADMIN'], '', ' ') . ' ';
+ $message .= sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' ');
- bb_die($message);
- }
- else if ($mode == 'newgroup')
- {
- $sql_ary['group_time'] = $sql_ary['mod_time'] = TIMENOW;
- $sql_args = DB()->build_array('INSERT', $sql_ary);
+ bb_die($message);
+ } elseif ($mode == 'newgroup') {
+ $sql_ary['group_time'] = $sql_ary['mod_time'] = TIMENOW;
+ $sql_args = DB()->build_array('INSERT', $sql_ary);
- // Create new group
- DB()->query("INSERT INTO ". BB_GROUPS ." $sql_args");
- $new_group_id = DB()->sql_nextid();
+ // Create new group
+ DB()->query('INSERT INTO ' . BB_GROUPS . " $sql_args");
+ $new_group_id = DB()->sql_nextid();
- // Create user_group for group's moderator
- add_user_into_group($new_group_id, $group_moderator);
+ // Create user_group for group's moderator
+ \TorrentPier\Legacy\Group::add_user_into_group($new_group_id, $group_moderator);
- $message = $lang['ADDED_NEW_GROUP'] .' ';
- $message .= sprintf($lang['CLICK_RETURN_GROUPSADMIN'], '', ' ') .' ';
- $message .= sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' ');
+ $message = $lang['ADDED_NEW_GROUP'] . ' ';
+ $message .= sprintf($lang['CLICK_RETURN_GROUPSADMIN'], '', ' ') . ' ';
+ $message .= sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' ');
- bb_die($message);
- }
- else
- {
- bb_die($lang['NO_GROUP_ACTION']);
- }
- }
-}
-else
-{
- $template->assign_vars(array(
- 'TPL_GROUP_SELECT' => true,
+ bb_die($message);
+ } else {
+ bb_die($lang['NO_GROUP_ACTION']);
+ }
+ }
+} else {
+ $template->assign_vars([
+ 'TPL_GROUP_SELECT' => true,
- 'S_GROUP_ACTION' => "admin_groups.php",
- 'S_GROUP_SELECT' => stripslashes(get_select('groups')),
- ));
+ 'S_GROUP_ACTION' => 'admin_groups.php',
+ 'S_GROUP_SELECT' => stripslashes(get_select('groups')),
+ ]);
}
-print_page('admin_groups.tpl', 'admin');
\ No newline at end of file
+print_page('admin_groups.tpl', 'admin');
diff --git a/admin/admin_log.php b/admin/admin_log.php
index 2e53c4099..89f0e8b0b 100644
--- a/admin/admin_log.php
+++ b/admin/admin_log.php
@@ -1,60 +1,67 @@
enqueue(array(
- 'moderators',
-));
+require __DIR__ . '/pagestart.php';
+
+$datastore->enqueue([
+ 'moderators',
+ 'cat_forums',
+]);
$log_action->init();
-$per_page = 50;
-$row_class_1 = 'row1';
-$row_class_2 = 'row2';
-$def_days = 3;
-$def_datetime = TIMENOW;
-$max_forum_name_len = 40;
+$per_page = 50;
+$row_class_1 = 'row1';
+$row_class_2 = 'row2';
+$def_days = 3;
+$def_datetime = TIMENOW;
+$max_forum_name_len = 40;
$title_match_max_len = 60;
$poster_name_max_len = 25;
-$select_max_height = 16;
-$dt_format = 'Y-m-d'; // used in one-day filter
+$select_max_height = 16;
+$dt_format = 'Y-m-d'; // used in one-day filter
$url = basename(__FILE__);
// Key names
-$type_key = 'type';
-$forum_key = 'f';
-$topic_key = 't';
-$user_key = 'u';
-$datetime_key = 'dt'; // value should be strtotime() time ("2006-06-25" etc.)
-$daysback_key = 'db';
-$sort_key = 'sort';
+$type_key = 'type';
+$forum_key = POST_FORUM_URL;
+$topic_key = POST_TOPIC_URL;
+$user_key = POST_USERS_URL;
+$datetime_key = 'dt'; // value should be strtotime() time ("2006-06-25" etc.)
+$daysback_key = 'db';
+$sort_key = 'sort';
$title_match_key = 'tm';
// Key values
-$all_types = 0; // =|
-$all_users = 0; // |> only "0" is a valid value
+$all_types = 0; // =|
+$all_users = 0; // |> only "0" is a valid value
$all_forums = 0; // =|
-$sort_asc = 'ASC';
-$sort_desc = 'DESC';
+$sort_asc = 'ASC';
+$sort_desc = 'DESC';
// Defaults
-$def_types = $all_types;
-$def_users = $all_users;
+$def_types = $all_types;
+$def_users = $all_users;
$def_forums = $all_forums;
-$def_sort = $sort_desc;
+$def_sort = $sort_desc;
// Moderators data
-if (!$mod = $datastore->get('moderators'))
-{
- $datastore->update('moderators');
- $mod = $datastore->get('moderators');
+if (!$mod = $datastore->get('moderators')) {
+ $datastore->update('moderators');
+ $mod = $datastore->get('moderators');
}
array_deep($mod['moderators'], 'html_entity_decode');
array_deep($mod['admins'], 'html_entity_decode');
@@ -64,350 +71,292 @@ $users = array($lang['ACTS_LOG_ALL_ACTIONS'] => $all_users) + array_flip($mod['m
unset($mod);
// Forums data
-if (!$forums = $datastore->get('cat_forums'))
-{
- $datastore->update('cat_forums');
- $forums = $datastore->get('cat_forums');
+if (!$forums = $datastore->get('cat_forums')) {
+ $datastore->update('cat_forums');
+ $forums = $datastore->get('cat_forums');
}
$f_data = $forums['f'];
unset($forums);
// Start
-$start = isset($_REQUEST['start']) ? abs(intval($_REQUEST['start'])) : 0;
+$start = isset($_REQUEST['start']) ? abs((int)$_REQUEST['start']) : 0;
// Type
$type_selected = array($def_types);
$type_csv = '';
-if ($var =& $_REQUEST[$type_key])
-{
- $type_selected = get_id_ary($var);
+if ($var =& $_REQUEST[$type_key]) {
+ $type_selected = get_id_ary($var);
- if (in_array($all_types, $type_selected))
- {
- $type_selected = array($all_types);
- }
- $type_csv = join(',', $type_selected);
- $url = ($type_csv != $def_types) ? url_arg($url, $type_key, $type_csv) : $url;
+ if (in_array($all_types, $type_selected)) {
+ $type_selected = array($all_types);
+ }
+ $type_csv = implode(',', $type_selected);
+ $url = ($type_csv != $def_types) ? url_arg($url, $type_key, $type_csv) : $url;
}
// User
$user_selected = array($def_users);
$user_csv = '';
-if ($var =& $_REQUEST[$user_key])
-{
- $user_selected = get_id_ary($var);
+if ($var =& $_REQUEST[$user_key]) {
+ $user_selected = get_id_ary($var);
- if (in_array($all_users, $user_selected))
- {
- $user_selected = array($all_users);
- }
- $user_csv = join(',', $user_selected);
- $url = ($user_csv != $def_users) ? url_arg($url, $user_key, $user_csv) : $url;
+ if (in_array($all_users, $user_selected)) {
+ $user_selected = array($all_users);
+ }
+ $user_csv = implode(',', $user_selected);
+ $url = ($user_csv != $def_users) ? url_arg($url, $user_key, $user_csv) : $url;
}
// Forum
$forum_selected = array($def_forums);
$forum_csv = '';
-if ($var =& $_REQUEST[$forum_key])
-{
- $forum_selected = get_id_ary($var);
+if ($var =& $_REQUEST[$forum_key]) {
+ $forum_selected = get_id_ary($var);
- if (in_array($all_forums, $forum_selected))
- {
- $forum_selected = array($all_forums);
- }
- $forum_csv = join(',', $forum_selected);
- $url = ($forum_csv != $def_forums) ? url_arg($url, $forum_key, $forum_csv) : $url;
+ if (in_array($all_forums, $forum_selected)) {
+ $forum_selected = array($all_forums);
+ }
+ $forum_csv = implode(',', $forum_selected);
+ $url = ($forum_csv != $def_forums) ? url_arg($url, $forum_key, $forum_csv) : $url;
}
// Topic
$topic_selected = null;
$topic_csv = '';
-if ($var =& $_REQUEST[$topic_key])
-{
- $topic_selected = get_id_ary($var);
- $topic_csv = join(',', $topic_selected);
- $url = ($topic_csv) ? url_arg($url, $topic_key, $topic_csv) : $url;
+if ($var =& $_REQUEST[$topic_key]) {
+ $topic_selected = get_id_ary($var);
+ $topic_csv = implode(',', $topic_selected);
+ $url = $topic_csv ? url_arg($url, $topic_key, $topic_csv) : $url;
}
-// Order
-$order_val = 'log_time';
-
// Sort
$sort_val = $def_sort;
-if ($var =& $_REQUEST[$sort_key] AND $var != $def_sort)
-{
- $sort_val = ($var == $sort_asc) ? $sort_asc : $sort_desc;
- $url = url_arg($url, $sort_key, $sort_val);
+if ($var =& $_REQUEST[$sort_key] && $var != $def_sort) {
+ $sort_val = ($var == $sort_asc) ? $sort_asc : $sort_desc;
+ $url = url_arg($url, $sort_key, $sort_val);
}
// Time
$datetime_val = $def_datetime;
$daysback_val = $def_days;
-if ($var =& $_REQUEST[$daysback_key] AND $var != $def_days)
-{
- $daysback_val = max(intval($var), 1);
- $url = url_arg($url, $daysback_key, $daysback_val);
+if ($var =& $_REQUEST[$daysback_key] && $var != $def_days) {
+ $daysback_val = max((int)$var, 1);
+ $url = url_arg($url, $daysback_key, $daysback_val);
}
-if ($var =& $_REQUEST[$datetime_key] AND $var != $def_datetime)
-{
- $tz = TIMENOW + (3600 * $bb_cfg['board_timezone']);
- if (($tmp_timestamp = strtotime($var, $tz)) > 0)
- {
- $datetime_val = $tmp_timestamp;
- $url = url_arg($url, $datetime_key, date($dt_format, $datetime_val));
- }
+if ($var =& $_REQUEST[$datetime_key] && $var != $def_datetime) {
+ $tz = TIMENOW + (3600 * config()->get('board_timezone'));
+ if (($tmp_timestamp = strtotime($var, $tz)) > 0) {
+ $datetime_val = $tmp_timestamp;
+ $url = url_arg($url, $datetime_key, date($dt_format, $datetime_val));
+ }
}
$time_end_val = 86400 + mktime(0, 0, 0, date('m', $datetime_val), date('d', $datetime_val), date('Y', $datetime_val));
-$time_start_val = $time_end_val - 86400*$daysback_val;
+$time_start_val = $time_end_val - 86400 * $daysback_val;
// First log time
-$row = DB()->fetch_row("SELECT MIN(log_time) AS first_log_time FROM ". BB_LOG);
-$first_log_time = (int) $row['first_log_time'];
+$row = DB()->fetch_row('SELECT MIN(log_time) AS first_log_time FROM ' . BB_LOG);
+$first_log_time = (int)$row['first_log_time'];
// Title match
$title_match_val = $title_match_sql = '';
-if ($var =& $_REQUEST[$title_match_key])
-{
- if ($tmp_title_match = substr(urldecode(trim($var)), 0, $title_match_max_len))
- {
- $title_match_sql = DB()->escape($tmp_title_match);
- $url = url_arg($url, $title_match_key, urlencode($tmp_title_match));
- }
+if ($var =& $_REQUEST[$title_match_key]) {
+ if ($tmp_title_match = substr(urldecode(trim($var)), 0, $title_match_max_len)) {
+ $title_match_sql = DB()->escape($tmp_title_match);
+ $url = url_arg($url, $title_match_key, urlencode($tmp_title_match));
+ }
}
-//
// SQL
-//
-$select = "SELECT *";
+$where = " WHERE l.log_time BETWEEN '$time_start_val' AND '$time_end_val'";
+$where .= $type_csv ? " AND l.log_type_id IN($type_csv)" : '';
+$where .= $user_csv ? " AND l.log_user_id IN($user_csv)" : '';
+$where .= $forum_csv ? " AND l.log_forum_id IN($forum_csv)" : '';
+$where .= $topic_csv ? " AND l.log_topic_id IN($topic_csv)" : '';
+$where .= $title_match_sql ? " AND MATCH (l.log_topic_title) AGAINST ('$title_match_sql' IN BOOLEAN MODE)" : '';
-$from = "FROM ". BB_LOG;
-
-$where = "
- WHERE log_time BETWEEN $time_start_val AND $time_end_val
-";
-$where .= ($type_csv) ? "
- AND log_type_id IN($type_csv)
-" : '';
-$where .= ($user_csv) ? "
- AND log_user_id IN($user_csv)
-" : '';
-$where .= ($forum_csv) ? "
- AND log_forum_id IN($forum_csv)
-" : '';
-$where .= ($topic_csv) ? "
- AND log_topic_id IN($topic_csv)
-" : '';
-$where .= ($title_match_sql) ? "
- AND MATCH (log_topic_title) AGAINST ('$title_match_sql' IN BOOLEAN MODE)
-" : '';
-
-$order = "ORDER BY $order_val";
-
-$sort = $sort_val;
-
-$limit = "LIMIT $start, ". ($per_page + 1);
-
-$sql = "
- $select
- $from
+$sql = 'SELECT l.*, u.*
+ FROM ' . BB_LOG . ' l
+ LEFT JOIN ' . BB_USERS . " u ON(u.user_id = l.log_user_id)
$where
- $order
- $sort
- $limit
-";
+ ORDER BY l.log_time
+ $sort_val
+ LIMIT $start, " . ($per_page + 1);
$log_rowset = DB()->fetch_rowset($sql);
$log_count = count($log_rowset);
-if ($log_count == $per_page + 1)
-{
- $items_count = $start + ($per_page * 2);
- $pages = '?';
- array_pop($log_rowset);
-}
-else
-{
- $items_count = $start + $log_count;
- $pages = (!$log_count) ? 1 : ceil($items_count / $per_page);
+if ($log_count == $per_page + 1) {
+ $items_count = $start + ($per_page * 2);
+ $pages = '?';
+ array_pop($log_rowset);
+} else {
+ $items_count = $start + $log_count;
+ $pages = (!$log_count) ? 1 : ceil($items_count / $per_page);
}
generate_pagination($url, $items_count, $per_page, $start);
-$filter = array();
+$filter = [];
-if ($log_rowset)
-{
- $log_type = $log_action->log_type;
- $log_type_flip = array_flip($log_type);
+if ($log_rowset) {
+ $log_type = $log_action->log_type;
+ $log_type_flip = array_flip($log_type);
- foreach ($log_rowset as $row_num => $row)
- {
- $msg = '';
- $forum_name = $forum_name_new = '';
- $topic_title = $topic_title_new = '';
+ foreach ($log_rowset as $row_num => $row) {
+ $msg = '';
+ $forum_name = $forum_name_new = '';
+ $topic_title = $topic_title_new = '';
- $topic_deleted = ($row['log_type_id'] == $log_type['mod_topic_delete']);
+ $topic_deleted = ($row['log_type_id'] == $log_type['mod_topic_delete']);
- switch ($row['log_type_id'])
- {
- case $log_type['mod_topic_delete']:
- case $log_type['mod_topic_move']:
- case $log_type['mod_topic_lock']:
- case $log_type['mod_topic_unlock']:
- case $log_type['mod_post_delete']:
- case $log_type['mod_topic_split']:
- // topic_title
- if (!empty($row['log_topic_title']))
- {
- $topic_title = $row['log_topic_title'];
- }
- // topic_title_new
- if (!empty($row['log_topic_title_new']))
- {
- $topic_title_new = $row['log_topic_title_new'];
- }
- // forum_name
- if ($fid =& $row['log_forum_id'])
- {
- $forum_name = ($fname =& $f_data[$fid]['forum_name']) ? $fname : 'id:'. $row['log_forum_id'];
- }
- // forum_name_new
- if ($fid =& $row['log_forum_id_new'])
- {
- $forum_name_new = ($fname =& $f_data[$fid]['forum_name']) ? $fname : 'id:'. $row['log_forum_id'];
- }
+ switch ($row['log_type_id']) {
+ case $log_type['mod_topic_delete']:
+ case $log_type['mod_topic_move']:
+ case $log_type['mod_topic_lock']:
+ case $log_type['mod_topic_unlock']:
+ case $log_type['mod_topic_set_downloaded']:
+ case $log_type['mod_topic_unset_downloaded']:
+ case $log_type['mod_topic_change_tor_status']:
+ case $log_type['mod_topic_change_tor_type']:
+ case $log_type['mod_topic_tor_unregister']:
+ case $log_type['mod_topic_renamed']:
+ case $log_type['mod_post_delete']:
+ case $log_type['mod_post_pin']:
+ case $log_type['mod_post_unpin']:
+ case $log_type['mod_topic_split']:
+ // topic_title
+ if (!empty($row['log_topic_title'])) {
+ $topic_title = $row['log_topic_title'];
+ }
+ // topic_title_new
+ if (!empty($row['log_topic_title_new'])) {
+ $topic_title_new = $row['log_topic_title_new'];
+ }
+ // forum_name
+ if ($fid =& $row['log_forum_id']) {
+ $forum_name = ($fname =& $f_data[$fid]['forum_name']) ? $fname : 'id:' . $row['log_forum_id'];
+ }
+ // forum_name_new
+ if ($fid =& $row['log_forum_id_new']) {
+ $forum_name_new = ($fname =& $f_data[$fid]['forum_name']) ? $fname : 'id:' . $row['log_forum_id'];
+ }
- break;
- }
+ break;
+ }
- $msg .= " $row[log_msg]";
+ $msg .= " {$row['log_msg']}";
- $row_class = !($row_num & 1) ? $row_class_1 : $row_class_2;
+ $row_class = !($row_num & 1) ? $row_class_1 : $row_class_2;
- $datetime_href_s = url_arg($url, $datetime_key, date($dt_format, $row['log_time']));
- $datetime_href_s = url_arg($datetime_href_s, $daysback_key, 1);
+ $datetime_href_s = url_arg($url, $datetime_key, date($dt_format, $row['log_time']));
+ $datetime_href_s = url_arg($datetime_href_s, $daysback_key, 1);
- $template->assign_block_vars('log', array(
- 'ACTION_DESC' => $lang['LOG_ACTION']['LOG_TYPE'][$log_type_flip[$row['log_type_id']]],
- 'ACTION_HREF_S' => url_arg($url, $type_key, $row['log_type_id']),
+ $template->assign_block_vars('log', array(
+ 'ACTION_DESC' => $lang['LOG_ACTION']['LOG_TYPE'][$log_type_flip[$row['log_type_id']]],
+ 'ACTION_HREF_S' => url_arg($url, $type_key, $row['log_type_id']),
- 'USER_ID' => $row['log_user_id'],
- 'USERNAME' => $row['log_username'],
- 'USER_HREF_S' => url_arg($url, $user_key, $row['log_user_id']),
- 'USER_IP' => decode_ip($row['log_user_ip']),
+ 'USER_ID' => $row['log_user_id'],
+ 'USERNAME' => profile_url($row, true),
+ 'USER_HREF_S' => url_arg($url, $user_key, $row['log_user_id']),
+ 'USER_IP' => \TorrentPier\Helpers\IPHelper::isValid($row['log_user_ip']) ? \TorrentPier\Helpers\IPHelper::long2ip_extended($row['log_user_ip']) : '127.0.0.1',
- 'FORUM_ID' => $row['log_forum_id'],
- 'FORUM_HREF' => BB_ROOT . FORUM_URL . $row['log_forum_id'],
- 'FORUM_HREF_S' => url_arg($url, $forum_key, $row['log_forum_id']),
- 'FORUM_NAME' => htmlCHR($forum_name),
+ 'FORUM_ID' => $row['log_forum_id'],
+ 'FORUM_HREF' => BB_ROOT . FORUM_URL . $row['log_forum_id'],
+ 'FORUM_HREF_S' => url_arg($url, $forum_key, $row['log_forum_id']),
+ 'FORUM_NAME' => htmlCHR($forum_name),
- 'FORUM_ID_NEW' => $row['log_forum_id_new'],
- 'FORUM_HREF_NEW' => BB_ROOT . FORUM_URL . $row['log_forum_id_new'],
- 'FORUM_HREF_NEW_S' => url_arg($url, $forum_key, $row['log_forum_id_new']),
- 'FORUM_NAME_NEW' => htmlCHR($forum_name_new),
+ 'FORUM_ID_NEW' => $row['log_forum_id_new'],
+ 'FORUM_HREF_NEW' => BB_ROOT . FORUM_URL . $row['log_forum_id_new'],
+ 'FORUM_HREF_NEW_S' => url_arg($url, $forum_key, $row['log_forum_id_new']),
+ 'FORUM_NAME_NEW' => htmlCHR($forum_name_new),
- 'TOPIC_ID' => $row['log_topic_id'],
- 'TOPIC_HREF' => (!$topic_deleted) ? BB_ROOT . TOPIC_URL . $row['log_topic_id'] : '',
- 'TOPIC_HREF_S' => url_arg($url, $topic_key, $row['log_topic_id']),
- 'TOPIC_TITLE' => $topic_title,
+ 'TOPIC_ID' => $row['log_topic_id'],
+ 'TOPIC_HREF' => (!$topic_deleted) ? BB_ROOT . TOPIC_URL . $row['log_topic_id'] : '',
+ 'TOPIC_HREF_S' => url_arg($url, $topic_key, $row['log_topic_id']),
+ 'TOPIC_TITLE' => $topic_title,
- 'TOPIC_ID_NEW' => $row['log_topic_id_new'],
- 'TOPIC_HREF_NEW' => BB_ROOT . TOPIC_URL . $row['log_topic_id_new'],
- 'TOPIC_HREF_NEW_S' => url_arg($url, $topic_key, $row['log_topic_id_new']),
- 'TOPIC_TITLE_NEW' => $topic_title_new,
+ 'TOPIC_ID_NEW' => $row['log_topic_id_new'],
+ 'TOPIC_HREF_NEW' => BB_ROOT . TOPIC_URL . $row['log_topic_id_new'],
+ 'TOPIC_HREF_NEW_S' => url_arg($url, $topic_key, $row['log_topic_id_new']),
+ 'TOPIC_TITLE_NEW' => $topic_title_new,
- 'DATE' => bb_date($row['log_time'], 'j-M'),
- 'TIME' => bb_date($row['log_time'], 'H:i'),
- 'DATETIME_HREF_S' => $datetime_href_s,
- 'MSG' => $msg,
- 'ROW_CLASS' => $row_class,
+ 'DATETIME' => bb_date($row['log_time'], 'd-M-y H:i'),
+ 'DATETIME_HREF_S' => $datetime_href_s,
+ 'MSG' => $msg,
+ 'ROW_CLASS' => $row_class,
- ));
+ ));
- // Topics
- if ($topic_csv && empty($filter['topics'][$row['log_topic_title']]))
- {
- $template->assign_block_vars('topics', array(
- 'TOPIC_TITLE' => $row['log_topic_title'],
- ));
- $filter['topics'][$row['log_topic_title']] = true;
- }
- // Forums
- if ($forum_csv && empty($filter['forums'][$forum_name]))
- {
- $template->assign_block_vars('forums', array(
- 'FORUM_NAME' => htmlCHR($forum_name),
- ));
- $filter['forums'][$forum_name] = true;
- }
- // Users
- if ($user_csv && empty($filter['users'][$row['log_username']]))
- {
- $template->assign_block_vars('users', array(
- 'USERNAME' => $row['log_username'],
- ));
- $filter['users'][$row['log_username']] = true;
- }
- }
+ // Topics
+ if ($topic_csv && empty($filter['topics'][$row['log_topic_title']])) {
+ $template->assign_block_vars('topics', array(
+ 'TOPIC_TITLE' => $row['log_topic_title'],
+ ));
+ $filter['topics'][$row['log_topic_title']] = true;
+ }
+ // Forums
+ if ($forum_csv && empty($filter['forums'][$forum_name])) {
+ $template->assign_block_vars('forums', array(
+ 'FORUM_NAME' => htmlCHR($forum_name),
+ ));
+ $filter['forums'][$forum_name] = true;
+ }
+ // Users
+ if ($user_csv && empty($filter['users'])) {
+ $template->assign_block_vars('users', array(
+ 'USERNAME' => profile_url($row, true),
+ ));
+ $filter['users'] = true;
+ }
+ }
- $template->assign_vars(array(
- 'FILTERS' => ($topic_csv || $forum_csv || $user_csv),
- 'FILTER_TOPICS' => !empty($filter['topics']),
- 'FILTER_FORUMS' => !empty($filter['forums']),
- 'FILTER_USERS' => !empty($filter['users']),
- ));
-}
-else
-{
- $template->assign_block_vars('log_not_found', array());
+ $template->assign_vars(array(
+ 'FILTERS' => $topic_csv || $forum_csv || $user_csv,
+ 'FILTER_TOPICS' => !empty($filter['topics']),
+ 'FILTER_FORUMS' => !empty($filter['forums']),
+ 'FILTER_USERS' => !empty($filter['users']),
+ ));
+} else {
+ $template->assign_block_vars('log_not_found', []);
}
-//
-// Selects
-//
+// Select
$log_type_select = array($lang['ACTS_LOG_ALL_ACTIONS'] => $all_types) + $log_action->log_type_select;
-// Order select
-$order_options = ' '.$lang['ACTS_LOG_TIME'].' ';
-
$template->assign_vars(array(
- 'LOG_COLSPAN' => 4,
+ 'LOG_COLSPAN' => 4,
- 'DATETIME_NAME' => $datetime_key,
- 'DATETIME_VAL' => date('Y-m-d', $datetime_val),
- 'DAYSBACK_NAME' => $daysback_key,
- 'DAYSBACK_VAL' => $daysback_val,
- 'FIRST_LOG_TIME' => ($first_log_time) ? date('Y-m-d', $first_log_time) : $lang['ACC_NONE'],
+ 'DATETIME_NAME' => $datetime_key,
+ 'DATETIME_VAL' => date('Y-m-d', $datetime_val),
+ 'DAYSBACK_NAME' => $daysback_key,
+ 'DAYSBACK_VAL' => $daysback_val,
+ 'FIRST_LOG_TIME' => $first_log_time ? date('Y-m-d', $first_log_time) : $lang['ACC_NONE'],
- 'TITLE_MATCH_MAX' => $title_match_max_len,
- 'TITLE_MATCH_NAME' => $title_match_key,
- 'TITLE_MATCH_VAL' => $title_match_val,
+ 'TITLE_MATCH_MAX' => $title_match_max_len,
+ 'TITLE_MATCH_NAME' => $title_match_key,
+ 'TITLE_MATCH_VAL' => $title_match_val,
- 'ORDER_NAME' => '',
- 'ORDER_OPTIONS' => $order_options,
+ 'SORT_NAME' => $sort_key,
+ 'SORT_ASC' => $sort_asc,
+ 'SORT_DESC' => $sort_desc,
+ 'SORT_ASC_CHECKED' => ($sort_val == $sort_asc) ? HTML_CHECKED : '',
+ 'SORT_DESC_CHECKED' => ($sort_val == $sort_desc) ? HTML_CHECKED : '',
- 'SORT_NAME' => $sort_key,
- 'SORT_ASC' => $sort_asc,
- 'SORT_DESC' => $sort_desc,
- 'SORT_ASC_CHECKED' => ($sort_val == $sort_asc) ? HTML_CHECKED : '',
- 'SORT_DESC_CHECKED' => ($sort_val == $sort_desc) ? HTML_CHECKED : '',
+ 'SEL_FORUM' => get_forum_select('admin', "{$forum_key}[]", $forum_selected, $max_forum_name_len, $select_max_height, '', $all_forums),
+ 'SEL_LOG_TYPE' => build_select("{$type_key}[]", $log_type_select, $type_selected, 60, $select_max_height),
+ 'SEL_USERS' => build_select("{$user_key}[]", $users, $user_selected, 16, $select_max_height),
- 'SEL_FORUM' => get_forum_select('admin', "{$forum_key}[]", $forum_selected, $max_forum_name_len, $select_max_height, '', $all_forums),
- 'SEL_LOG_TYPE' => build_select("{$type_key}[]", $log_type_select, $type_selected, 60, $select_max_height),
- 'SEL_USERS' => build_select("{$user_key}[]", $users, $user_selected, 16, $select_max_height),
-
- 'S_LOG_ACTION' => "admin_log.php",
- 'TOPIC_CSV' => $topic_csv,
+ 'S_LOG_ACTION' => 'admin_log.php',
+ 'TOPIC_CSV' => $topic_csv,
));
-print_page('admin_log.tpl', 'admin');
\ No newline at end of file
+print_page('admin_log.tpl', 'admin');
diff --git a/admin/admin_mass_email.php b/admin/admin_mass_email.php
index a9285ebf0..51902d960 100644
--- a/admin/admin_mass_email.php
+++ b/admin/admin_mass_email.php
@@ -1,102 +1,105 @@
get('emailer.enabled')) {
+ bb_die($lang['EMAILER_DISABLED']);
+}
-$errors = $user_id_sql = array();
+set_time_limit(1200);
-if (isset($_POST['submit']))
-{
- if (!$subject) $errors[] = $lang['EMPTY_SUBJECT'];
- if (!$message) $errors[] = $lang['EMPTY_MESSAGE'];
- if (!$group_id) $errors[] = $lang['GROUP_NOT_EXIST'];
+$subject = trim(request_var('subject', ''));
+$message = (string)request_var('message', '');
+$group_id = (int)request_var(POST_GROUPS_URL, 0);
+$reply_to = (string)request_var('reply_to', config()->get('board_email'));
+$message_type = (string)request_var('message_type', '');
- if (!$errors)
- {
- $sql = DB()->fetch_rowset("SELECT ban_userid FROM ". BB_BANLIST ." WHERE ban_userid != 0");
+$errors = $user_id_sql = [];
- foreach ($sql as $row)
- {
- $user_id_sql[] = ','. $row['ban_userid'];
- }
- $user_id_sql = join('', $user_id_sql);
+if (isset($_POST['submit'])) {
+ if (!$subject) {
+ $errors[] = $lang['EMPTY_SUBJECT'];
+ }
+ if (!$message) {
+ $errors[] = $lang['EMPTY_MESSAGE'];
+ }
+ if (!$group_id) {
+ $errors[] = $lang['GROUP_NOT_EXIST'];
+ }
- if ($group_id != -1)
- {
- $user_list = DB()->fetch_rowset("
+ if (!$errors) {
+ $banned_users = ($get_banned_users = get_banned_users()) ? (', ' . implode(', ', $get_banned_users)) : '';
+
+ if ($group_id != -1) {
+ $user_list = DB()->fetch_rowset('
SELECT u.username, u.user_email, u.user_lang
- FROM ". BB_USERS ." u, ". BB_USER_GROUP ." ug
+ FROM ' . BB_USERS . ' u, ' . BB_USER_GROUP . " ug
WHERE ug.group_id = $group_id
AND ug.user_pending = 0
AND u.user_id = ug.user_id
AND u.user_active = 1
- AND u.user_id NOT IN(". EXCLUDED_USERS_CSV . $user_id_sql .")
- ");
- }
- else
- {
- $user_list = DB()->fetch_rowset("
+ AND u.user_id NOT IN(" . EXCLUDED_USERS . $banned_users . ')
+ ');
+ } else {
+ $user_list = DB()->fetch_rowset('
SELECT username, user_email, user_lang
- FROM ". BB_USERS ."
+ FROM ' . BB_USERS . '
WHERE user_active = 1
- AND user_id NOT IN(". EXCLUDED_USERS_CSV . $user_id_sql .")
- ");
- }
+ AND user_id NOT IN(' . EXCLUDED_USERS . $banned_users . ')
+ ');
+ }
- require(CLASS_DIR .'emailer.php');
+ foreach ($user_list as $i => $row) {
+ // Sending email
+ $emailer = new TorrentPier\Emailer();
- foreach ($user_list as $i => $row)
- {
- $emailer = new emailer($bb_cfg['smtp_delivery']);
+ $emailer->set_to($row['user_email'], $row['username']);
+ $emailer->set_subject($subject);
+ $emailer->set_reply($reply_to);
- $emailer->from($bb_cfg['sitename'] ." <{$bb_cfg['board_email']}>");
- $emailer->email_address($row['username'] ." <{$row['user_email']}>");
- $emailer->use_template('admin_send_email');
+ $emailer->set_template('admin_send_email');
+ $emailer->assign_vars(['MESSAGE' => trim(html_entity_decode($message))]);
- $emailer->assign_vars(array(
- 'SUBJECT' => html_entity_decode($subject),
- 'MESSAGE' => html_entity_decode($message),
- ));
-
- $emailer->send();
- $emailer->reset();
- }
- }
+ $emailer->send($message_type);
+ }
+ }
}
//
// Generate page
//
-$sql = "SELECT group_id, group_name
- FROM ". BB_GROUPS ."
+$sql = 'SELECT group_id, group_name
+ FROM ' . BB_GROUPS . '
WHERE group_single_user = 0
ORDER BY group_name
-";
+';
-$groups = array('-- '. $lang['ALL_USERS'] .' --' => -1);
-foreach (DB()->fetch_rowset($sql) as $row)
-{
- $groups[$row['group_name']] = $row['group_id'];
+$groups = ['-- ' . $lang['ALL_USERS'] . ' --' => -1];
+foreach (DB()->fetch_rowset($sql) as $row) {
+ $groups[$row['group_name']] = $row['group_id'];
}
-$template->assign_vars(array(
- 'MESSAGE' => $message,
- 'SUBJECT' => $subject,
+$template->assign_vars([
+ 'MESSAGE' => $message,
+ 'SUBJECT' => $subject,
+ 'REPLY_TO' => $reply_to,
- 'ERROR_MESSAGE' => ($errors) ? join(' ', array_unique($errors)) : '',
+ 'ERROR_MESSAGE' => $errors ? implode(' ', array_unique($errors)) : '',
- 'S_USER_ACTION' => 'admin_mass_email.php',
- 'S_GROUP_SELECT' => build_select(POST_GROUPS_URL, $groups),
-));
+ 'S_USER_ACTION' => 'admin_mass_email.php',
+ 'S_GROUP_SELECT' => build_select(POST_GROUPS_URL, $groups)
+]);
-print_page('admin_mass_email.tpl', 'admin');
\ No newline at end of file
+print_page('admin_mass_email.tpl', 'admin');
diff --git a/admin/admin_migrations.php b/admin/admin_migrations.php
new file mode 100644
index 000000000..e416d81fb
--- /dev/null
+++ b/admin/admin_migrations.php
@@ -0,0 +1,79 @@
+getMigrationStatus();
+$schemaInfo = $migrationStatus->getSchemaInfo();
+
+// Template variables
+$template->assign_vars([
+ 'PAGE_TITLE' => __('MIGRATIONS_STATUS'),
+ 'CURRENT_TIME' => date('Y-m-d H:i:s'),
+
+ // Migration status individual fields
+ 'MIGRATION_TABLE_EXISTS' => $status['table_exists'],
+ 'MIGRATION_CURRENT_VERSION' => $status['current_version'],
+ 'MIGRATION_APPLIED_COUNT' => count($status['applied_migrations']),
+ 'MIGRATION_PENDING_COUNT' => count($status['pending_migrations']),
+
+ // Setup status fields
+ 'SETUP_REQUIRES_SETUP' => $status['requires_setup'] ?? false,
+ 'SETUP_TYPE' => $status['setup_status']['type'] ?? __('UNKNOWN'),
+ 'SETUP_MESSAGE' => $status['setup_status']['message'] ?? '',
+ 'SETUP_ACTION_REQUIRED' => $status['setup_status']['action_required'] ?? false,
+ 'SETUP_INSTRUCTIONS' => $status['setup_status']['instructions'] ?? '',
+
+ // Schema info individual fields
+ 'SCHEMA_DATABASE_NAME' => $schemaInfo['database_name'],
+ 'SCHEMA_TABLE_COUNT' => $schemaInfo['table_count'],
+ 'SCHEMA_SIZE_MB' => $schemaInfo['size_mb'],
+]);
+
+// Assign migration data for template
+if (!empty($status['applied_migrations'])) {
+ foreach ($status['applied_migrations'] as $i => $migration) {
+ $template->assign_block_vars('applied_migrations', [
+ 'VERSION' => $migration['version'],
+ 'NAME' => $migration['migration_name'] ?? __('UNKNOWN'),
+ 'START_TIME' => $migration['start_time'] ?? __('UNKNOWN'),
+ 'END_TIME' => $migration['end_time'] ?? __('UNKNOWN'),
+ 'ROW_CLASS' => ($i % 2) ? 'row1' : 'row2'
+ ]);
+ }
+}
+
+if (!empty($status['pending_migrations'])) {
+ foreach ($status['pending_migrations'] as $i => $migration) {
+ $template->assign_block_vars('pending_migrations', [
+ 'VERSION' => $migration['version'],
+ 'NAME' => $migration['name'],
+ 'FILENAME' => $migration['filename'],
+ 'ROW_CLASS' => ($i % 2) ? 'row1' : 'row2'
+ ]);
+ }
+}
+
+// Output template using standard admin pattern
+print_page('admin_migrations.tpl', 'admin');
diff --git a/admin/admin_phpinfo.php b/admin/admin_phpinfo.php
index 1c70efd1e..1db2a7305 100644
--- a/admin/admin_phpinfo.php
+++ b/admin/admin_phpinfo.php
@@ -1,10 +1,29 @@
sql_query($sql))
- {
- bb_die('Could not obtain ranks data #1');
- }
+if ($mode != '') {
+ if ($mode == 'edit' || $mode == 'add') {
+ //
+ // They want to add a new rank, show the form.
+ //
+ $rank_id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
- $rank_info = DB()->sql_fetchrow($result);
- $s_hidden_fields .= ' ';
- }
- else
- {
- $rank_info['rank_special'] = 0;
- }
+ $s_hidden_fields = '';
- $s_hidden_fields .= ' ';
+ if ($mode == 'edit') {
+ if (empty($rank_id)) {
+ bb_die($lang['MUST_SELECT_RANK']);
+ }
- $rank_is_special = !empty($rank_info['rank_special']) ? HTML_CHECKED : '';
- $rank_is_not_special = empty($rank_info['rank_special']) ? HTML_CHECKED : '';
+ $sql = 'SELECT * FROM ' . BB_RANKS . " WHERE rank_id = $rank_id";
+ if (!$result = DB()->sql_query($sql)) {
+ bb_die('Could not obtain ranks data #1');
+ }
- $template->assign_vars(array(
- 'TPL_RANKS_EDIT' => true,
+ $rank_info = DB()->sql_fetchrow($result);
+ $s_hidden_fields .= ' ';
+ }
- 'RANK' => !empty($rank_info['rank_title']) ? $rank_info['rank_title'] : '',
- 'SPECIAL_RANK' => $rank_is_special,
- 'NOT_SPECIAL_RANK' => $rank_is_not_special,
- 'MINIMUM' => ($rank_is_special) ? '' : @$rank_info['rank_min'],
- 'IMAGE' => !empty($rank_info['rank_image']) ? $rank_info['rank_image'] : 'images/ranks/rank_image.png',
- 'STYLE' => !empty($rank_info['rank_style']) ? $rank_info['rank_style'] : '',
- 'IMAGE_DISPLAY' => !empty($rank_info['rank_image']) ? ' ' : '',
+ $s_hidden_fields .= ' ';
- 'S_RANK_ACTION' => "admin_ranks.php",
- 'S_HIDDEN_FIELDS' => $s_hidden_fields,
- ));
- }
- elseif ($mode == 'save')
- {
- //
- // Ok, they sent us our info, let's update it.
- //
+ $template->assign_vars([
+ 'TPL_RANKS_EDIT' => true,
- $rank_id = (isset($_POST['id'])) ? intval($_POST['id']) : 0;
- $rank_title = (isset($_POST['title'])) ? trim($_POST['title']) : '';
- $rank_style = (isset($_POST['style'])) ? trim($_POST['style']) : '';
- $special_rank = ($_POST['special_rank'] == 1) ? TRUE : 0;
- $min_posts = (isset($_POST['min_posts'])) ? intval($_POST['min_posts']) : -1;
- $rank_image = ((isset($_POST['rank_image']))) ? trim($_POST['rank_image']) : '';
+ 'RANK' => !empty($rank_info['rank_title']) ? $rank_info['rank_title'] : '',
+ 'IMAGE' => !empty($rank_info['rank_image']) ? $rank_info['rank_image'] : 'styles/images/ranks/rank_image.png',
+ 'STYLE' => !empty($rank_info['rank_style']) ? $rank_info['rank_style'] : '',
+ 'IMAGE_DISPLAY' => !empty($rank_info['rank_image']) ? ' ' : '',
- if ($rank_title == '')
- {
- bb_die($lang['MUST_SELECT_RANK']);
- }
+ 'S_RANK_ACTION' => 'admin_ranks.php',
+ 'S_HIDDEN_FIELDS' => $s_hidden_fields
+ ]);
+ } elseif ($mode == 'save') {
+ //
+ // Ok, they sent us our info, let's update it.
+ //
- if ($special_rank == 1)
- {
- $max_posts = -1;
- $min_posts = -1;
- }
+ $rank_id = isset($_POST['id']) ? (int)$_POST['id'] : 0;
+ $rank_title = isset($_POST['title']) ? trim($_POST['title']) : '';
+ $rank_style = isset($_POST['style']) ? trim($_POST['style']) : '';
+ $rank_image = isset($_POST['rank_image']) ? trim($_POST['rank_image']) : '';
- //
- // The rank image has to be a jpg, gif or png
- //
- if ($rank_image != '')
- {
- if (!preg_match('/(\.gif|\.png|\.jpg)$/is', $rank_image))
- {
- $rank_image = '';
- }
- }
+ if ($rank_title == '') {
+ bb_die($lang['MUST_SELECT_RANK']);
+ }
- if ($rank_id)
- {
- if (!$special_rank)
- {
- $sql = "UPDATE " . BB_USERS . " SET user_rank = 0 WHERE user_rank = $rank_id";
- if (!$result = DB()->sql_query($sql))
- {
- bb_die($lang['NO_UPDATE_RANKS']);
- }
- }
- $sql = "UPDATE " . BB_RANKS . "
- SET rank_title = '". DB()->escape($rank_title) ."',
- rank_special = $special_rank,
- rank_min = $min_posts,
- rank_image = '". DB()->escape($rank_image) . "',
- rank_style = '". DB()->escape($rank_style) ."'
+ //
+ // The rank image has to be a jpg, gif or png
+ //
+ if ($rank_image != '') {
+ if (!preg_match('/(\.gif|\.png|\.jpg|\.jpeg|\.bmp|\.webp|\.avif\.ico)$/is', $rank_image)) {
+ $rank_image = '';
+ }
+ }
+
+ if ($rank_id) {
+
+ $sql = 'UPDATE ' . BB_USERS . " SET user_rank = 0 WHERE user_rank = $rank_id";
+ if (!$result = DB()->sql_query($sql)) {
+ bb_die($lang['NO_UPDATE_RANKS']);
+ }
+
+ $sql = 'UPDATE ' . BB_RANKS . "
+ SET rank_title = '" . DB()->escape($rank_title) . "',
+ rank_image = '" . DB()->escape($rank_image) . "',
+ rank_style = '" . DB()->escape($rank_style) . "'
WHERE rank_id = $rank_id";
- $message = $lang['RANK_UPDATED'];
- }
- else
- {
- $sql = "INSERT INTO " . BB_RANKS . " (rank_title, rank_special, rank_min, rank_image, rank_style)
- VALUES ('". DB()->escape($rank_title) ."', $special_rank, $min_posts, '". DB()->escape($rank_image) ."', '". DB()->escape($rank_style) ."')";
+ $message = $lang['RANK_UPDATED'];
+ } else {
+ $sql = 'INSERT INTO ' . BB_RANKS . " (rank_title, rank_image, rank_style)
+ VALUES ('" . DB()->escape($rank_title) . "', '" . DB()->escape($rank_image) . "', '" . DB()->escape($rank_style) . "')";
- $message = $lang['RANK_ADDED'];
- }
+ $message = $lang['RANK_ADDED'];
+ }
- if (!$result = DB()->sql_query($sql))
- {
- bb_die('Could not update / insert into ranks table');
- }
+ if (!$result = DB()->sql_query($sql)) {
+ bb_die('Could not update / insert into ranks table');
+ }
- $message .= ' ' . sprintf($lang['CLICK_RETURN_RANKADMIN'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' ');
+ $message .= ' ' . sprintf($lang['CLICK_RETURN_RANKADMIN'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' ');
- $datastore->update('ranks');
+ $datastore->update('ranks');
- bb_die($message);
- }
- elseif ($mode == 'delete')
- {
- //
- // Ok, they want to delete their rank
- //
+ bb_die($message);
+ } elseif ($mode == 'delete') {
+ //
+ // Ok, they want to delete their rank
+ //
- if (isset($_POST['id']) || isset($_GET['id']))
- {
- $rank_id = (isset($_POST['id'])) ? intval($_POST['id']) : intval($_GET['id']);
- }
- else
- {
- $rank_id = 0;
- }
+ $confirmed = isset($_POST['confirm']);
+ if (isset($_POST['id']) || isset($_GET['id'])) {
+ $rank_id = isset($_POST['id']) ? (int)$_POST['id'] : (int)$_GET['id'];
+ } else {
+ $rank_id = 0;
+ }
- if ($rank_id)
- {
- $sql = "DELETE FROM " . BB_RANKS . " WHERE rank_id = $rank_id";
+ if ($confirmed) {
+ if ($rank_id) {
+ $sql = 'DELETE FROM ' . BB_RANKS . " WHERE rank_id = $rank_id";
- if (!$result = DB()->sql_query($sql))
- {
- bb_die('Could not delete rank data');
- }
+ if (!$result = DB()->sql_query($sql)) {
+ bb_die('Could not delete rank data');
+ }
- $sql = "UPDATE " . BB_USERS . " SET user_rank = 0 WHERE user_rank = $rank_id";
- if (!$result = DB()->sql_query($sql))
- {
- bb_die($lang['NO_UPDATE_RANKS']);
- }
+ $sql = 'UPDATE ' . BB_USERS . " SET user_rank = 0 WHERE user_rank = $rank_id";
+ if (!$result = DB()->sql_query($sql)) {
+ bb_die($lang['NO_UPDATE_RANKS']);
+ }
- $datastore->update('ranks');
+ $datastore->update('ranks');
- bb_die($lang['RANK_REMOVED'] . ' ' . sprintf($lang['CLICK_RETURN_RANKADMIN'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '));
- }
- else
- {
- bb_die($lang['MUST_SELECT_RANK']);
- }
- }
- else
- {
- bb_die('Invalid mode');
- }
-}
-else
-{
- //
- // Show the default page
- //
- $sql = "SELECT * FROM " . BB_RANKS . " ORDER BY rank_min, rank_title";
- if (!$result = DB()->sql_query($sql))
- {
- bb_die('Could not obtain ranks data #2');
- }
- $rank_count = DB()->num_rows($result);
- $rank_rows = DB()->sql_fetchrowset($result);
+ bb_die($lang['RANK_REMOVED'] . ' ' . sprintf($lang['CLICK_RETURN_RANKADMIN'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '));
+ } else {
+ bb_die($lang['MUST_SELECT_RANK']);
+ }
+ } else {
+ $hidden_fields = ' ';
+ $hidden_fields .= ' ';
- $template->assign_vars(array(
- 'TPL_RANKS_LIST' => true,
- 'S_RANKS_ACTION' => "admin_ranks.php",
- ));
+ print_confirmation([
+ 'FORM_ACTION' => 'admin_ranks.php',
+ 'HIDDEN_FIELDS' => $hidden_fields,
+ ]);
+ }
+ } else {
+ bb_die('Invalid mode');
+ }
+} else {
+ //
+ // Show the default page
+ //
+ $sql = 'SELECT * FROM ' . BB_RANKS . ' ORDER BY rank_title';
+ if (!$result = DB()->sql_query($sql)) {
+ bb_die('Could not obtain ranks data #2');
+ }
+ $rank_count = DB()->num_rows($result);
+ $rank_rows = DB()->sql_fetchrowset($result);
- for ($i = 0; $i < $rank_count; $i++)
- {
- $rank = $rank_rows[$i]['rank_title'];
- $special_rank = $rank_rows[$i]['rank_special'];
- $rank_id = $rank_rows[$i]['rank_id'];
- $rank_min = $rank_rows[$i]['rank_min'];
+ $template->assign_vars([
+ 'TPL_RANKS_LIST' => true,
+ 'S_RANKS_ACTION' => 'admin_ranks.php'
+ ]);
- if ($special_rank == 1)
- {
- $rank_min = $rank_max = '-';
- }
+ for ($i = 0; $i < $rank_count; $i++) {
+ $rank = $rank_rows[$i]['rank_title'];
+ $rank_id = $rank_rows[$i]['rank_id'];
- $row_class = !($i % 2) ? 'row1' : 'row2';
+ $row_class = !($i % 2) ? 'row1' : 'row2';
- $rank_is_special = ($special_rank) ? $lang['YES'] : $lang['NO'];
+ $template->assign_block_vars('ranks', [
+ 'ROW_CLASS' => $row_class,
+ 'RANK' => $rank,
+ 'STYLE' => $rank_rows[$i]['rank_style'],
+ 'IMAGE_DISPLAY' => $rank_rows[$i]['rank_image'] ? ' ' : '',
- $template->assign_block_vars('ranks', array(
- 'ROW_CLASS' => $row_class,
- 'RANK' => $rank,
- 'STYLE' => $rank_rows[$i]['rank_style'],
- 'IMAGE_DISPLAY' => ($rank_rows[$i]['rank_image']) ? ' ' : '',
- 'SPECIAL_RANK' => $rank_is_special,
- 'RANK_MIN' => $rank_min,
-
- 'U_RANK_EDIT' => "admin_ranks.php?mode=edit&id=$rank_id",
- 'U_RANK_DELETE' => "admin_ranks.php?mode=delete&id=$rank_id",
- ));
- }
+ 'U_RANK_EDIT' => "admin_ranks.php?mode=edit&id=$rank_id",
+ 'U_RANK_DELETE' => "admin_ranks.php?mode=delete&id=$rank_id"
+ ]);
+ }
}
-print_page('admin_ranks.tpl', 'admin');
\ No newline at end of file
+print_page('admin_ranks.tpl', 'admin');
diff --git a/admin/admin_rebuild_search.php b/admin/admin_rebuild_search.php
index 391c2917f..cdd4fe32e 100644
--- a/admin/admin_rebuild_search.php
+++ b/admin/admin_rebuild_search.php
@@ -1,447 +1,422 @@
query("
- UPDATE ". BB_SEARCH_REBUILD ." SET
- rebuild_session_status = ". REBUILD_SEARCH_ABORTED ."
+if (isset($_REQUEST['cancel_button'])) {
+ // update the rebuild_status
+ if ($last_session_id) {
+ DB()->query('
+ UPDATE ' . BB_SEARCH_REBUILD . ' SET
+ rebuild_session_status = ' . REBUILD_SEARCH_ABORTED . "
WHERE rebuild_session_id = $last_session_id
");
- }
+ }
- bb_die(sprintf($lang['REBUILD_SEARCH_ABORTED'], $last_session_data['end_post_id']) .' '. sprintf($lang['CLICK_RETURN_REBUILD_SEARCH'], '', ' '));
+ bb_die(sprintf($lang['REBUILD_SEARCH_ABORTED'], $last_session_data['end_post_id']) . ' ' . sprintf($lang['CLICK_RETURN_REBUILD_SEARCH'], '', ' '));
}
// from which post to start processing
-$start = abs(intval(@$_REQUEST['start']));
+$start = isset($_REQUEST['start']) ? abs((int)$_REQUEST['start']) : 0;
// get the total number of posts in the db
$total_posts = get_total_posts();
// clear the search tables and clear mode (delete or truncate)
-$clear_search = isset($_REQUEST['clear_search']) ? (int) $_REQUEST['clear_search'] : 0;
+$clear_search = isset($_REQUEST['clear_search']) ? (int)$_REQUEST['clear_search'] : 0;
// get the number of total/session posts already processed
-$total_posts_processed = ( $start != 0 ) ? get_total_posts('before', $last_session_data['end_post_id']) : 0;
-$session_posts_processed = ( $mode == 'refresh' ) ? get_processed_posts('session') : 0;
+$total_posts_processed = ($start != 0) ? get_total_posts('before', $last_session_data['end_post_id']) : 0;
+$session_posts_processed = ($mode == 'refresh') ? get_processed_posts('session') : 0;
// find how many posts aren't processed
$total_posts_processing = $total_posts - $total_posts_processed;
// how many posts to process in this session
-if ($session_posts_processing = @intval($_REQUEST['session_posts_processing']))
-{
- if ($mode == 'submit')
- {
- // check if we passed over total_posts just after submitting
- if ($session_posts_processing + $total_posts_processed > $total_posts)
- {
- $session_posts_processing = $total_posts - $total_posts_processed;
- }
- }
- // correct it when posts are deleted during processing
- $session_posts_processing = ($session_posts_processing > $total_posts) ? $total_posts : $session_posts_processing;
-}
-else
-{
- // if we have finished, get all the posts, else only the remaining
- $session_posts_processing = (!$total_posts_processing) ? $total_posts : $total_posts_processing;
+$session_posts_processing = isset($_REQUEST['session_posts_processing']) ? (int)$_REQUEST['session_posts_processing'] : null;
+if (null !== $session_posts_processing) {
+ if ($mode == 'submit') {
+ // check if we passed over total_posts just after submitting
+ if ($session_posts_processing + $total_posts_processed > $total_posts) {
+ $session_posts_processing = $total_posts - $total_posts_processed;
+ }
+ }
+ // correct it when posts are deleted during processing
+ $session_posts_processing = ($session_posts_processing > $total_posts) ? $total_posts : $session_posts_processing;
+} else {
+ // if we have finished, get all the posts, else only the remaining
+ $session_posts_processing = (!$total_posts_processing) ? $total_posts : $total_posts_processing;
}
// how many posts to process per cycle
-$post_limit = isset($_REQUEST['post_limit']) ? (int) $_REQUEST['post_limit'] : $def_post_limit;
+$post_limit = isset($_REQUEST['post_limit']) ? (int)$_REQUEST['post_limit'] : $def_post_limit;
// correct the post_limit when we pass over it
-if ( $session_posts_processed + $post_limit > $session_posts_processing )
-{
- $post_limit = $session_posts_processing - $session_posts_processed;
+if ($session_posts_processed + $post_limit > $session_posts_processing) {
+ $post_limit = $session_posts_processing - $session_posts_processed;
}
// how much time to wait per cycle
-if (isset($_REQUEST['time_limit']))
-{
- $time_limit = (int) $_REQUEST['time_limit'];
-}
-else
-{
- $time_limit = $def_time_limit;
- $time_limit_explain = $lang['TIME_LIMIT_EXPLAIN'];
+if (isset($_REQUEST['time_limit'])) {
+ $time_limit = (int)$_REQUEST['time_limit'];
+} else {
+ $time_limit = $def_time_limit;
+ $time_limit_explain = $lang['TIME_LIMIT_EXPLAIN'];
- // check for safe mode timeout
- if ( ini_get('safe_mode') )
- {
- // get execution time
- $max_execution_time = ini_get('max_execution_time');
- $time_limit_explain .= ' ' . sprintf($lang['TIME_LIMIT_EXPLAIN_SAFE'], $max_execution_time);
+ // check for webserver timeout (IE returns null)
+ if (isset($_SERVER['HTTP_KEEP_ALIVE'])) {
+ // get webserver timeout
+ $webserver_timeout = (int)$_SERVER['HTTP_KEEP_ALIVE'];
+ $time_limit_explain .= ' ' . sprintf($lang['TIME_LIMIT_EXPLAIN_WEBSERVER'], $webserver_timeout);
- if ( $time_limit > $max_execution_time )
- {
- $time_limit = $max_execution_time;
- }
- }
-
- // check for webserver timeout (IE returns null)
- if ( isset($_SERVER["HTTP_KEEP_ALIVE"]) )
- {
- // get webserver timeout
- $webserver_timeout = intval($_SERVER["HTTP_KEEP_ALIVE"]);
- $time_limit_explain .= ' ' . sprintf($lang['TIME_LIMIT_EXPLAIN_WEBSERVER'], $webserver_timeout);
-
- if ( $time_limit > $webserver_timeout )
- {
- $time_limit = $webserver_timeout;
- }
- }
+ if ($time_limit > $webserver_timeout) {
+ $time_limit = $webserver_timeout;
+ }
+ }
}
// how much time to wait between page refreshes
-$refresh_rate = isset($_REQUEST['refresh_rate']) ? (int) $_REQUEST['refresh_rate'] : $def_refresh_rate;
+$refresh_rate = isset($_REQUEST['refresh_rate']) ? (int)$_REQUEST['refresh_rate'] : $def_refresh_rate;
// check if the user gave wrong input
-if ($mode == 'submit')
-{
- if (($session_posts_processing || $post_limit || $refresh_rate || $time_limit) <= 0)
- {
- bb_die($lang['WRONG_INPUT'] .' '. sprintf($lang['CLICK_RETURN_REBUILD_SEARCH'], '', ' '));
- }
+if ($mode == 'submit') {
+ if (($session_posts_processing || $post_limit || $refresh_rate || $time_limit) <= 0) {
+ bb_die($lang['WRONG_INPUT'] . ' ' . sprintf($lang['CLICK_RETURN_REBUILD_SEARCH'], '', ' '));
+ }
}
// Increase maximum execution time in case of a lot of posts, but don't complain about it if it isn't allowed.
-@set_time_limit($time_limit + 20);
+set_time_limit($time_limit + 20);
// check if we are should start processing
-if ($mode == 'submit' || $mode == 'refresh')
-{
- // check if we are in the beginning of processing
- if ($start == 0)
- {
- $last_session_data = get_empty_last_session_data();
- clear_search_tables($clear_search);
- }
+if ($mode == 'submit' || $mode == 'refresh') {
+ // check if we are in the beginning of processing
+ if ($start == 0) {
+ $last_session_data = get_empty_last_session_data();
+ clear_search_tables($clear_search);
+ }
- // get the db sizes
- list($search_data_size, $search_index_size, $search_tables_size) = get_db_sizes();
+ // get the db sizes
+ [$search_data_size, $search_index_size, $search_tables_size] = get_db_sizes();
- // get the post subject/text of each post
- $result = DB()->query("
+ // get the post subject/text of each post
+ $result = DB()->query("
SELECT
pt.post_id, pt.post_text,
IF(p.post_id = t.topic_first_post_id, t.topic_title, '') AS post_subject
FROM
- ". BB_POSTS_TEXT ." pt,
- ". BB_POSTS ." p,
- ". BB_TOPICS ." t
+ " . BB_POSTS_TEXT . ' pt,
+ ' . BB_POSTS . ' p,
+ ' . BB_TOPICS . ' t
WHERE p.post_id = pt.post_id
AND t.topic_id = p.topic_id
- AND p.poster_id NOT IN(". BOT_UID .")
+ AND p.poster_id NOT IN(' . BOT_UID . ")
AND pt.post_id >= $start
ORDER BY pt.post_id ASC
LIMIT $post_limit
");
- $expire_time = $start_time + $time_limit - 5;
- $start_post_id = $end_post_id = $num_rows = 0;
- $timer_expired = false;
- $words_sql = array();
+ $expire_time = $start_time + $time_limit - 5;
+ $start_post_id = $end_post_id = $num_rows = 0;
+ $timer_expired = false;
+ $words_sql = [];
- while ($row = DB()->fetch_next($result) AND !$timer_expired)
- {
- @set_time_limit(600);
- $start_post_id = ($num_rows == 0) ? $row['post_id'] : $start_post_id;
- $end_post_id = $row['post_id'];
+ while ($row = DB()->fetch_next($result) and !$timer_expired) {
+ set_time_limit(600);
+ $start_post_id = ($num_rows == 0) ? $row['post_id'] : $start_post_id;
+ $end_post_id = $row['post_id'];
- // Get search words
- $s_post_text = str_replace('\n', "\n", $row['post_text']);
- $s_post_subject = str_replace('\n', "\n", $row['post_subject']);
- $words_sql[] = array(
- 'post_id' => (int) $row['post_id'],
- 'search_words' => add_search_words($row['post_id'], stripslashes($s_post_text), stripslashes($s_post_subject), true),
- );
+ // Get search words
+ $s_post_text = str_replace('\n', "\n", $row['post_text']);
+ $s_post_subject = str_replace('\n', "\n", $row['post_subject']);
+ $words_sql[] = array(
+ 'post_id' => (int)$row['post_id'],
+ 'search_words' => add_search_words($row['post_id'], stripslashes($s_post_text), stripslashes($s_post_subject), true),
+ );
- $timer_expired = (TIMENOW > $expire_time);
- $num_rows++;
- }
+ $timer_expired = (TIMENOW > $expire_time);
+ $num_rows++;
+ }
- // Store search words
- if ($words_sql)
- {
- DB()->query("REPLACE INTO ". BB_POSTS_SEARCH . DB()->build_array('MULTI_INSERT', $words_sql));
- }
+ // Store search words
+ if ($words_sql) {
+ DB()->query('REPLACE INTO ' . BB_POSTS_SEARCH . DB()->build_array('MULTI_INSERT', $words_sql));
+ }
- // find how much time the last cycle took
- $last_cycle_time = intval(TIMENOW - $start_time);
+ // find how much time the last cycle took
+ $last_cycle_time = (int)(TIMENOW - $start_time);
- // check if we had any data
- if ($num_rows != 0)
- {
- if ($mode == 'submit')
- {
- // insert a new session entry
- $args = DB()->build_array('INSERT', array(
- 'end_post_id' => (int) $end_post_id,
- 'end_time' => (int) TIMENOW,
- 'last_cycle_time' => (int) $last_cycle_time,
- 'session_time' => (int) $last_cycle_time,
- 'session_posts' => (int) $num_rows,
- 'session_cycles' => (int) 1,
- 'start_post_id' => (int) $start_post_id,
- 'start_time' => (int) $start_time,
- 'search_size' => (int) $search_tables_size,
- 'rebuild_session_status' => REBUILD_SEARCH_PROCESSED,
- ));
- DB()->query("REPLACE INTO ". BB_SEARCH_REBUILD . $args);
- }
- else // refresh
- {
- // update the last session entry
- DB()->query("
- UPDATE ". BB_SEARCH_REBUILD ." SET
+ // check if we had any data
+ if ($num_rows != 0) {
+ if ($mode == 'submit') {
+ // insert a new session entry
+ $args = DB()->build_array('INSERT', array(
+ 'end_post_id' => (int)$end_post_id,
+ 'end_time' => (int)TIMENOW,
+ 'last_cycle_time' => (int)$last_cycle_time,
+ 'session_time' => (int)$last_cycle_time,
+ 'session_posts' => (int)$num_rows,
+ 'session_cycles' => (int)1,
+ 'start_post_id' => (int)$start_post_id,
+ 'start_time' => (int)$start_time,
+ 'search_size' => (int)$search_tables_size,
+ 'rebuild_session_status' => REBUILD_SEARCH_PROCESSED,
+ ));
+ DB()->query('REPLACE INTO ' . BB_SEARCH_REBUILD . $args);
+ } else {
+ // refresh
+
+ // update the last session entry
+ DB()->query('
+ UPDATE ' . BB_SEARCH_REBUILD . " SET
end_post_id = $end_post_id,
- end_time = ". TIMENOW .",
+ end_time = " . TIMENOW . ",
last_cycle_time = $last_cycle_time,
session_time = session_time + $last_cycle_time,
session_posts = session_posts + $num_rows,
session_cycles = session_cycles + 1,
- rebuild_session_status = ". REBUILD_SEARCH_PROCESSED ."
+ rebuild_session_status = " . REBUILD_SEARCH_PROCESSED . "
WHERE rebuild_session_id = $last_session_id
");
- }
- }
+ }
+ }
- $last_session_data = get_rebuild_session_details('last', 'all');
- $template->assign_vars(array('TPL_REBUILD_SEARCH_PROGRESS' => true));
+ $last_session_data = get_rebuild_session_details('last', 'all');
+ $template->assign_vars(array('TPL_REBUILD_SEARCH_PROGRESS' => true));
- $processing_messages = '';
- $processing_messages .= ($timer_expired) ? sprintf($lang['TIMER_EXPIRED'], TIMENOW - $start_time) : '';
- $processing_messages .= ($start == 0 && $clear_search) ? $lang['CLEARED_SEARCH_TABLES'] : '';
+ $processing_messages = '';
+ $processing_messages .= $timer_expired ? sprintf($lang['TIMER_EXPIRED'], TIMENOW - $start_time) : '';
+ $processing_messages .= ($start == 0 && $clear_search) ? $lang['CLEARED_SEARCH_TABLES'] : '';
- // check if we have reached the end of our post processing
- $session_posts_processed = get_processed_posts('session');
- $total_posts_processed = get_total_posts('before', $last_session_data['end_post_id']);
- $total_posts = get_total_posts();
+ // check if we have reached the end of our post processing
+ $session_posts_processed = get_processed_posts('session');
+ $total_posts_processed = get_total_posts('before', $last_session_data['end_post_id']);
+ $total_posts = get_total_posts();
- if ( $session_posts_processed < $session_posts_processing && $total_posts_processed < $total_posts )
- {
- $form_parameters = '&start='.($end_post_id+1);
- $form_parameters .= '&session_posts_processing='.$session_posts_processing;
- $form_parameters .= '&post_limit='.$post_limit;
- $form_parameters .= '&time_limit='.$time_limit;
- $form_parameters .= '&refresh_rate='.$refresh_rate;
+ if ($session_posts_processed < $session_posts_processing && $total_posts_processed < $total_posts) {
+ $form_parameters = '&start=' . ($end_post_id + 1);
+ $form_parameters .= '&session_posts_processing=' . $session_posts_processing;
+ $form_parameters .= '&post_limit=' . $post_limit;
+ $form_parameters .= '&time_limit=' . $time_limit;
+ $form_parameters .= '&refresh_rate=' . $refresh_rate;
- $form_action = 'admin_rebuild_search.php'.'?mode=refresh'.$form_parameters;
- $next_button = $lang['NEXT'];
- $progress_bar_img = $images['progress_bar'];
+ $form_action = 'admin_rebuild_search.php' . '?mode=refresh' . $form_parameters;
+ $next_button = $lang['NEXT'];
+ $progress_bar_img = $images['progress_bar'];
- $processing_messages .= sprintf($lang['PROCESSING_NEXT_POSTS'], $post_limit);
+ $processing_messages .= sprintf($lang['PROCESSING_NEXT_POSTS'], $post_limit);
meta_refresh($form_action, $refresh_rate);
- // create the meta tag for refresh
- $template->assign_vars(array(
- 'CANCEL_BUTTON' => true,
- ));
- }
- else // end of processing
- {
- $form_action = "admin_rebuild_search.php";
- $next_button = $lang['FINISHED'];
- $progress_bar_img = $images['progress_bar_full'];
+ // create the meta tag for refresh
+ $template->assign_vars(array(
+ 'CANCEL_BUTTON' => true,
+ ));
+ } else {
+ // end of processing
- $processing_messages .= ( $session_posts_processed < $session_posts_processing ) ? sprintf($lang['DELETED_POSTS'], $session_posts_processing - $session_posts_processed) : '';
- $processing_messages .= ( $total_posts_processed == $total_posts ) ? $lang['ALL_POSTS_PROCESSED'] : $lang['ALL_SESSION_POSTS_PROCESSED'];
+ $form_action = 'admin_rebuild_search.php';
+ $next_button = $lang['FINISHED'];
+ $progress_bar_img = $images['progress_bar_full'];
- // if we have processed all the db posts we need to update the rebuild_status
- DB()->query("UPDATE ". BB_SEARCH_REBUILD ." SET
- rebuild_session_status = ". REBUILD_SEARCH_COMPLETED ."
+ $processing_messages .= ($session_posts_processed < $session_posts_processing) ? sprintf($lang['DELETED_POSTS'], $session_posts_processing - $session_posts_processed) : '';
+ $processing_messages .= ($total_posts_processed == $total_posts) ? $lang['ALL_POSTS_PROCESSED'] : $lang['ALL_SESSION_POSTS_PROCESSED'];
+
+ // if we have processed all the db posts we need to update the rebuild_status
+ DB()->query('UPDATE ' . BB_SEARCH_REBUILD . ' SET
+ rebuild_session_status = ' . REBUILD_SEARCH_COMPLETED . "
WHERE rebuild_session_id = $last_session_id
AND end_post_id = $max_post_id
");
- // optimize all search tables when finished
- $table_ary = array(BB_POSTS_SEARCH);
+ // optimize all search tables when finished
+ $table_ary = array(BB_POSTS_SEARCH);
- foreach ($table_ary as $table)
- {
- DB()->query("ANALYZE TABLE $table");
- DB()->query("OPTIMIZE TABLE $table");
- }
+ foreach ($table_ary as $table) {
+ DB()->query("ANALYZE TABLE $table");
+ DB()->query("OPTIMIZE TABLE $table");
+ }
- $processing_messages .= ' ' . $lang['ALL_TABLES_OPTIMIZED'];
- }
+ $processing_messages .= ' ' . $lang['ALL_TABLES_OPTIMIZED'];
+ }
- // calculate the percent
- $session_percent = ($session_posts_processed / $session_posts_processing) * 100;
- $total_percent = ($total_posts_processed / $total_posts) * 100;
+ // calculate the percent
+ if ($session_posts_processing > 0) {
+ $session_percent = ($session_posts_processed / $session_posts_processing) * 100;
+ } else {
+ $session_percent = 100;
+ }
+ if ($total_posts > 0) {
+ $total_percent = ($total_posts_processed / $total_posts) * 100;
+ } else {
+ $total_percent = 100;
+ }
- // get the db sizes
- list($search_data_size, $search_index_size, $search_tables_size) = get_db_sizes();
+ // get the db sizes
+ [$search_data_size, $search_index_size, $search_tables_size] = get_db_sizes();
- // calculate the final (estimated) values
- $final_search_tables_size = '';
+ // calculate the final (estimated) values
+ $final_search_tables_size = '';
- if ($search_tables_size)
- {
- $start_search_tables_size = $last_session_data['search_size'];
- $final_search_tables_size = $start_search_tables_size + round(($search_tables_size - $start_search_tables_size) * (100 / $session_percent));
- }
+ if ($search_tables_size) {
+ $start_search_tables_size = $last_session_data['search_size'];
+ $final_search_tables_size = $start_search_tables_size + round(($search_tables_size - $start_search_tables_size) * (100 / $session_percent));
+ }
- // calculate various times
- $session_time = $last_session_data['session_time'];
- $session_average_cycle_time = round($session_time / $last_session_data['session_cycles']);
- $session_estimated_time = round($session_time * (100 / $session_percent)) - $session_time;
+ // calculate various times
+ $session_time = $last_session_data['session_time'];
+ if ($last_session_data['session_cycles'] > 0) {
+ $session_average_cycle_time = round($session_time / $last_session_data['session_cycles']);
+ } else {
+ $session_average_cycle_time = 0;
+ }
+ $session_estimated_time = round($session_time * (100 / $session_percent)) - $session_time;
- // create the percent boxes
- create_percent_box('session', create_percent_color($session_percent), $session_percent);
- create_percent_box('total', create_percent_color($total_percent), $total_percent);
+ // create the percent boxes
+ create_percent_box('session', create_percent_color($session_percent), $session_percent);
+ create_percent_box('total', create_percent_color($total_percent), $total_percent);
- $template->assign_vars(array(
- 'L_NEXT' => $next_button,
- 'L_TIME_LAST_POSTS_ADMIN' => sprintf($lang['TIME_LAST_POSTS'], $num_rows),
+ $template->assign_vars(array(
+ 'L_NEXT' => $next_button,
+ 'L_TIME_LAST_POSTS_ADMIN' => sprintf($lang['TIME_LAST_POSTS'], $num_rows),
- 'PROCESSING_POSTS' => sprintf($lang['PROCESSED_POST_IDS'], $start_post_id, $end_post_id),
- 'PROCESSING_MESSAGES' => $processing_messages,
- 'PROGRESS_BAR_IMG' => $progress_bar_img,
+ 'PROCESSING_POSTS' => sprintf($lang['PROCESSED_POST_IDS'], $start_post_id, $end_post_id),
+ 'PROCESSING_MESSAGES' => $processing_messages,
+ 'PROGRESS_BAR_IMG' => $progress_bar_img,
- 'SESSION_DETAILS' => sprintf($lang['PROCESS_DETAILS'], $session_posts_processed - $num_rows + 1, $session_posts_processed, $session_posts_processing),
- 'SESSION_PERCENT' => sprintf($lang['PERCENT_COMPLETED'], round($session_percent, 2)),
+ 'SESSION_DETAILS' => sprintf($lang['PROCESS_DETAILS'], $session_posts_processed - $num_rows + 1, $session_posts_processed, $session_posts_processing),
+ 'SESSION_PERCENT' => sprintf($lang['PERCENT_COMPLETED'], round($session_percent, 2)),
- 'TOTAL_DETAILS' => sprintf($lang['PROCESS_DETAILS'], $total_posts_processed - $num_rows + 1, $total_posts_processed, $total_posts),
- 'TOTAL_PERCENT' => sprintf($lang['PERCENT_COMPLETED'], round($total_percent, 2)),
+ 'TOTAL_DETAILS' => sprintf($lang['PROCESS_DETAILS'], $total_posts_processed - $num_rows + 1, $total_posts_processed, $total_posts),
+ 'TOTAL_PERCENT' => sprintf($lang['PERCENT_COMPLETED'], round($total_percent, 2)),
- 'LAST_CYCLE_TIME' => delta_time(TIMENOW),
- 'SESSION_TIME' => delta_time($last_session_data['start_time']),
- 'SESSION_AVERAGE_CYCLE_TIME'=> delta_time($session_average_cycle_time, 0),
- 'SESSION_ESTIMATED_TIME' => delta_time($session_estimated_time, 0),
+ 'LAST_CYCLE_TIME' => delta_time(TIMENOW),
+ 'SESSION_TIME' => delta_time(($last_session_data['start_time'] == 0) ? TIMENOW : $last_session_data['start_time']),
+ 'SESSION_AVERAGE_CYCLE_TIME' => delta_time((int)$session_average_cycle_time, 0),
+ 'SESSION_ESTIMATED_TIME' => delta_time((int)$session_estimated_time, 0),
- 'SEARCH_TABLES_SIZE' => humn_size($search_tables_size),
- 'FINAL_SEARCH_TABLES_SIZE' => humn_size($final_search_tables_size),
- 'SEARCH_DATA_SIZE' => humn_size($search_data_size),
- 'SEARCH_INDEX_SIZE' => humn_size($search_index_size),
+ 'SEARCH_TABLES_SIZE' => humn_size($search_tables_size),
+ 'FINAL_SEARCH_TABLES_SIZE' => humn_size($final_search_tables_size),
+ 'SEARCH_DATA_SIZE' => humn_size($search_data_size),
+ 'SEARCH_INDEX_SIZE' => humn_size($search_index_size),
- 'START_POST' => $last_session_data['start_post_id'],
- 'POST_LIMIT' => $num_rows,
- 'TIME_LIMIT' => $time_limit,
- 'REFRESH_RATE' => $refresh_rate,
+ 'START_POST' => $last_session_data['start_post_id'],
+ 'POST_LIMIT' => $num_rows,
+ 'TIME_LIMIT' => $time_limit,
+ 'REFRESH_RATE' => $refresh_rate,
- 'S_REBUILD_SEARCH_ACTION' => $form_action,
- ));
-}
-else // show the input page
-{
- // create the page
- // used only with the select input
- $post_limit_hidden = ( $def_post_limit > $total_posts ) ? $total_posts : $def_post_limit;
+ 'S_REBUILD_SEARCH_ACTION' => $form_action,
+ ));
+} else {// show the input page
+ // create the page
+ // used only with the select input
+ $post_limit_hidden = ($def_post_limit > $total_posts) ? $total_posts : $def_post_limit;
- $s_hidden_fields = ' ';
- $s_hidden_fields .= ' ';
+ $s_hidden_fields = ' ';
+ $s_hidden_fields .= ' ';
- $next_start_post_id = 0;
- $last_saved_processing = '';
- $clear_search_disabled = '';
+ $next_start_post_id = 0;
+ $last_saved_processing = '';
+ $clear_search_disabled = '';
- if ($last_session_data['rebuild_session_id'])
- {
- $last_saved_post_id = $last_session_data['end_post_id'];
- $next_start_post_id = $last_saved_post_id + 1;
- $last_saved_date = bb_date($last_session_data['end_time']);
+ if ($last_session_data['rebuild_session_id']) {
+ $last_saved_post_id = $last_session_data['end_post_id'];
+ $next_start_post_id = $last_saved_post_id + 1;
+ $last_saved_date = bb_date($last_session_data['end_time']);
- // check our last status
- if ( $last_session_data['rebuild_session_status'] == REBUILD_SEARCH_PROCESSED )
- {
- $last_saved_processing = sprintf($lang['INFO_PROCESSING_STOPPED'], $last_saved_post_id, $total_posts_processed, $last_saved_date);
- $clear_search_disabled = 'disabled="disabled"';
+ // check our last status
+ if ($last_session_data['rebuild_session_status'] == REBUILD_SEARCH_PROCESSED) {
+ $last_saved_processing = sprintf($lang['INFO_PROCESSING_STOPPED'], $last_saved_post_id, $total_posts_processed, $last_saved_date);
+ $clear_search_disabled = 'disabled';
- $template->assign_block_vars("start_select_input", array());
- }
- elseif ( $last_session_data['rebuild_session_status'] == REBUILD_SEARCH_ABORTED )
- {
- $last_saved_processing = sprintf($lang['INFO_PROCESSING_ABORTED'], $last_saved_post_id, $total_posts_processed, $last_saved_date);
- // check if the interrupted cycle has finished
- if ( TIMENOW - $last_session_data['end_time'] < $last_session_data['last_cycle_time'] )
- {
- $last_saved_processing .= ' '.$lang['INFO_PROCESSING_ABORTED_SOON'];
- }
- $clear_search_disabled = 'disabled="disabled"';
+ $template->assign_block_vars('start_select_input', []);
+ } elseif ($last_session_data['rebuild_session_status'] == REBUILD_SEARCH_ABORTED) {
+ $last_saved_processing = sprintf($lang['INFO_PROCESSING_ABORTED'], $last_saved_post_id, $total_posts_processed, $last_saved_date);
+ // check if the interrupted cycle has finished
+ if (TIMENOW - $last_session_data['end_time'] < $last_session_data['last_cycle_time']) {
+ $last_saved_processing .= ' ' . $lang['INFO_PROCESSING_ABORTED_SOON'];
+ }
+ $clear_search_disabled = 'disabled';
- $template->assign_block_vars("start_select_input", array());
- }
- else // when finished
- {
- if ( $last_session_data['end_post_id'] < $max_post_id )
- {
- $last_saved_processing = sprintf($lang['INFO_PROCESSING_FINISHED_NEW'], $last_saved_post_id, $total_posts_processed, $last_saved_date, ($total_posts - $total_posts_processed));
- $clear_search_disabled = 'disabled="disabled"';
+ $template->assign_block_vars('start_select_input', []);
+ } else {
+ // when finished
- $template->assign_block_vars("start_select_input", array());
- }
- else
- {
- $last_saved_processing = sprintf($lang['INFO_PROCESSING_FINISHED'], $total_posts, $last_saved_date);
+ if ($last_session_data['end_post_id'] < $max_post_id) {
+ $last_saved_processing = sprintf($lang['INFO_PROCESSING_FINISHED_NEW'], $last_saved_post_id, $total_posts_processed, $last_saved_date, $total_posts - $total_posts_processed);
+ $clear_search_disabled = 'disabled';
- $template->assign_block_vars("start_text_input", array());
- }
- }
+ $template->assign_block_vars('start_select_input', []);
+ } else {
+ $last_saved_processing = sprintf($lang['INFO_PROCESSING_FINISHED'], $total_posts, $last_saved_date);
- $template->assign_block_vars("last_saved_info", array());
- }
- else
- {
- $template->assign_block_vars("start_text_input", array());
- }
+ $template->assign_block_vars('start_text_input', []);
+ }
+ }
- // create the output of page
- $template->assign_vars(array(
- 'TPL_REBUILD_SEARCH_MAIN' => true,
+ $template->assign_block_vars('last_saved_info', []);
+ } else {
+ $template->assign_block_vars('start_text_input', []);
+ }
- 'L_TIME_LIMIT_EXPLAIN' => $time_limit_explain,
+ // create the output of page
+ $template->assign_vars(array(
+ 'TPL_REBUILD_SEARCH_MAIN' => true,
- 'NEXT_START_POST_ID' => $next_start_post_id,
- 'CLEAR_SEARCH_DISABLED' => $clear_search_disabled,
- 'SESSION_POSTS_PROCESSING' => $session_posts_processing,
- 'POST_LIMIT' => $post_limit,
- 'REFRESH_RATE' => $refresh_rate,
- 'TIME_LIMIT' => $time_limit,
+ 'L_TIME_LIMIT_EXPLAIN' => $time_limit_explain,
- 'LAST_SAVED_PROCESSING' => $last_saved_processing,
+ 'NEXT_START_POST_ID' => $next_start_post_id,
+ 'CLEAR_SEARCH_DISABLED' => $clear_search_disabled,
+ 'SESSION_POSTS_PROCESSING' => $session_posts_processing,
+ 'POST_LIMIT' => $post_limit,
+ 'REFRESH_RATE' => $refresh_rate,
+ 'TIME_LIMIT' => $time_limit,
- 'SESSION_ID' => $userdata['session_id'],
+ 'LAST_SAVED_PROCESSING' => $last_saved_processing,
- 'S_HIDDEN_FIELDS' => $s_hidden_fields,
- 'S_REBUILD_SEARCH_ACTION' => "admin_rebuild_search.php?mode=submit",
- ));
+ 'SESSION_ID' => $userdata['session_id'],
+
+ 'S_HIDDEN_FIELDS' => $s_hidden_fields,
+ 'S_REBUILD_SEARCH_ACTION' => 'admin_rebuild_search.php?mode=submit',
+ ));
}
print_page('admin_rebuild_search.tpl', 'admin');
@@ -449,124 +424,117 @@ print_page('admin_rebuild_search.tpl', 'admin');
//
// Functions
//
-function get_db_sizes ()
+function get_db_sizes()
{
- $search_data_size = $search_index_size = 0;
- $search_table_like = DB()->escape(BB_POSTS_SEARCH);
+ $search_data_size = $search_index_size = 0;
+ $search_table_like = DB()->escape(BB_POSTS_SEARCH);
- $sql = "SHOW TABLE STATUS FROM `". DB()->selected_db ."` LIKE '$search_table_like'";
+ $sql = 'SHOW TABLE STATUS FROM `' . DB()->selected_db . "` LIKE '$search_table_like'";
- foreach (DB()->fetch_rowset($sql) as $row)
- {
- $search_data_size += $row['Data_length'];
- $search_index_size += $row['Index_length'];
- }
+ foreach (DB()->fetch_rowset($sql) as $row) {
+ $search_data_size += $row['Data_length'];
+ $search_index_size += $row['Index_length'];
+ }
- return array($search_data_size, $search_index_size, $search_data_size+$search_index_size);
+ return array($search_data_size, $search_index_size, $search_data_size + $search_index_size);
}
// get the latest post_id in the forum
-function get_latest_post_id ()
+function get_latest_post_id()
{
- $row = DB()->fetch_row("SELECT MAX(post_id) as post_id FROM ". BB_POSTS_TEXT);
+ $row = DB()->fetch_row('SELECT MAX(post_id) as post_id FROM ' . BB_POSTS_TEXT);
- return (int) $row['post_id'];
+ return (int)$row['post_id'];
}
-function get_empty_last_session_data ()
+function get_empty_last_session_data()
{
- return array(
- 'rebuild_session_id' => 0,
- 'start_post_id' => 0,
- 'end_post_id' => 0,
- 'start_time' => 0,
- 'end_time' => 0,
- 'last_cycle_time' => 0,
- 'session_time' => 0,
- 'session_posts' => 0,
- 'session_cycles' => 0,
- 'search_size' => 0,
- 'rebuild_session_status' => REBUILD_SEARCH_COMPLETED,
- );
+ return array(
+ 'rebuild_session_id' => 0,
+ 'start_post_id' => 0,
+ 'end_post_id' => 0,
+ 'start_time' => 0,
+ 'end_time' => 0,
+ 'last_cycle_time' => 0,
+ 'session_time' => 0,
+ 'session_posts' => 0,
+ 'session_cycles' => 0,
+ 'search_size' => 0,
+ 'rebuild_session_status' => REBUILD_SEARCH_COMPLETED,
+ );
}
// get some or all of the rebuild details of a specific session or of the last session
// $id is the id or the 'last' id
// $details is one of the fields or 'all' of them
-function get_rebuild_session_details ($id, $details = 'all')
+function get_rebuild_session_details($id, $details = 'all')
{
- $session_details = get_empty_last_session_data();
+ $session_details = get_empty_last_session_data();
- if ($id != 'last')
- {
- $sql = "SELECT * FROM ". BB_SEARCH_REBUILD ." WHERE rebuild_session_id = $id";
- }
- else
- {
- $sql = "SELECT * FROM ". BB_SEARCH_REBUILD ." ORDER BY rebuild_session_id DESC LIMIT 1";
- }
+ if ($id != 'last') {
+ $sql = 'SELECT * FROM ' . BB_SEARCH_REBUILD . " WHERE rebuild_session_id = $id";
+ } else {
+ $sql = 'SELECT * FROM ' . BB_SEARCH_REBUILD . ' ORDER BY rebuild_session_id DESC LIMIT 1';
+ }
- if ($row = DB()->fetch_row($sql))
- {
- $session_details = ($details == 'all') ? $row : $row[$details];
- }
+ if ($row = DB()->fetch_row($sql)) {
+ $session_details = ($details == 'all') ? $row : $row[$details];
+ }
- return $session_details;
+ return $session_details;
}
// get the number of processed posts in the last session or in all sessions
// 'total' to get the sum of posts of all sessions
// 'session' to get the posts of the last session
-function get_processed_posts ($mode = 'session')
+function get_processed_posts($mode = 'session')
{
- global $last_session_data;
+ global $last_session_data;
+ $row = [];
- if ($mode == 'total')
- {
- $sql = "SELECT SUM(session_posts) as posts FROM ". BB_SEARCH_REBUILD;
- $row = DB()->fetch_row($sql);
- }
- else
- {
- $row['posts'] = $last_session_data['session_posts'];
- }
+ if ($mode == 'total') {
+ $sql = 'SELECT SUM(session_posts) as posts FROM ' . BB_SEARCH_REBUILD;
+ $row = DB()->fetch_row($sql);
+ } else {
+ $row['posts'] = $last_session_data['session_posts'];
+ }
- return (int) $row['posts'];
+ return (int)$row['posts'];
}
// how many posts are in the db before or after a specific post_id
// after/before require and the post_id
-function get_total_posts ($mode = 'after', $post_id = 0)
+function get_total_posts($mode = 'after', $post_id = 0)
{
- if ($post_id)
- {
- $sql = "SELECT COUNT(post_id) as total_posts FROM " . BB_POSTS_TEXT . "
- WHERE post_id " . (($mode == 'after') ? '>= ' : '<= ' ) . (int) $post_id;
- }
- else
- {
- $sql = "SELECT COUNT(*) as total_posts FROM " . BB_POSTS_TEXT;
- }
+ if ($post_id) {
+ $sql = 'SELECT COUNT(post_id) as total_posts FROM ' . BB_POSTS_TEXT . '
+ WHERE post_id ' . (($mode == 'after') ? '>= ' : '<= ') . (int)$post_id;
+ } else {
+ $sql = 'SELECT COUNT(*) as total_posts FROM ' . BB_POSTS_TEXT;
+ }
- $row = DB()->fetch_row($sql);
+ $row = DB()->fetch_row($sql);
+ $totalPosts = (int)$row['total_posts'];
- return (int) $row['total_posts'];
+ if ($totalPosts < 0) {
+ return 0;
+ }
+
+ return $totalPosts;
}
-function clear_search_tables ($mode = '')
+function clear_search_tables($mode = '')
{
- DB()->query("DELETE FROM ". BB_SEARCH_REBUILD);
+ DB()->query('DELETE FROM ' . BB_SEARCH_REBUILD);
- if ($mode)
- {
- $table_ary = array(BB_POSTS_SEARCH);
+ if ($mode) {
+ $table_ary = array(BB_POSTS_SEARCH);
- foreach ($table_ary as $table)
- {
- $sql = (($mode == 1) ? "DELETE FROM " : "TRUNCATE TABLE ") . $table;
- DB()->query($sql);
- }
- }
+ foreach ($table_ary as $table) {
+ $sql = (($mode == 1) ? 'DELETE FROM ' : 'TRUNCATE TABLE ') . $table;
+ DB()->query($sql);
+ }
+ }
}
// Create the percent color
@@ -576,49 +544,45 @@ function clear_search_tables ($mode = '')
// We limit the result to 200, in order to avoid white (255).
function create_percent_color($percent)
{
- $percent_ary = array(
- 'r' => array(86, 100),
- 'g' => array(0, 50),
- 'b' => array(51, 85),
- );
+ $percent_color = null;
+ $percent_ary = array(
+ 'r' => array(86, 100),
+ 'g' => array(0, 50),
+ 'b' => array(51, 85),
+ );
- foreach ($percent_ary as $key => $value)
- {
- if ( $percent <= $value[1] )
- {
- $percent_color = create_color($key, round(200-($percent-$value[0])*(200/($value[1]-$value[0]))));
- break;
- }
- }
+ foreach ($percent_ary as $key => $value) {
+ if ($percent <= $value[1]) {
+ $percent_color = create_color($key, round(200 - ($percent - $value[0]) * (200 / ($value[1] - $value[0]))));
+ break;
+ }
+ }
- return $percent_color;
+ return $percent_color;
}
// create the hex representation of color
function create_color($mode, $code)
{
- return (($mode == 'r') ? 'FF': sprintf("%02X", $code)) . (($mode == 'g') ? 'FF': sprintf("%02X", $code)) . (($mode == 'b') ? 'FF': sprintf("%02X", $code));
+ return (($mode == 'r') ? 'FF' : sprintf('%02X', $code)) . (($mode == 'g') ? 'FF' : sprintf('%02X', $code)) . (($mode == 'b') ? 'FF' : sprintf('%02X', $code));
}
// create the percent bar & box
function create_percent_box($box, $percent_color, $percent_width)
{
- global $template;
+ global $template;
- if ($box == 'session')
- {
- $template->assign_vars(array(
- 'SESSION_PERCENT_BOX' => true,
- 'SESSION_PERCENT_COLOR' => $percent_color,
- 'SESSION_PERCENT_WIDTH' => round($percent_width),
- ));
- }
- else
- {
- $template->assign_vars(array(
- 'TOTAL_PERCENT_BOX' => true,
- 'TOTAL_PERCENT_COLOR' => $percent_color,
- 'TOTAL_PERCENT_WIDTH' => round($percent_width),
- ));
- }
-}
\ No newline at end of file
+ if ($box == 'session') {
+ $template->assign_vars(array(
+ 'SESSION_PERCENT_BOX' => true,
+ 'SESSION_PERCENT_COLOR' => $percent_color,
+ 'SESSION_PERCENT_WIDTH' => round($percent_width),
+ ));
+ } else {
+ $template->assign_vars(array(
+ 'TOTAL_PERCENT_BOX' => true,
+ 'TOTAL_PERCENT_COLOR' => $percent_color,
+ 'TOTAL_PERCENT_WIDTH' => round($percent_width),
+ ));
+ }
+}
diff --git a/admin/admin_robots.php b/admin/admin_robots.php
new file mode 100644
index 000000000..44d73d52b
--- /dev/null
+++ b/admin/admin_robots.php
@@ -0,0 +1,45 @@
+ ' . sprintf($lang['CLICK_RETURN_ROBOTS_TXT_CONFIG'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '));
+}
+
+$current_content = '';
+if (is_file($robots_file)) {
+ $current_content = file_get_contents($robots_file);
+}
+
+$template->assign_vars([
+ 'S_ACTION' => 'admin_robots.php',
+ 'ROBOTS_TXT' => htmlCHR($current_content),
+]);
+
+print_page('admin_robots.tpl', 'admin');
diff --git a/admin/admin_sitemap.php b/admin/admin_sitemap.php
index 3976758af..66e2f800b 100644
--- a/admin/admin_sitemap.php
+++ b/admin/admin_sitemap.php
@@ -1,52 +1,50 @@
sql_query($sql))
-{
- bb_die('Could not query config information in admin_sitemap');
-}
-else
-{
- $new_params = array();
-
- while ($row = DB()->sql_fetchrow($result))
- {
- $config_name = $row['config_name'];
- $config_value = $row['config_value'];
- $default_config[$config_name] = $config_value;
- $new[$config_name] = isset($_POST[$config_name]) ? $_POST[$config_name] : $default_config[$config_name];
-
- if (isset($_POST['submit']) && $row['config_value'] != $new[$config_name])
- {
- $new_params[$config_name] = $new[$config_name];
- }
- }
-
- if (isset($_POST['submit']))
- {
- if (!empty($new_params))
- {
- bb_update_config($new_params);
- }
- }
+if (!empty($setmodules)) {
+ $module['MODS']['SITEMAP'] = basename(__FILE__);
+ return;
}
-$s_mess = $lang['SITEMAP_CREATED'].': '.bb_date($new['sitemap_time'], $bb_cfg['post_date_format']).' '.$lang['SITEMAP_AVAILABLE'].': '.make_url('sitemap.xml').' ';
-$message = (@file_exists(BB_ROOT. "/internal_data/sitemap/sitemap.xml")) ? $s_mess : $lang['SITEMAP_NOT_CREATED'];
+require __DIR__ . '/pagestart.php';
-$template->assign_vars(array(
- 'STATIC_SITEMAP' => $new['static_sitemap'],
- 'MESSAGE' => $message,
-));
+$sql = "SELECT * FROM " . BB_CONFIG . " WHERE config_name IN('sitemap_time', 'static_sitemap')";
-print_page('admin_sitemap.tpl', 'admin');
\ No newline at end of file
+if (!$result = DB()->sql_query($sql)) {
+ bb_die('Could not query config information in admin_sitemap');
+} else {
+ $new_params = [];
+
+ while ($row = DB()->sql_fetchrow($result)) {
+ $config_name = $row['config_name'];
+ $config_value = $row['config_value'];
+ $default_config[$config_name] = $config_value;
+ $new[$config_name] = $_POST[$config_name] ?? $default_config[$config_name];
+
+ if (isset($_POST['submit']) && $row['config_value'] != $new[$config_name]) {
+ $new_params[$config_name] = $new[$config_name];
+ }
+ }
+
+ if (isset($_POST['submit'])) {
+ if (!empty($new_params)) {
+ bb_update_config($new_params);
+ }
+ }
+}
+
+$s_mess = $lang['SITEMAP_CREATED'] . ': ' . bb_date($new['sitemap_time'], config()->get('post_date_format')) . ' ' . $lang['SITEMAP_AVAILABLE'] . ': ' . make_url('sitemap/sitemap.xml') . ' ';
+$message = is_file(SITEMAP_DIR . '/sitemap.xml') ? $s_mess : $lang['SITEMAP_NOT_CREATED'];
+
+$template->assign_vars([
+ 'STATIC_SITEMAP' => $new['static_sitemap'],
+ 'MESSAGE' => $message
+]);
+
+print_page('admin_sitemap.tpl', 'admin');
diff --git a/admin/admin_smilies.php b/admin/admin_smilies.php
index 4d60e7090..9e84c3ea0 100644
--- a/admin/admin_smilies.php
+++ b/admin/admin_smilies.php
@@ -1,370 +1,334 @@
get('smilies_path');
+$delimeter = '=+:';
+$s_hidden_fields = '';
+$smiley_paks = $smiley_images = [];
+
+// Read a listing of uploaded smiles
+$smilesDirectory = new DirectoryIterator($pathToSmilesDir);
+
+foreach ($smilesDirectory as $files) {
+ if ($files->isFile()) {
+ $extension = strtolower(pathinfo($files->getFilename(), PATHINFO_EXTENSION));
+ if (in_array($extension, ['png', 'gif'], true) && getimagesize($pathToSmilesDir . '/' . $files->getFilename())) {
+ $smiley_images[] = $files->getFilename();
+ } else if ($extension === 'pak') {
+ $smiley_paks[] = $files->getFilename();
+ }
+ }
+}
// Select main mode
-if (isset($_GET['import_pack']) || isset($_POST['import_pack']))
-{
- $smile_pak = (string) request_var('smile_pak', '');
- $clear_current = (int) request_var('clear_current', '');
- $replace_existing = (int) request_var('replace', '');
+if (isset($_GET['import_pack']) || isset($_POST['import_pack'])) {
+ $smile_pak = (string)request_var('smile_pak', '');
+ $clear_current = (int)request_var('clear_current', '');
+ $replace_existing = (int)request_var('replace', '');
- if (!empty($smile_pak))
- {
- // The user has already selected a smile_pak file.. Import it
- if (!empty($clear_current))
- {
- $sql = "DELETE FROM " . BB_SMILIES;
- if (!$result = DB()->sql_query($sql))
- {
- bb_die('Could not delete current smilies');
- }
- $datastore->update('smile_replacements');
- }
- else
- {
- $sql = "SELECT code FROM ". BB_SMILIES;
- if (!$result = DB()->sql_query($sql))
- {
- bb_die('Could not get current smilies');
- }
+ if (!empty($smile_pak)) {
+ // The user has already selected a smile_pak file.. Import it
+ if (!empty($clear_current)) {
+ $sql = 'DELETE FROM ' . BB_SMILIES;
+ if (!$result = DB()->sql_query($sql)) {
+ bb_die('Could not delete current smilies');
+ }
+ $datastore->update('smile_replacements');
+ } else {
+ $sql = 'SELECT code FROM ' . BB_SMILIES;
+ if (!$result = DB()->sql_query($sql)) {
+ bb_die('Could not get current smilies');
+ }
- $cur_smilies = DB()->sql_fetchrowset($result);
+ $cur_smilies = DB()->sql_fetchrowset($result);
- for ($i = 0; $i < count($cur_smilies); $i++)
- {
- $k = $cur_smilies[$i]['code'];
- $smiles[$k] = 1;
- }
- }
+ for ($i = 0, $iMax = count($cur_smilies); $i < $iMax; $i++) {
+ $k = $cur_smilies[$i]['code'];
+ $smiles[$k] = 1;
+ }
+ }
- $fcontents = @file(BB_ROOT . $bb_cfg['smilies_path'] . '/'. $smile_pak);
+ $fcontents = file($pathToSmilesDir . '/' . $smile_pak);
- if (empty($fcontents))
- {
- bb_die('Could not read smiley pak file');
- }
+ if (empty($fcontents)) {
+ bb_die('Could not read smiley pak file');
+ }
- for ($i = 0; $i < count($fcontents); $i++)
- {
- $smile_data = explode($delimeter, trim(addslashes($fcontents[$i])));
+ foreach ($fcontents as $i => $iValue) {
+ $smile_data = explode($delimeter, trim(addslashes($fcontents[$i])));
- for ($j = 2; $j < count($smile_data); $j++)
- {
- // Replace > and < with the proper html_entities for matching
- $smile_data[$j] = str_replace('<', '<', $smile_data[$j]);
- $smile_data[$j] = str_replace('>', '>', $smile_data[$j]);
- $k = $smile_data[$j];
+ for ($j = 2, $jMax = count($smile_data); $j < $jMax; $j++) {
+ // Replace > and < with the proper html_entities for matching
+ $smile_data[$j] = str_replace('<', '<', $smile_data[$j]);
+ $smile_data[$j] = str_replace('>', '>', $smile_data[$j]);
+ $k = $smile_data[$j];
- if (isset($smiles[$k]))
- {
- if( !empty($replace_existing) )
- {
- $sql = "UPDATE " . BB_SMILIES . "
+ if (isset($smiles[$k])) {
+ if (!empty($replace_existing)) {
+ $sql = 'UPDATE ' . BB_SMILIES . "
SET smile_url = '" . DB()->escape($smile_data[0]) . "', emoticon = '" . DB()->escape($smile_data[1]) . "'
WHERE code = '" . DB()->escape($smile_data[$j]) . "'";
- }
- else
- {
- $sql = '';
- }
- }
- else
- {
- $sql = "INSERT INTO " . BB_SMILIES . " (code, smile_url, emoticon)
+ } else {
+ $sql = '';
+ }
+ } else {
+ $sql = 'INSERT INTO ' . BB_SMILIES . " (code, smile_url, emoticon)
VALUES('" . DB()->escape($smile_data[$j]) . "', '" . DB()->escape($smile_data[0]) . "', '" . DB()->escape($smile_data[1]) . "')";
- }
+ }
- if ($sql != '')
- {
- $result = DB()->sql_query($sql);
- if (!$result)
- {
- bb_die('Could not update smilies #1');
- }
- $datastore->update('smile_replacements');
- }
- }
- }
+ if ($sql != '') {
+ $result = DB()->sql_query($sql);
+ if (!$result) {
+ bb_die('Could not update smilies #1');
+ }
+ $datastore->update('smile_replacements');
+ }
+ }
+ }
- bb_die($lang['SMILEY_IMPORT_SUCCESS'] . ' ' . sprintf($lang['CLICK_RETURN_SMILEADMIN'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '));
- }
- else
- {
- // Display the script to get the smile_pak cfg file
- $smile_paks_select = '' . $lang['SELECT_PAK'] . ' ';
- while (list($key, $value) = @each($smiley_paks))
- {
- if (!empty($value))
- {
- $smile_paks_select .= '' . $value . ' ';
- }
- }
- $smile_paks_select .= ' ';
+ bb_die($lang['SMILEY_IMPORT_SUCCESS'] . ' ' . sprintf($lang['CLICK_RETURN_SMILEADMIN'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '));
+ } else {
+ // Display the script to get the smile_pak cfg file
+ $smile_paks_select = '' . $lang['SELECT_PAK'] . ' ';
+ foreach ($smiley_paks as $key => $value) {
+ if (!empty($value)) {
+ $smile_paks_select .= '' . $value . ' ';
+ }
+ }
+ $smile_paks_select .= ' ';
- $hidden_vars = ' ';
+ $hidden_vars = ' ';
- $template->assign_vars(array(
- 'TPL_SMILE_IMPORT' => true,
+ $template->assign_vars([
+ 'TPL_SMILE_IMPORT' => true,
- 'S_SMILEY_ACTION' => 'admin_smilies.php',
- 'S_SMILE_SELECT' => $smile_paks_select,
- 'S_HIDDEN_FIELDS' => $hidden_vars,
- ));
- }
-}
-else if (isset($_POST['export_pack']) || isset($_GET['export_pack']))
-{
- $export_pack = (string) request_var('export_pack', '');
+ 'S_SMILEY_ACTION' => 'admin_smilies.php',
+ 'S_SMILE_SELECT' => $smile_paks_select,
+ 'S_HIDDEN_FIELDS' => $hidden_vars
+ ]);
+ }
+} elseif (isset($_POST['export_pack']) || isset($_GET['export_pack'])) {
+ $export_pack = (string)request_var('export_pack', '');
- if ($export_pack == 'send')
- {
- $sql = "SELECT * FROM " . BB_SMILIES;
- if (!$result = DB()->sql_query($sql))
- {
- bb_die('Could not get smiley list');
- }
+ if ($export_pack == 'send') {
+ $sql = 'SELECT * FROM ' . BB_SMILIES;
+ if (!$result = DB()->sql_query($sql)) {
+ bb_die('Could not get smiley list');
+ }
- $resultset = DB()->sql_fetchrowset($result);
+ $resultset = DB()->sql_fetchrowset($result);
- $smile_pak = '';
- for ($i = 0; $i < count($resultset); $i++)
- {
- $smile_pak .= $resultset[$i]['smile_url'] . $delimeter;
- $smile_pak .= $resultset[$i]['emoticon'] . $delimeter;
- $smile_pak .= $resultset[$i]['code'] . "\n";
- }
+ $smile_pak = '';
+ for ($i = 0, $iMax = count($resultset); $i < $iMax; $i++) {
+ $smile_pak .= $resultset[$i]['smile_url'] . $delimeter;
+ $smile_pak .= $resultset[$i]['emoticon'] . $delimeter;
+ $smile_pak .= $resultset[$i]['code'] . "\n";
+ }
- header("Content-Type: text/x-delimtext; name=\"smiles.pak\"");
- header("Content-disposition: attachment; filename=smiles.pak");
+ header('Content-Type: text/x-delimtext; name="smiles.pak"');
+ header('Content-disposition: attachment; filename=smiles.pak');
- echo $smile_pak;
+ echo $smile_pak;
- exit;
- }
+ exit;
+ }
- bb_die(sprintf($lang['EXPORT_SMILES'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_SMILEADMIN'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '));
-}
-else if (isset($_POST['add']) || isset($_GET['add']))
-{
- $filename_list = '';
- for ($i = 0; $i < count($smiley_images); $i++)
- {
- $filename_list .= ''. $smiley_images[$i] .' ';
- }
+ bb_die(sprintf($lang['EXPORT_SMILES'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_SMILEADMIN'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '));
+} elseif (isset($_POST['add']) || isset($_GET['add'])) {
+ $filename_list = '';
+ for ($i = 0, $iMax = count($smiley_images); $i < $iMax; $i++) {
+ $filename_list .= '' . $smiley_images[$i] . ' ';
+ }
- $s_hidden_fields = ' ';
+ $s_hidden_fields = ' ';
- $template->assign_vars(array(
- 'TPL_SMILE_EDIT' => true,
- 'SMILEY_IMG' => BB_ROOT . $bb_cfg['smilies_path'] . '/' . $smiley_images[0],
- 'S_SMILEY_ACTION' => "admin_smilies.php",
- 'S_HIDDEN_FIELDS' => $s_hidden_fields,
- 'S_FILENAME_OPTIONS' => $filename_list,
- 'S_SMILEY_BASEDIR' => BB_ROOT . $bb_cfg['smilies_path']
- ));
-}
-else if ( $mode != '' )
-{
- switch( $mode )
- {
- case 'delete':
- $smiley_id = ( !empty($_POST['id']) ) ? $_POST['id'] : $_GET['id'];
- $smiley_id = intval($smiley_id);
+ $template->assign_vars([
+ 'TPL_SMILE_EDIT' => true,
+ 'SMILEY_IMG' => $pathToSmilesDir . '/' . $smiley_images[0],
+ 'S_SMILEY_ACTION' => 'admin_smilies.php',
+ 'S_HIDDEN_FIELDS' => $s_hidden_fields,
+ 'S_FILENAME_OPTIONS' => $filename_list,
+ 'S_SMILEY_BASEDIR' => $pathToSmilesDir
+ ]);
+} elseif ($mode != '') {
+ switch ($mode) {
+ case 'delete':
+ $confirmed = isset($_POST['confirm']);
+ $smiley_id = (!empty($_POST['id'])) ? $_POST['id'] : $_GET['id'];
+ $smiley_id = (int)$smiley_id;
- $sql = "DELETE FROM " . BB_SMILIES . " WHERE smilies_id = " . $smiley_id;
- $result = DB()->sql_query($sql);
- if (!$result)
- {
- bb_die('Could not delete smiley');
- }
- $datastore->update('smile_replacements');
+ if ($confirmed) {
+ $sql = 'DELETE FROM ' . BB_SMILIES . ' WHERE smilies_id = ' . $smiley_id;
+ $result = DB()->sql_query($sql);
+ if (!$result) {
+ bb_die('Could not delete smiley');
+ }
- bb_die($lang['SMILEY_DEL_SUCCESS'] . ' ' . sprintf($lang['CLICK_RETURN_SMILEADMIN'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '));
- break;
+ $datastore->update('smile_replacements');
+ bb_die($lang['SMILEY_DEL_SUCCESS'] . ' ' . sprintf($lang['CLICK_RETURN_SMILEADMIN'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '));
+ } else {
+ $hidden_fields = ' ';
+ $hidden_fields .= ' ';
- case 'edit':
- $smiley_id = ( !empty($_POST['id']) ) ? $_POST['id'] : $_GET['id'];
- $smiley_id = intval($smiley_id);
+ print_confirmation([
+ 'FORM_ACTION' => 'admin_smilies.php',
+ 'HIDDEN_FIELDS' => $hidden_fields,
+ ]);
+ }
+ break;
- $sql = "SELECT * FROM " . BB_SMILIES . " WHERE smilies_id = " . $smiley_id;
- $result = DB()->sql_query($sql);
- if (!$result)
- {
- bb_die('Could not obtain emoticon information');
- }
- $smile_data = DB()->sql_fetchrow($result);
+ case 'edit':
+ $smiley_id = (!empty($_POST['id'])) ? $_POST['id'] : $_GET['id'];
+ $smiley_id = (int)$smiley_id;
- $filename_list = '';
- for ($i = 0; $i < count($smiley_images); $i++)
- {
- if ($smiley_images[$i] == $smile_data['smile_url'])
- {
- $smiley_selected = 'selected="selected"';
- $smiley_edit_img = $smiley_images[$i];
- }
- else
- {
- $smiley_selected = '';
- }
- $filename_list .= '' . $smiley_images[$i] . ' ';
- }
+ $sql = 'SELECT * FROM ' . BB_SMILIES . ' WHERE smilies_id = ' . $smiley_id;
+ $result = DB()->sql_query($sql);
+ if (!$result) {
+ bb_die('Could not obtain emoticon information');
+ }
+ $smile_data = DB()->sql_fetchrow($result);
- $s_hidden_fields = ' ';
+ $filename_list = $smiley_edit_img = '';
+ for ($i = 0, $iMax = count($smiley_images); $i < $iMax; $i++) {
+ if ($smiley_images[$i] == $smile_data['smile_url']) {
+ $smiley_selected = 'selected';
+ $smiley_edit_img = $smiley_images[$i];
+ } else {
+ $smiley_selected = '';
+ }
+ $filename_list .= '' . $smiley_images[$i] . ' ';
+ }
- $template->assign_vars(array(
- 'TPL_SMILE_EDIT' => true,
- 'SMILEY_CODE' => $smile_data['code'],
- 'SMILEY_EMOTICON' => $smile_data['emoticon'],
- 'SMILEY_IMG' => BB_ROOT . $bb_cfg['smilies_path'] . '/' . $smiley_edit_img,
- 'S_SMILEY_ACTION' => "admin_smilies.php",
- 'S_HIDDEN_FIELDS' => $s_hidden_fields,
- 'S_FILENAME_OPTIONS' => $filename_list,
- 'S_SMILEY_BASEDIR' => BB_ROOT . $bb_cfg['smilies_path'],
- ));
+ $s_hidden_fields = ' ';
- break;
+ $template->assign_vars([
+ 'TPL_SMILE_EDIT' => true,
+ 'SMILEY_CODE' => $smile_data['code'],
+ 'SMILEY_EMOTICON' => $smile_data['emoticon'],
+ 'SMILEY_IMG' => $pathToSmilesDir . '/' . $smiley_edit_img,
+ 'S_SMILEY_ACTION' => 'admin_smilies.php',
+ 'S_HIDDEN_FIELDS' => $s_hidden_fields,
+ 'S_FILENAME_OPTIONS' => $filename_list,
+ 'S_SMILEY_BASEDIR' => $pathToSmilesDir
+ ]);
- case 'save':
- $smile_code = ( isset($_POST['smile_code']) ) ? trim($_POST['smile_code']) : trim($_GET['smile_code']);
- $smile_url = ( isset($_POST['smile_url']) ) ? trim($_POST['smile_url']) : trim($_GET['smile_url']);
- $smile_url = bb_ltrim(basename($smile_url), "'");
- $smile_emotion = ( isset($_POST['smile_emotion']) ) ? trim($_POST['smile_emotion']) : trim($_GET['smile_emotion']);
- $smile_id = ( isset($_POST['smile_id']) ) ? intval($_POST['smile_id']) : intval($_GET['smile_id']);
+ break;
- // If no code was entered complain
- if ($smile_code == '' || $smile_url == '')
- {
- bb_die($lang['FIELDS_EMPTY']);
- }
+ case 'save':
+ $smile_code = isset($_POST['smile_code']) ? trim($_POST['smile_code']) : trim($_GET['smile_code']);
+ $smile_url = isset($_POST['smile_url']) ? trim($_POST['smile_url']) : trim($_GET['smile_url']);
+ $smile_url = ltrim(basename($smile_url), "'");
+ $smile_emotion = isset($_POST['smile_emotion']) ? trim($_POST['smile_emotion']) : trim($_GET['smile_emotion']);
+ $smile_id = isset($_POST['smile_id']) ? (int)$_POST['smile_id'] : (int)$_GET['smile_id'];
- // Convert < and > to proper htmlentities for parsing
- $smile_code = str_replace('<', '<', $smile_code);
- $smile_code = str_replace('>', '>', $smile_code);
+ // If no code was entered complain
+ if ($smile_code == '' || $smile_url == '') {
+ bb_die($lang['FIELDS_EMPTY']);
+ }
- // Proceed with updating the smiley table
- $sql = "UPDATE " . BB_SMILIES . "
+ // Convert < and > to proper htmlentities for parsing
+ $smile_code = str_replace(['<', '>'], ['<', '>'], $smile_code);
+
+ // Proceed with updating the smiley table
+ $sql = 'UPDATE ' . BB_SMILIES . "
SET code = '" . DB()->escape($smile_code) . "', smile_url = '" . DB()->escape($smile_url) . "', emoticon = '" . DB()->escape($smile_emotion) . "'
WHERE smilies_id = $smile_id";
- if (!($result = DB()->sql_query($sql)))
- {
- bb_die('Could not update smilies #2');
- }
- $datastore->update('smile_replacements');
+ if (!($result = DB()->sql_query($sql))) {
+ bb_die('Could not update smilies #2');
+ }
+ $datastore->update('smile_replacements');
- bb_die($lang['SMILEY_EDIT_SUCCESS'] . ' ' . sprintf($lang['CLICK_RETURN_SMILEADMIN'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '));
- break;
+ bb_die($lang['SMILEY_EDIT_SUCCESS'] . ' ' . sprintf($lang['CLICK_RETURN_SMILEADMIN'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '));
+ break;
- case 'savenew':
- $smile_code = ( isset($_POST['smile_code']) ) ? $_POST['smile_code'] : $_GET['smile_code'];
- $smile_url = ( isset($_POST['smile_url']) ) ? $_POST['smile_url'] : $_GET['smile_url'];
- $smile_url = bb_ltrim(basename($smile_url), "'");
- $smile_emotion = ( isset($_POST['smile_emotion']) ) ? $_POST['smile_emotion'] : $_GET['smile_emotion'];
- $smile_code = trim($smile_code);
- $smile_url = trim($smile_url);
- $smile_emotion = trim($smile_emotion);
+ case 'savenew':
+ $smile_code = $_POST['smile_code'] ?? $_GET['smile_code'];
+ $smile_url = $_POST['smile_url'] ?? $_GET['smile_url'];
+ $smile_url = ltrim(basename($smile_url), "'");
+ $smile_emotion = $_POST['smile_emotion'] ?? $_GET['smile_emotion'];
+ $smile_code = trim($smile_code);
+ $smile_url = trim($smile_url);
+ $smile_emotion = trim($smile_emotion);
- // If no code was entered complain
- if ($smile_code == '' || $smile_url == '')
- {
- bb_die($lang['FIELDS_EMPTY']);
- }
+ // If no code was entered complain
+ if ($smile_code == '' || $smile_url == '') {
+ bb_die($lang['FIELDS_EMPTY']);
+ }
- // Convert < and > to proper htmlentities for parsing
- $smile_code = str_replace('<', '<', $smile_code);
- $smile_code = str_replace('>', '>', $smile_code);
+ // Convert < and > to proper htmlentities for parsing
+ $smile_code = str_replace(['<', '>'], ['<', '>'], $smile_code);
- // Save the data to the smiley table
- $sql = "INSERT INTO " . BB_SMILIES . " (code, smile_url, emoticon)
+ // Save the data to the smiley table
+ $sql = 'INSERT INTO ' . BB_SMILIES . " (code, smile_url, emoticon)
VALUES ('" . DB()->escape($smile_code) . "', '" . DB()->escape($smile_url) . "', '" . DB()->escape($smile_emotion) . "')";
- $result = DB()->sql_query($sql);
- if (!$result)
- {
- bb_die('Could not insert new smiley');
- }
- $datastore->update('smile_replacements');
+ $result = DB()->sql_query($sql);
+ if (!$result) {
+ bb_die('Could not insert new smiley');
+ }
+ $datastore->update('smile_replacements');
- bb_die($lang['SMILEY_ADD_SUCCESS'] . ' ' . sprintf($lang['CLICK_RETURN_SMILEADMIN'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '));
- break;
- }
-}
-else
-{
- $sql = "SELECT * FROM " . BB_SMILIES;
- $result = DB()->sql_query($sql);
- if (!$result)
- {
- bb_die('Could not obtain smileys from database');
- }
+ bb_die($lang['SMILEY_ADD_SUCCESS'] . ' ' . sprintf($lang['CLICK_RETURN_SMILEADMIN'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '));
+ break;
+ }
+} else {
+ $sql = 'SELECT * FROM ' . BB_SMILIES;
+ $result = DB()->sql_query($sql);
+ if (!$result) {
+ bb_die('Could not obtain smileys from database');
+ }
- $smilies = DB()->sql_fetchrowset($result);
+ $smilies = DB()->sql_fetchrowset($result);
- $template->assign_vars(array(
- 'TPL_SMILE_MAIN' => true,
- 'S_HIDDEN_FIELDS' => @$s_hidden_fields,
- 'S_SMILEY_ACTION' => 'admin_smilies.php',
- ));
+ $template->assign_vars([
+ 'TPL_SMILE_MAIN' => true,
+ 'S_HIDDEN_FIELDS' => $s_hidden_fields,
+ 'S_SMILEY_ACTION' => 'admin_smilies.php'
+ ]);
- // Loop throuh the rows of smilies setting block vars for the template
- for ($i = 0; $i < count($smilies); $i++)
- {
- // Replace htmlentites for < and > with actual character
- $smilies[$i]['code'] = str_replace('<', '<', $smilies[$i]['code']);
- $smilies[$i]['code'] = str_replace('>', '>', $smilies[$i]['code']);
+ // Loop throuh the rows of smilies setting block vars for the template
+ for ($i = 0, $iMax = count($smilies); $i < $iMax; $i++) {
+ // Replace htmlentites for < and > with actual character
+ $smilies[$i]['code'] = str_replace('<', '<', $smilies[$i]['code']);
+ $smilies[$i]['code'] = str_replace('>', '>', $smilies[$i]['code']);
- $row_class = !($i % 2) ? 'row1' : 'row2';
+ $row_class = !($i % 2) ? 'row1' : 'row2';
- $template->assign_block_vars('smiles', array(
- 'ROW_CLASS' => $row_class,
+ $template->assign_block_vars('smiles', [
+ 'ROW_CLASS' => $row_class,
- 'SMILEY_IMG' => BB_ROOT . $bb_cfg['smilies_path'] .'/'. $smilies[$i]['smile_url'],
- 'CODE' => $smilies[$i]['code'],
- 'EMOT' => $smilies[$i]['emoticon'],
+ 'SMILEY_IMG' => $pathToSmilesDir . '/' . $smilies[$i]['smile_url'],
+ 'CODE' => $smilies[$i]['code'],
+ 'EMOT' => $smilies[$i]['emoticon'],
- 'U_SMILEY_EDIT' => "admin_smilies.php?mode=edit&id=". $smilies[$i]['smilies_id'],
- 'U_SMILEY_DELETE' => "admin_smilies.php?mode=delete&id=". $smilies[$i]['smilies_id'],
- ));
- }
+ 'U_SMILEY_EDIT' => 'admin_smilies.php?mode=edit&id=' . $smilies[$i]['smilies_id'],
+ 'U_SMILEY_DELETE' => 'admin_smilies.php?mode=delete&id=' . $smilies[$i]['smilies_id'],
+ ]);
+ }
}
-print_page('admin_smilies.tpl', 'admin');
\ No newline at end of file
+print_page('admin_smilies.tpl', 'admin');
diff --git a/admin/admin_terms.php b/admin/admin_terms.php
index cb9437927..45acd875c 100644
--- a/admin/admin_terms.php
+++ b/admin/admin_terms.php
@@ -1,25 +1,32 @@
$_POST['message']));
- bb_die($lang['CONFIG_UPDATED']);
+if (!empty($setmodules)) {
+ $module['GENERAL']['TERMS'] = basename(__FILE__);
+ return;
}
-$template->assign_vars(array(
- 'S_ACTION' => 'admin_terms.php',
- 'EXT_LINK_NW' => $bb_cfg['ext_link_new_win'],
- 'MESSAGE' => ($bb_cfg['terms']) ? $bb_cfg['terms'] : '',
- 'PREVIEW_HTML' => (isset($_REQUEST['preview'])) ? bbcode2html($_POST['message']) : '',
-));
+require __DIR__ . '/pagestart.php';
+require INC_DIR . '/bbcode.php';
-print_page('admin_terms.tpl', 'admin');
\ No newline at end of file
+$preview = isset($_POST['preview']);
+
+if (isset($_POST['post']) && (config()->get('terms') !== $_POST['message'])) {
+ bb_update_config(['terms' => $_POST['message']]);
+ bb_die($lang['TERMS_UPDATED_SUCCESSFULLY'] . ' ' . sprintf($lang['CLICK_RETURN_TERMS_CONFIG'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '));
+}
+
+$template->assign_vars([
+ 'S_ACTION' => 'admin_terms.php',
+ 'EXT_LINK_NW' => config()->get('ext_link_new_win'),
+ 'MESSAGE' => $preview ? $_POST['message'] : config()->get('terms'),
+ 'PREVIEW_HTML' => $preview ? bbcode2html($_POST['message']) : '',
+]);
+
+print_page('admin_terms.tpl', 'admin');
diff --git a/admin/admin_ug_auth.php b/admin/admin_ug_auth.php
index 1fd568925..7cef20864 100644
--- a/admin/admin_ug_auth.php
+++ b/admin/admin_ug_auth.php
@@ -1,474 +1,426 @@
fetch_row($sql))
- {
- $group_id = $row['group_id'];
- }
- else
- {
- $group_id = create_user_group($user_id);
- }
+ if ($row = DB()->fetch_row($sql)) {
+ $group_id = $row['group_id'];
+ } else {
+ $group_id = \TorrentPier\Legacy\Group::create_user_group($user_id);
+ }
- if (!$group_id || !$user_id || is_null($this_user_level))
- {
- trigger_error('data missing', E_USER_ERROR);
- }
+ if (!$group_id || !$user_id || null === $this_user_level) {
+ trigger_error('data missing', E_USER_ERROR);
+ }
- // Make user an admin (if already user)
- if (@$_POST['userlevel'] === 'admin')
- {
- if ($userdata['user_id'] == $user_id || $user_id == GUEST_UID || $user_id == BOT_UID)
- {
- bb_die("Could not update admin status");
- }
+ // Make user an admin (if already user)
+ if (isset($_POST['userlevel'])) {
+ if ($_POST['userlevel'] === 'admin') {
+ if ($userdata['user_id'] == $user_id || $user_id == GUEST_UID || $user_id == BOT_UID) {
+ bb_die($lang['AUTH_GENERAL_ERROR']);
+ }
- DB()->query("UPDATE ". BB_USERS ." SET user_level = ". ADMIN ." WHERE user_id = $user_id LIMIT 1");
+ DB()->query('UPDATE ' . BB_USERS . ' SET user_level = ' . ADMIN . " WHERE user_id = $user_id");
- // Delete any entries in auth_access, they are not required if user is becoming an admin
- delete_permissions($group_id, $user_id);
+ // Delete any entries in auth_access, they are not required if user is becoming an admin
+ \TorrentPier\Legacy\Group::delete_permissions($group_id, $user_id);
- $message = $lang['AUTH_UPDATED'] .' ';
- $message .= sprintf($lang['CLICK_RETURN_USERAUTH'], '', ' ') .' ';
- $message .= sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' ');
+ $message = $lang['AUTH_UPDATED'] . ' ';
+ $message .= sprintf($lang['CLICK_RETURN_USERAUTH'], '', ' ') . ' ';
+ $message .= sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' ');
- bb_die($message);
- }
- // Make admin a user (if already admin)
- else if (@$_POST['userlevel'] === 'user')
- {
- // ignore if you're trying to change yourself from an admin to user!
- if ($userdata['user_id'] == $user_id)
- {
- bb_die("Could not update admin status Could not change yourself from an admin to user");
- }
- // Update users level, reset to USER
- DB()->query("UPDATE ". BB_USERS ." SET user_level = ". USER ." WHERE user_id = $user_id LIMIT 1");
+ bb_die($message);
+ } // Make admin a user (if already admin)
+ elseif ($_POST['userlevel'] === 'user') {
+ // ignore if you're trying to change yourself from an admin to user!
+ if ($userdata['user_id'] == $user_id) {
+ bb_die($lang['AUTH_SELF_ERROR']);
+ }
+ // Update users level, reset to USER
+ DB()->query('UPDATE ' . BB_USERS . ' SET user_level = ' . USER . " WHERE user_id = $user_id");
- delete_permissions($group_id, $user_id);
+ \TorrentPier\Legacy\Group::delete_permissions($group_id, $user_id);
- $message = $lang['AUTH_UPDATED'] .' ';
- $message .= sprintf($lang['CLICK_RETURN_USERAUTH'], '', ' ') .' ';
- $message .= sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' ');
+ $message = $lang['AUTH_UPDATED'] . ' ';
+ $message .= sprintf($lang['CLICK_RETURN_USERAUTH'], '', ' ') . ' ';
+ $message .= sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' ');
- bb_die($message);
- }
+ bb_die($message);
+ }
+ }
- //
- // Submit new USER permissions
- //
- $auth = array();
+ //
+ // Submit new USER permissions
+ //
+ $auth = [];
- if (is_array(@$_POST['auth']))
- {
- array_deep($_POST['auth'], 'intval');
+ if (!empty($_POST['auth']) && is_array($_POST['auth'])) {
+ array_deep($_POST['auth'], 'intval');
- foreach ($_POST['auth'] as $f_id => $bf_ary)
- {
- if (array_sum($bf_ary))
- {
- $auth[$f_id] = bit2dec(array_keys($bf_ary, 1));
- }
- }
- }
+ foreach ($_POST['auth'] as $f_id => $bf_ary) {
+ if (array_sum($bf_ary)) {
+ $auth[$f_id] = bit2dec(array_keys($bf_ary, 1));
+ }
+ }
+ }
- delete_permissions($group_id, null, $cat_id);
- store_permissions($group_id, $auth);
+ \TorrentPier\Legacy\Group::delete_permissions($group_id, null, $cat_id);
+ \TorrentPier\Legacy\Group::store_permissions($group_id, $auth);
+ \TorrentPier\Legacy\Group::update_user_level($user_id);
- update_user_level($user_id);
+ $l_auth_return = ($mode == 'user') ? $lang['CLICK_RETURN_USERAUTH'] : $lang['CLICK_RETURN_GROUPAUTH'];
+ $message = $lang['AUTH_UPDATED'] . ' ';
+ $message .= sprintf($l_auth_return, '', ' ') . ' ';
+ $message .= sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' ');
- $l_auth_return = ($mode == 'user') ? $lang['CLICK_RETURN_USERAUTH'] : $lang['CLICK_RETURN_GROUPAUTH'];
- $message = $lang['AUTH_UPDATED'] .' ';
- $message .= sprintf($l_auth_return, '', ' ') .' ';
- $message .= sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' ');
-
- bb_die($message);
+ bb_die($message);
}
//
// Submit new GROUP permissions
//
-else if ($submit && $mode == 'group' && is_array(@$_POST['auth']))
-{
- if (!$group_data = get_group_data($group_id))
- {
- bb_die($lang['GROUP_NOT_EXIST']);
- }
+elseif ($submit && $mode == 'group' && (!empty($_POST['auth']) && is_array($_POST['auth']))) {
+ if (!$group_data = \TorrentPier\Legacy\Group::get_group_data($group_id)) {
+ bb_die($lang['GROUP_NOT_EXIST']);
+ }
- $auth = array();
- array_deep($_POST['auth'], 'intval');
+ $auth = [];
+ array_deep($_POST['auth'], 'intval');
- foreach ($_POST['auth'] as $f_id => $bf_ary)
- {
- if (array_sum($bf_ary))
- {
- $auth[$f_id] = bit2dec(array_keys($bf_ary, 1));
- }
- }
+ foreach ($_POST['auth'] as $f_id => $bf_ary) {
+ if (array_sum($bf_ary)) {
+ $auth[$f_id] = bit2dec(array_keys($bf_ary, 1));
+ }
+ }
- delete_permissions($group_id, null, $cat_id);
- store_permissions($group_id, $auth);
+ \TorrentPier\Legacy\Group::delete_permissions($group_id, null, $cat_id);
+ \TorrentPier\Legacy\Group::store_permissions($group_id, $auth);
+ \TorrentPier\Legacy\Group::update_user_level('all');
- update_user_level('all');
+ $l_auth_return = $lang['CLICK_RETURN_GROUPAUTH'];
+ $message = $lang['AUTH_UPDATED'] . ' ';
+ $message .= sprintf($l_auth_return, '', ' ') . ' ';
+ $message .= sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' ');
- $l_auth_return = $lang['CLICK_RETURN_GROUPAUTH'];
- $message = $lang['AUTH_UPDATED'] .' ';
- $message .= sprintf($l_auth_return, '', ' ') .' ';
- $message .= sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' ');
-
- bb_die($message);
+ bb_die($message);
}
//
// Front end (changing permissions)
//
-if ($mode == 'user' && (!empty($_POST['username']) || $user_id))
-{
- $page_cfg['quirks_mode'] = true;
+if ($mode == 'user' && (!empty($_POST['username']) || $user_id)) {
+ $page_cfg['quirks_mode'] = true;
- if (!empty($_POST['username']))
- {
- $this_userdata = get_userdata($_POST['username'], true);
- $user_id = $this_userdata['user_id'];
- }
- else
- {
- $this_userdata = get_userdata($user_id);
- }
- if (!$this_userdata)
- {
- bb_die($lang['NO_SUCH_USER']);
- }
+ if (!empty($_POST['username'])) {
+ $this_userdata = get_userdata($_POST['username'], true);
+ $user_id = $this_userdata['user_id'];
+ } else {
+ $this_userdata = get_userdata($user_id);
+ }
+ if (!$this_userdata) {
+ bb_die($lang['NO_SUCH_USER']);
+ }
- if (!$forums = $datastore->get('cat_forums'))
- {
- $datastore->update('cat_forums');
- $forums = $datastore->get('cat_forums');
- }
- $base_url = basename(__FILE__) ."?mode=user&u=$user_id";
+ if (!$forums = $datastore->get('cat_forums')) {
+ $datastore->update('cat_forums');
+ $forums = $datastore->get('cat_forums');
+ }
+ $base_url = basename(__FILE__) . "?mode=user&" . POST_USERS_URL . "=$user_id";
- $ug_data = $this_userdata;
- $ug_data['session_logged_in'] = 1;
+ $ug_data = $this_userdata;
+ $ug_data['session_logged_in'] = 1;
- $u_access = auth(AUTH_ALL, AUTH_LIST_ALL, $ug_data, array(), UG_PERM_USER_ONLY);
- $g_access = auth(AUTH_ALL, AUTH_LIST_ALL, $ug_data, array(), UG_PERM_GROUP_ONLY);
+ $u_access = auth(AUTH_ALL, AUTH_LIST_ALL, $ug_data, [], UG_PERM_USER_ONLY);
+ $g_access = auth(AUTH_ALL, AUTH_LIST_ALL, $ug_data, [], UG_PERM_GROUP_ONLY);
- foreach ($forums['c'] as $c_id => $c_data)
- {
- $template->assign_block_vars('c', array(
- 'CAT_ID' => $c_id,
- 'CAT_TITLE' => $forums['cat_title_html'][$c_id],
- 'CAT_HREF' => "$base_url&c=$c_id",
- ));
+ foreach ($forums['c'] as $c_id => $c_data) {
+ $template->assign_block_vars('c', array(
+ 'CAT_ID' => $c_id,
+ 'CAT_TITLE' => $forums['cat_title_html'][$c_id],
+ 'CAT_HREF' => "$base_url&" . POST_CAT_URL . "=$c_id",
+ ));
- if (!$c =& $_REQUEST['c'] OR !in_array($c, array('all', $c_id)) OR empty($c_data['forums']))
- {
- continue;
- }
+ if (!$c =& $_REQUEST[POST_CAT_URL] or !in_array($c, array('all', $c_id)) or empty($c_data['forums'])) {
+ continue;
+ }
- foreach ($c_data['forums'] as $f_id)
- {
- $f_data = $forums['f'][$f_id];
- $auth_mod = ($u_access[$f_id]['auth_mod'] || $g_access[$f_id]['auth_mod']);
- $disabled = $g_access[$f_id]['auth_mod'];
+ foreach ($c_data['forums'] as $f_id) {
+ $f_data = $forums['f'][$f_id];
+ $auth_mod = ($u_access[$f_id]['auth_mod'] || $g_access[$f_id]['auth_mod']);
+ $disabled = $g_access[$f_id]['auth_mod'];
- $template->assign_block_vars('c.f', array(
- 'DISABLED' => $disabled,
- 'FORUM_ID' => $f_id,
- 'FORUM_NAME' => str_short($forums['forum_name_html'][$f_id], $max_forum_name_length),
- 'SF_SPACER' => ($f_data['forum_parent']) ? HTML_SF_SPACER : '',
- 'IS_MODERATOR' => (bool) $auth_mod,
- 'MOD_STATUS' => ($auth_mod) ? $lang['MODERATOR'] : $lang['NONE'],
- 'MOD_CLASS' => ($auth_mod) ? (($disabled) ? 'yesDisabled' : 'yesMOD') : 'noMOD',
- 'AUTH_MOD_VAL' => ($auth_mod) ? 1 : 0,
- ));
+ $template->assign_block_vars('c.f', array(
+ 'DISABLED' => $disabled,
+ 'FORUM_ID' => $f_id,
+ 'FORUM_NAME' => str_short($forums['forum_name_html'][$f_id], $max_forum_name_length),
+ 'SF_SPACER' => $f_data['forum_parent'] ? HTML_SF_SPACER : '',
+ 'IS_MODERATOR' => (bool)$auth_mod,
+ 'MOD_STATUS' => $auth_mod ? $lang['MODERATOR'] : $lang['NONE'],
+ 'MOD_CLASS' => $auth_mod ? ($disabled ? 'yesDisabled' : 'yesMOD') : 'noMOD',
+ 'AUTH_MOD_VAL' => $auth_mod ? 1 : 0,
+ ));
- foreach ($forum_auth_fields as $auth_type)
- {
- $bf_num = $bf['forum_perm'][$auth_type];
- $f_perm = $f_data[$auth_type];
- $auth_via_acl = ($u_access[$f_id][$auth_type] || $g_access[$f_id][$auth_type]);
+ foreach ($forum_auth_fields as $auth_type) {
+ $bf_num = $bf['forum_perm'][$auth_type];
+ $f_perm = $f_data[$auth_type];
+ $auth_via_acl = ($u_access[$f_id][$auth_type] || $g_access[$f_id][$auth_type]);
- if ($f_perm == AUTH_ACL)
- {
- $disabled = ($auth_mod || $g_access[$f_id][$auth_type]);
- $perm_sign = ($auth_via_acl || $auth_mod) ? $yes_sign : $no_sign;
- $acl_class = ($auth_via_acl || $auth_mod) ? 'yes' : 'no';
- }
- else
- {
- $disabled = true;
- $perm_sign = ($auth_via_acl) ? $yes_sign : $no_sign;
- $acl_class = ($auth_via_acl) ? 'yes' : 'no';
- }
+ if ($f_perm == AUTH_ACL) {
+ $disabled = ($auth_mod || $g_access[$f_id][$auth_type]);
+ $perm_sign = ($auth_via_acl || $auth_mod) ? $yes_sign : $no_sign;
+ $acl_class = ($auth_via_acl || $auth_mod) ? 'yes' : 'no';
+ } else {
+ $disabled = true;
+ $perm_sign = $auth_via_acl ? $yes_sign : $no_sign;
+ $acl_class = $auth_via_acl ? 'yes' : 'no';
+ }
- $template->assign_block_vars('c.f.acl', array(
- 'DISABLED' => $disabled,
- 'PERM_SIGN' => $perm_sign,
- 'ACL_CLASS' => $acl_class,
- 'FORUM_ID' => $f_id,
- 'ACL_TYPE_BF' => $bf_num,
- 'ACL_VAL' => ($auth_via_acl) ? 1 : 0,
- ));
- }
- }
- }
+ $template->assign_block_vars('c.f.acl', array(
+ 'DISABLED' => $disabled,
+ 'PERM_SIGN' => $perm_sign,
+ 'ACL_CLASS' => $acl_class,
+ 'FORUM_ID' => $f_id,
+ 'ACL_TYPE_BF' => $bf_num,
+ 'ACL_VAL' => $auth_via_acl ? 1 : 0,
+ ));
+ }
+ }
+ }
- $template->assign_vars(array(
- 'AUTH_MOD_BF' => AUTH_MOD,
- ));
+ $template->assign_vars(array(
+ 'AUTH_MOD_BF' => AUTH_MOD,
+ ));
- $s_column_span = 2;
+ $s_column_span = 2;
- foreach ($forum_auth_fields as $auth_type)
- {
- $template->assign_block_vars('acltype', array(
- 'ACL_TYPE_NAME' => preg_replace("#(.{5})#u", "\\1 ", $lang[strtoupper($auth_type)]),
- 'ACL_TYPE_BF' => $bf['forum_perm'][$auth_type],
- ));
- $s_column_span++;
- }
+ foreach ($forum_auth_fields as $auth_type) {
+ $template->assign_block_vars('acltype', array(
+ 'ACL_TYPE_NAME' => preg_replace('#(.{5})#u', "\\1 ", $lang[strtoupper($auth_type)]),
+ 'ACL_TYPE_BF' => $bf['forum_perm'][$auth_type],
+ ));
+ $s_column_span++;
+ }
- unset($forums, $u_access, $g_access);
- $datastore->rm('cat_forums');
+ unset($forums, $u_access, $g_access);
+ $datastore->rm('cat_forums');
- $s_hidden_fields = '
-
-
+ $s_hidden_fields = '
+
+
';
- $s_user_type = ($this_userdata['user_level'] == ADMIN) ? '
+ $s_user_type = ($this_userdata['user_level'] == ADMIN) ? '
- '. $lang['AUTH_ADMIN'] .'
- '. $lang['AUTH_USER'] .'
+ ' . $lang['AUTH_ADMIN'] . '
+ ' . $lang['AUTH_USER'] . '
' : '
- '. $lang['AUTH_ADMIN'] .'
- '. $lang['AUTH_USER'] .'
+ ' . $lang['AUTH_ADMIN'] . '
+ ' . $lang['AUTH_USER'] . '
';
- $template->assign_block_vars('switch_user_auth', array());
+ $template->assign_block_vars('switch_user_auth', []);
- $template->assign_vars(array(
- 'TPL_AUTH_UG_MAIN' => true,
+ $template->assign_vars(array(
+ 'TPL_AUTH_UG_MAIN' => true,
+ 'USER_OR_GROUPNAME' => profile_url($this_userdata, true),
+ 'USER_LEVEL' => $lang['USER_LEVEL'] . ' : ' . $s_user_type,
+ 'T_USER_OR_GROUPNAME' => $lang['USERNAME'],
+ 'T_AUTH_TITLE' => $lang['AUTH_CONTROL_USER'],
+ 'T_AUTH_EXPLAIN' => $lang['USER_AUTH_EXPLAIN'],
+ 'S_COLUMN_SPAN' => $s_column_span,
+ 'S_HIDDEN_FIELDS' => $s_hidden_fields,
+ ));
+} elseif ($mode == 'group' && $group_id) {
+ $page_cfg['quirks_mode'] = true;
- 'USER_OR_GROUPNAME' => $this_userdata['username'],
- 'USER_LEVEL' => $lang['USER_LEVEL'] .' : '. $s_user_type,
- 'USER_GROUP_MEMBERSHIPS' => $lang['GROUP_MEMBERSHIPS'],
- ));
+ if (!$group_data = \TorrentPier\Legacy\Group::get_group_data($group_id)) {
+ bb_die($lang['GROUP_NOT_EXIST']);
+ }
- $template->assign_vars(array(
- 'T_USER_OR_GROUPNAME' => $lang['USERNAME'],
- 'T_AUTH_TITLE' => $lang['AUTH_CONTROL_USER'],
- 'T_AUTH_EXPLAIN' => $lang['USER_AUTH_EXPLAIN'],
+ if (!$forums = $datastore->get('cat_forums')) {
+ $datastore->update('cat_forums');
+ $forums = $datastore->get('cat_forums');
+ }
+ $base_url = basename(__FILE__) . "?mode=group&" . POST_GROUPS_URL . "=$group_id";
- 'S_COLUMN_SPAN' => $s_column_span,
- 'S_HIDDEN_FIELDS' => $s_hidden_fields,
- ));
-}
-else if ($mode == 'group' && $group_id)
-{
- $page_cfg['quirks_mode'] = true;
+ $ug_data = array('group_id' => $group_id);
+ $u_access = auth(AUTH_ALL, AUTH_LIST_ALL, $ug_data);
- if (!$group_data = get_group_data($group_id))
- {
- bb_die($lang['GROUP_NOT_EXIST']);
- }
+ foreach ($forums['c'] as $c_id => $c_data) {
+ $template->assign_block_vars('c', array(
+ 'CAT_ID' => $c_id,
+ 'CAT_TITLE' => $forums['cat_title_html'][$c_id],
+ 'CAT_HREF' => "$base_url&" . POST_CAT_URL . "=$c_id",
+ ));
- if (!$forums = $datastore->get('cat_forums'))
- {
- $datastore->update('cat_forums');
- $forums = $datastore->get('cat_forums');
- }
- $base_url = basename(__FILE__) ."?mode=group&g=$group_id";
+ if (!($c =& $_REQUEST[POST_CAT_URL]) || !in_array($c, array('all', $c_id)) || empty($c_data['forums'])) {
+ continue;
+ }
- $ug_data = array('group_id' => $group_id);
- $u_access = auth(AUTH_ALL, AUTH_LIST_ALL, $ug_data);
+ foreach ($c_data['forums'] as $f_id) {
+ $f_data = $forums['f'][$f_id];
+ $auth_mod = $u_access[$f_id]['auth_mod'];
- foreach ($forums['c'] as $c_id => $c_data)
- {
- $template->assign_block_vars('c', array(
- 'CAT_ID' => $c_id,
- 'CAT_TITLE' => $forums['cat_title_html'][$c_id],
- 'CAT_HREF' => "$base_url&c=$c_id",
- ));
+ $template->assign_block_vars('c.f', array(
+ 'DISABLED' => false,
+ 'FORUM_ID' => $f_id,
+ 'FORUM_NAME' => str_short($forums['forum_name_html'][$f_id], $max_forum_name_length),
+ 'SF_SPACER' => $f_data['forum_parent'] ? HTML_SF_SPACER : '',
+ 'IS_MODERATOR' => (bool)$auth_mod,
+ 'MOD_STATUS' => $auth_mod ? $lang['MODERATOR'] : $lang['NO'],
+ 'MOD_CLASS' => $auth_mod ? 'yesMOD' : 'noMOD',
+ 'AUTH_MOD_VAL' => $auth_mod ? 1 : 0,
+ ));
- if (!$c =& $_REQUEST['c'] OR !in_array($c, array('all', $c_id)) OR empty($c_data['forums']))
- {
- continue;
- }
+ foreach ($forum_auth_fields as $auth_type) {
+ $bf_num = $bf['forum_perm'][$auth_type];
+ $f_perm = $f_data[$auth_type];
+ $auth_via_acl = $u_access[$f_id][$auth_type];
- foreach ($c_data['forums'] as $f_id)
- {
- $f_data = $forums['f'][$f_id];
- $auth_mod = $u_access[$f_id]['auth_mod'];
+ if ($f_perm == AUTH_ACL) {
+ $disabled = $auth_mod;
+ $perm_sign = ($auth_via_acl || $auth_mod) ? $yes_sign : $no_sign;
+ $acl_class = ($auth_via_acl || $auth_mod) ? 'yes' : 'no';
+ } else {
+ $disabled = true;
+ $perm_sign = $auth_via_acl ? $yes_sign : $no_sign;
+ $acl_class = $auth_via_acl ? 'yes' : 'no';
+ }
- $template->assign_block_vars('c.f', array(
- 'DISABLED' => false,
- 'FORUM_ID' => $f_id,
- 'FORUM_NAME' => str_short($forums['forum_name_html'][$f_id], $max_forum_name_length),
- 'SF_SPACER' => ($f_data['forum_parent']) ? HTML_SF_SPACER : '',
- 'IS_MODERATOR' => (bool) $auth_mod,
- 'MOD_STATUS' => ($auth_mod) ? $lang['MODERATOR'] : $lang['NO'],
- 'MOD_CLASS' => ($auth_mod) ? 'yesMOD' : 'noMOD',
- 'AUTH_MOD_VAL' => ($auth_mod) ? 1 : 0,
- ));
+ $template->assign_block_vars('c.f.acl', array(
+ 'DISABLED' => $disabled,
+ 'PERM_SIGN' => $perm_sign,
+ 'ACL_CLASS' => $acl_class,
+ 'FORUM_ID' => $f_id,
+ 'ACL_TYPE_BF' => $bf_num,
+ 'ACL_VAL' => $auth_via_acl ? 1 : 0,
+ ));
+ }
+ }
+ }
- foreach ($forum_auth_fields as $auth_type)
- {
- $bf_num = $bf['forum_perm'][$auth_type];
- $f_perm = $f_data[$auth_type];
- $auth_via_acl = $u_access[$f_id][$auth_type];
+ $template->assign_vars(array(
+ 'AUTH_MOD_BF' => AUTH_MOD,
+ ));
- if ($f_perm == AUTH_ACL)
- {
- $disabled = $auth_mod;
- $perm_sign = ($auth_via_acl || $auth_mod) ? $yes_sign : $no_sign;
- $acl_class = ($auth_via_acl || $auth_mod) ? 'yes' : 'no';
- }
- else
- {
- $disabled = true;
- $perm_sign = ($auth_via_acl) ? $yes_sign : $no_sign;
- $acl_class = ($auth_via_acl) ? 'yes' : 'no';
- }
+ $s_column_span = 2;
- $template->assign_block_vars('c.f.acl', array(
- 'DISABLED' => $disabled,
- 'PERM_SIGN' => $perm_sign,
- 'ACL_CLASS' => $acl_class,
- 'FORUM_ID' => $f_id,
- 'ACL_TYPE_BF' => $bf_num,
- 'ACL_VAL' => ($auth_via_acl) ? 1 : 0,
- ));
- }
- }
- }
+ foreach ($forum_auth_fields as $auth_type) {
+ $template->assign_block_vars('acltype', array(
+ 'ACL_TYPE_NAME' => preg_replace('#(.{5})#u', "\\1 ", $lang[strtoupper($auth_type)]),
+ 'ACL_TYPE_BF' => $bf['forum_perm'][$auth_type],
+ ));
+ $s_column_span++;
+ }
- $template->assign_vars(array(
- 'AUTH_MOD_BF' => AUTH_MOD,
- ));
+ unset($forums, $ug_data, $u_access);
+ $datastore->rm('cat_forums');
- $s_column_span = 2;
-
- foreach ($forum_auth_fields as $auth_type)
- {
- $template->assign_block_vars('acltype', array(
- 'ACL_TYPE_NAME' => preg_replace("#(.{5})#u", "\\1 ", $lang[strtoupper($auth_type)]),
- 'ACL_TYPE_BF' => $bf['forum_perm'][$auth_type],
- ));
- $s_column_span++;
- }
-
- unset($forums, $ug_data, $u_access);
- $datastore->rm('cat_forums');
-
- $s_hidden_fields = '
-
-
+ $s_hidden_fields = '
+
+
';
- $template->assign_vars(array(
- 'TPL_AUTH_UG_MAIN' => true,
+ $template->assign_vars(array(
+ 'TPL_AUTH_UG_MAIN' => true,
+ 'T_USER_OR_GROUPNAME' => $lang['GROUP_NAME'],
+ 'USER_LEVEL' => false,
+ 'T_AUTH_TITLE' => $lang['AUTH_CONTROL_GROUP'],
+ 'T_AUTH_EXPLAIN' => $lang['GROUP_AUTH_EXPLAIN'],
+ 'USER_OR_GROUPNAME' => ('' . htmlCHR($group_data['group_name']) . ' '),
+ 'S_COLUMN_SPAN' => $s_column_span,
+ 'S_HIDDEN_FIELDS' => $s_hidden_fields,
+ ));
+} else {
+ // Select a user/group
+ if ($mode == 'user') {
+ $template->assign_vars(array(
+ 'TPL_SELECT_USER' => true,
+ 'U_SEARCH_USER' => BB_ROOT . 'search.php?mode=searchuser',
+ ));
+ } else {
+ $template->assign_vars(array(
+ 'TPL_SELECT_GROUP' => true,
+ 'S_GROUP_SELECT' => get_select('groups'),
+ ));
+ }
- 'T_USER_OR_GROUPNAME' => $lang['GROUP_NAME'],
- 'USER_LEVEL' => false,
- 'T_AUTH_TITLE' => $lang['AUTH_CONTROL_GROUP'],
- 'T_AUTH_EXPLAIN' => $lang['GROUP_AUTH_EXPLAIN'],
- 'USER_OR_GROUPNAME' => htmlCHR($group_data['group_name']),
- 'S_COLUMN_SPAN' => $s_column_span,
- 'S_HIDDEN_FIELDS' => $s_hidden_fields,
- ));
-}
-else
-{
- // Select a user/group
- if ($mode == 'user')
- {
- $template->assign_vars(array(
- 'TPL_SELECT_USER' => true,
- 'U_SEARCH_USER' => BB_ROOT ."search.php?mode=searchuser",
- ));
- }
- else
- {
- $template->assign_vars(array(
- 'TPL_SELECT_GROUP' => true,
- 'S_GROUP_SELECT' => get_select('groups'),
- ));
- }
+ $s_hidden_fields = ' ';
- $s_hidden_fields = ' ';
-
- $template->assign_vars(array(
- 'S_HIDDEN_FIELDS' => $s_hidden_fields,
- ));
+ $template->assign_vars(array(
+ 'S_HIDDEN_FIELDS' => $s_hidden_fields,
+ ));
}
$template->assign_vars(array(
- 'YES_SIGN' => $yes_sign,
- 'NO_SIGN' => $no_sign,
- 'T_MOD_YES' => $lang['MODERATOR'],
- 'T_MOD_NO' => $lang['NO'],
- 'S_AUTH_ACTION' => "admin_ug_auth.php",
- 'SELECTED_CAT' => !empty($_REQUEST['c']) ? $_REQUEST['c'] : '',
- 'U_ALL_FORUMS' => !empty($base_url) ? "$base_url&c=all" : '',
+ 'YES_SIGN' => $yes_sign,
+ 'NO_SIGN' => $no_sign,
+ 'S_AUTH_ACTION' => 'admin_ug_auth.php',
+ 'SELECTED_CAT' => !empty($_REQUEST[POST_CAT_URL]) ? $_REQUEST[POST_CAT_URL] : '',
+ 'U_ALL_FORUMS' => !empty($base_url) ? "$base_url&" . POST_CAT_URL . "=all" : '',
));
-print_page('admin_ug_auth.tpl', 'admin');
\ No newline at end of file
+print_page('admin_ug_auth.tpl', 'admin');
diff --git a/admin/admin_user_ban.php b/admin/admin_user_ban.php
index 72cbac3ff..af4c31b81 100644
--- a/admin/admin_user_ban.php
+++ b/admin/admin_user_ban.php
@@ -1,362 +1,81 @@
sql_query($sql)))
- {
- bb_die('Could not obtain banlist information');
- }
-
- $current_banlist = DB()->sql_fetchrowset($result);
- DB()->sql_freeresult($result);
-
- $kill_session_sql = '';
- for ($i = 0; $i < count($user_list); $i++)
- {
- $in_banlist = false;
- for ($j = 0; $j < count($current_banlist); $j++)
- {
- if ($user_list[$i] == $current_banlist[$j]['ban_userid'])
- {
- $in_banlist = true;
- }
- }
-
- if (!$in_banlist)
- {
- $kill_session_sql .= ( ( $kill_session_sql != '' ) ? ' OR ' : '' ) . "session_user_id = " . $user_list[$i];
-
- $sql = "INSERT INTO " . BB_BANLIST . " (ban_userid) VALUES (" . $user_list[$i] . ")";
- if (!DB()->sql_query($sql))
- {
- bb_die('Could not insert ban_userid info into database');
- }
- }
- }
-
- for ($i = 0; $i < count($ip_list); $i++)
- {
- $in_banlist = false;
- for ($j = 0; $j < count($current_banlist); $j++)
- {
- if ($ip_list[$i] == $current_banlist[$j]['ban_ip'])
- {
- $in_banlist = true;
- }
- }
-
- if (!$in_banlist)
- {
- if (preg_match('/(ff\.)|(\.ff)/is', chunk_split($ip_list[$i], 2, '.')))
- {
- $kill_ip_sql = "session_ip LIKE '" . str_replace('.', '', preg_replace('/(ff\.)|(\.ff)/is', '%', chunk_split($ip_list[$i], 2, "."))) . "'";
- }
- else
- {
- $kill_ip_sql = "session_ip = '" . $ip_list[$i] . "'";
- }
-
- $kill_session_sql .= ( ( $kill_session_sql != '' ) ? ' OR ' : '' ) . $kill_ip_sql;
-
- $sql = "INSERT INTO " . BB_BANLIST . " (ban_ip) VALUES ('" . $ip_list[$i] . "')";
- if ( !DB()->sql_query($sql) )
- {
- bb_die('Could not insert ban_ip info into database');
- }
- }
- }
-
- // Now we'll delete all entries from the session table
- if ($kill_session_sql != '')
- {
- $sql = "DELETE FROM " . BB_SESSIONS . " WHERE $kill_session_sql";
- if (!DB()->sql_query($sql))
- {
- bb_die('Could not delete banned sessions from database');
- }
- }
-
- for ($i = 0; $i < count($email_list); $i++)
- {
- $in_banlist = false;
- for ($j = 0; $j < count($current_banlist); $j++)
- {
- if ($email_list[$i] == $current_banlist[$j]['ban_email'])
- {
- $in_banlist = true;
- }
- }
-
- if (!$in_banlist)
- {
- $sql = "INSERT INTO " . BB_BANLIST . " (ban_email) VALUES ('" . DB()->escape($email_list[$i]) . "')";
- if (!DB()->sql_query($sql))
- {
- bb_die('Could not insert ban_email info into database');
- }
- }
- }
-
- $where_sql = '';
-
- if (isset($_POST['unban_user']))
- {
- $user_list = $_POST['unban_user'];
-
- for ($i = 0; $i < count($user_list); $i++)
- {
- if ($user_list[$i] != -1)
- {
- $where_sql .= ( ( $where_sql != '' ) ? ', ' : '' ) . intval($user_list[$i]);
- }
- }
- }
-
- if (isset($_POST['unban_ip']))
- {
- $ip_list = $_POST['unban_ip'];
-
- for ($i = 0; $i < count($ip_list); $i++)
- {
- if ($ip_list[$i] != -1)
- {
- $where_sql .= ( ( $where_sql != '' ) ? ', ' : '' ) . DB()->escape($ip_list[$i]);
- }
- }
- }
-
- if (isset($_POST['unban_email']))
- {
- $email_list = $_POST['unban_email'];
-
- for ($i = 0; $i < count($email_list); $i++)
- {
- if ($email_list[$i] != -1)
- {
- $where_sql .= ( ( $where_sql != '' ) ? ', ' : '' ) . DB()->escape($email_list[$i]);
- }
- }
- }
-
- if ($where_sql != '')
- {
- $sql = "DELETE FROM " . BB_BANLIST . " WHERE ban_id IN ($where_sql)";
- if (!DB()->sql_query($sql))
- {
- bb_die('Could not delete ban info from database');
- }
- }
-
- bb_die($lang['BAN_UPDATE_SUCESSFUL'] . ' ' . sprintf($lang['CLICK_RETURN_BANADMIN'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '));
-}
-else
-{
- $template->assign_vars(array(
- 'S_BANLIST_ACTION' => 'admin_user_ban.php',
- ));
-
- $userban_count = 0;
- $ipban_count = 0;
- $emailban_count = 0;
-
- $sql = "SELECT b.ban_id, u.user_id, u.username
- FROM " . BB_BANLIST . " b, " . BB_USERS . " u
- WHERE u.user_id = b.ban_userid
- AND b.ban_userid <> 0
- AND u.user_id <> " . GUEST_UID . "
- ORDER BY u.username ASC";
- if (!($result = DB()->sql_query($sql)))
- {
- bb_die('Could not select current user_id ban list');
- }
-
- $user_list = DB()->sql_fetchrowset($result);
- DB()->sql_freeresult($result);
-
- $select_userlist = '';
- for ($i = 0; $i < count($user_list); $i++)
- {
- $select_userlist .= '' . $user_list[$i]['username'] . ' ';
- $userban_count++;
- }
-
- if ($select_userlist == '')
- {
- $select_userlist = '' . $lang['NO_BANNED_USERS'] . ' ';
- }
-
- $select_userlist = '' . $select_userlist . ' ';
-
- $sql = "SELECT ban_id, ban_ip, ban_email FROM ". BB_BANLIST ." ORDER BY ban_ip";
- if (!($result = DB()->sql_query($sql)))
- {
- bb_die('Could not select current ip ban list');
- }
-
- $banlist = DB()->sql_fetchrowset($result);
- DB()->sql_freeresult($result);
-
- $select_iplist = '';
- $select_emaillist = '';
-
- for ($i = 0; $i < count($banlist); $i++)
- {
- $ban_id = $banlist[$i]['ban_id'];
-
- if (!empty($banlist[$i]['ban_ip']))
- {
- $ban_ip = str_replace('255', '*', decode_ip($banlist[$i]['ban_ip']));
- $select_iplist .= '' . $ban_ip . ' ';
- $ipban_count++;
- }
- else if (!empty($banlist[$i]['ban_email']))
- {
- $ban_email = $banlist[$i]['ban_email'];
- $select_emaillist .= '' . $ban_email . ' ';
- $emailban_count++;
- }
- }
-
- if ($select_iplist == '')
- {
- $select_iplist = '' . $lang['NO_BANNED_IP'] . ' ';
- }
-
- if ($select_emaillist == '')
- {
- $select_emaillist = '' . $lang['NO_BANNED_EMAIL'] . ' ';
- }
-
- $select_iplist = '' . $select_iplist . ' ';
- $select_emaillist = '' . $select_emaillist . ' ';
-
- $template->assign_vars(array(
- 'U_SEARCH_USER' => './../search.php?mode=searchuser',
- 'S_UNBAN_USERLIST_SELECT' => $select_userlist,
- 'S_UNBAN_IPLIST_SELECT' => $select_iplist,
- 'S_UNBAN_EMAILLIST_SELECT' => $select_emaillist,
- 'S_BAN_ACTION' => 'admin_user_ban.php',
- ));
+if (!empty($setmodules)) {
+ $module['USERS']['BAN_MANAGEMENT'] = basename(__FILE__);
+ return;
}
-print_page('admin_user_ban.tpl', 'admin');
\ No newline at end of file
+require __DIR__ . '/pagestart.php';
+
+$submit = isset($_POST['submit']);
+
+// Check for demo mode
+if (IN_DEMO_MODE && $submit) {
+ bb_die($lang['CANT_EDIT_IN_DEMO_MODE']);
+}
+
+if ($submit) {
+ // Ban action
+ if (!empty($_POST['username'])) {
+ if (!$this_userdata = get_userdata($_POST['username'], true)) {
+ bb_die($lang['NO_USER_ID_SPECIFIED'] . ' ' . sprintf($lang['CLICK_RETURN_BANADMIN'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '));
+ }
+
+ if (!getBanInfo((int)$this_userdata['user_id'])) {
+ $sql = 'INSERT INTO ' . BB_BANLIST . ' (ban_userid) VALUES (' . $this_userdata['user_id'] . ')';
+ if (!DB()->sql_query($sql)) {
+ bb_die('Could not insert ban_userid info into database');
+ }
+ }
+ }
+
+ // Unban action
+ $where_sql = '';
+
+ if (!empty($_POST['unban_user'])) {
+ $user_list = $_POST['unban_user'];
+
+ for ($i = 0, $iMax = count($user_list); $i < $iMax; $i++) {
+ if ($user_list[$i] != -1) {
+ $where_sql .= (($where_sql != '') ? ', ' : '') . (int)$user_list[$i];
+ }
+ }
+
+ if ($where_sql != '') {
+ $sql = 'DELETE FROM ' . BB_BANLIST . " WHERE ban_id IN ($where_sql)";
+ if (!DB()->sql_query($sql)) {
+ bb_die('Could not delete ban info from database');
+ }
+ }
+ }
+
+ $datastore->update('ban_list');
+ bb_die($lang['BAN_UPDATE_SUCESSFUL'] . ' ' . sprintf($lang['CLICK_RETURN_BANADMIN'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '));
+} else {
+ $template->assign_vars(['S_BANLIST_ACTION' => 'admin_user_ban.php']);
+
+ $select_userlist = '';
+ foreach (getBanInfo() as $ban) {
+ $select_userlist .= '' . get_username($ban['ban_userid']) . ' ';
+ }
+
+ if ($select_userlist == '') {
+ $select_userlist = '' . $lang['NO_BANNED_USERS'] . ' ';
+ }
+ $select_userlist = '' . $select_userlist . ' ';
+
+ $template->assign_vars([
+ 'U_SEARCH_USER' => './../search.php?mode=searchuser',
+ 'S_UNBAN_USERLIST_SELECT' => $select_userlist,
+ 'S_BAN_ACTION' => 'admin_user_ban.php'
+ ]);
+}
+
+print_page('admin_user_ban.tpl', 'admin');
diff --git a/admin/admin_user_search.php b/admin/admin_user_search.php
index 31d3465ad..d383e5a29 100644
--- a/admin/admin_user_search.php
+++ b/admin/admin_user_search.php
@@ -1,1052 +1,937 @@
sql_query($sql))
- {
- bb_die('Could not select group data #1');
- }
-
- $group_list = '';
-
- if (DB()->num_rows($result) != 0)
- {
- $template->assign_block_vars('groups_exist', array());
-
- while ($row = DB()->sql_fetchrow($result))
- {
- $group_list .= ''.strip_tags(htmlspecialchars($row['group_name'])).' ';
- }
- }
-
- $sql = "SELECT * FROM " . BB_RANKS . " WHERE rank_special = 1 ORDER BY rank_title";
- if (!($result = DB()->sql_query($sql)))
- {
- bb_die('Could not obtain ranks data');
- }
- $rank_select_box = '';
- if (DB()->num_rows($result) != 0)
- {
- $template->assign_block_vars('ranks_exist', array());
- while( $row = DB()->sql_fetchrow($result) )
- {
- $rank = $row['rank_title'];
- $rank_id = $row['rank_id'];
- $rank_select_box .= '' . $rank . ' ';
- }
- }
-
- $language_list = language_select('', 'language_type');
- $timezone_list = tz_select('', 'timezone_type');
-
- $sql = "SELECT f.forum_id, f.forum_name, f.forum_parent, c.cat_id, c.cat_title
- FROM ( ". BB_FORUMS ." AS f INNER JOIN ". BB_CATEGORIES ." AS c ON c.cat_id = f.cat_id )
- ORDER BY c.cat_order, f.forum_order ASC";
-
- if (!$result = DB()->sql_query($sql))
- {
- bb_die('Could not select forum data');
- }
-
- $forums = array();
-
- if (DB()->num_rows($result) != 0)
- {
- $template->assign_block_vars('forums_exist', array());
-
- $last_cat_id = -1;
- $forums_list = '';
-
- while ($row = DB()->sql_fetchrow($result))
- {
- if ($row['cat_id'] != $last_cat_id)
- {
- $forums_list .= '';
- $last_cat_id = $row['cat_id'];
- }
-
- $forums_list .= ''.(($row['forum_parent']) ? HTML_SF_SPACER : '').htmlCHR($row['forum_name']).' ';
- }
- }
-
- $lastvisited = array(1, 7, 14, 30, 60, 120, 365, 500, 730, 1000);
- $lastvisited_list = '';
-
- foreach ($lastvisited as $days)
- {
- $lastvisited_list .= ''.$days.' '. ( ( $days > 1 ) ? $lang['DAYS'] : $lang['DAY'] ) .' ';
- }
-
- $template->assign_vars(array(
- 'TPL_ADMIN_USER_SEARCH_MAIN' => true,
-
- 'YEAR' => date("Y"),
- 'MONTH' => date("m"),
- 'DAY' => date("d"),
- 'GROUP_LIST' => $group_list,
- 'RANK_SELECT_BOX' => $rank_select_box,
- 'LANGUAGE_LIST' => $language_list,
- 'TIMEZONE_LIST' => $timezone_list,
- 'FORUMS_LIST' => $forums_list,
- 'LASTVISITED_LIST' => $lastvisited_list,
-
- 'S_SEARCH_ACTION' => 'admin_user_search.php',
- ));
-}
-else
-{
- $mode = '';
-
- // validate mode
- if (isset($_REQUEST['search_username']))
- {
- $mode = 'search_username';
- }
- elseif (isset($_REQUEST['search_email']))
- {
- $mode = 'search_email';
- }
- elseif (isset($_REQUEST['search_ip']))
- {
- $mode = 'search_ip';
- }
- elseif (isset($_REQUEST['search_joindate']))
- {
- $mode = 'search_joindate';
- }
- elseif (isset($_REQUEST['search_group']))
- {
- $mode = 'search_group';
- }
- elseif (isset($_REQUEST['search_rank']))
- {
- $mode = 'search_rank';
- }
- elseif (isset($_REQUEST['search_postcount']))
- {
- $mode = 'search_postcount';
- }
- elseif (isset($_REQUEST['search_userfield']))
- {
- $mode = 'search_userfield';
- }
- elseif (isset($_REQUEST['search_lastvisited']))
- {
- $mode = 'search_lastvisited';
- }
- elseif (isset($_REQUEST['search_language']))
- {
- $mode = 'search_language';
- }
- elseif (isset($_REQUEST['search_timezone']))
- {
- $mode = 'search_timezone';
- }
- elseif (isset($_REQUEST['search_moderators']))
- {
- $mode = 'search_moderators';
- }
- elseif (isset($_REQUEST['search_misc']))
- {
- $mode = 'search_misc';
- }
-
- // validate fields (that they exist)
- switch ($mode)
- {
- case 'search_username':
- $username = $_REQUEST['username'];
- if (!$username) bb_die($lang['SEARCH_INVALID_USERNAME']);
- break;
-
- case 'search_email':
- $email = $_REQUEST['email'];
- if (!$email) bb_die($lang['SEARCH_INVALID_EMAIL']);
- break;
-
- case 'search_ip':
- $ip_address = $_REQUEST['ip_address'];
- if (!$ip_address) bb_die($lang['SEARCH_INVALID_IP']);
- break;
-
- case 'search_joindate':
- $date_type = $_REQUEST['date_type'];
- $date_day = $_REQUEST['date_day'];
- $date_month = $_REQUEST['date_month'];
- $date_year = $_REQUEST['date_year'];
- if (!($date_type || $date_day || $date_month || $date_year)) bb_die($lang['SEARCH_INVALID_DATE']);
- break;
-
- case 'search_group':
- $group_id = $_REQUEST['group_id'];
- if (!$group_id) bb_die($lang['SEARCH_INVALID_GROUP']);
- break;
-
- case 'search_rank':
- $rank_id = $_REQUEST['rank_id'];
- if (!$rank_id) bb_die($lang['SEARCH_INVALID_RANK']);
- break;
-
- case 'search_postcount':
- $postcount_type = $_REQUEST['postcount_type'];
- $postcount_value = $_REQUEST['postcount_value'];
- if (!$postcount_type || (!$postcount_value && $postcount_value != 0)) bb_die($lang['SEARCH_INVALID_POSTCOUNT']);
- break;
-
- case 'search_userfield':
- $userfield_type = $_REQUEST['userfield_type'];
- $userfield_value = $_REQUEST['userfield_value'];
- if (!$userfield_type || !$userfield_value) bb_die($lang['SEARCH_INVALID_USERFIELD']);
- break;
-
- case 'search_lastvisited':
- $lastvisited_days = $_REQUEST['lastvisited_days'];
- $lastvisited_type = $_REQUEST['lastvisited_type'];
- if (!$lastvisited_days || !$lastvisited_type) bb_die($lang['SEARCH_INVALID_LASTVISITED']);
- break;
-
- case 'search_language':
- $language_type = $_REQUEST['language_type'];
- if (!$language_type) bb_die($lang['SEARCH_INVALID_LANGUAGE']);
- break;
-
- case 'search_timezone':
- $timezone_type = $_REQUEST['timezone_type'];
- if (!$timezone_type && $timezone_type != 0) bb_die($lang['SEARCH_INVALID_TIMEZONE']);
- break;
-
- case 'search_moderators':
- $moderators_forum = $_REQUEST['moderators_forum'];
- if (!$moderators_forum) bb_die($lang['SEARCH_INVALID_MODERATORS']);
- break;
-
- case 'search_misc':
- $misc = $_REQUEST['misc'];
- if (!$misc) bb_die($lang['SEARCH_INVALID']);
- break;
-
- default:
- bb_die('Invalid mode');
- }
-
- $base_url = 'admin_user_search.php?dosearch=true';
-
- $select_sql = "SELECT u.user_id, u.username, u.user_rank, u.user_email, u.user_posts, u.user_regdate, u.user_level, u.user_active, u.user_lastvisit FROM ". BB_USERS ." AS u";
-
- $lower_b = 'LOWER(';
- $lower_e = ')';
-
- // validate data & prepare sql
- switch($mode)
- {
- case 'search_username':
- $base_url .= '&search_username=true&username='.rawurlencode(stripslashes($username));
-
- $text = sprintf($lang['SEARCH_FOR_USERNAME'], strip_tags(htmlspecialchars(stripslashes($username))));
-
- $username = preg_replace('/\*/', '%', trim(strip_tags(strtolower($username))));
-
- if (strstr($username, '%'))
- {
- $op = 'LIKE';
- }
- else
- {
- $op = '=';
- }
-
- if ($username == '') bb_die($lang['SEARCH_INVALID_USERNAME']);
-
- $total_sql .= "SELECT COUNT(user_id) AS total FROM ".BB_USERS." WHERE {$lower_b}username{$lower_e} $op '".DB()->escape($username)."' AND user_id <> ".GUEST_UID;
- $select_sql .= " WHERE {$lower_b}u.username{$lower_e} $op '".DB()->escape($username)."' AND u.user_id <> ".GUEST_UID;
- break;
-
- case 'search_email':
- $base_url .= '&search_email=true&email='.rawurlencode(stripslashes($email));
-
- $text = sprintf($lang['SEARCH_FOR_EMAIL'], strip_tags(htmlspecialchars(stripslashes($email))));
-
- $email = preg_replace('/\*/', '%', trim(strip_tags(strtolower($email))));
-
- if (strstr($email, '%'))
- {
- $op = 'LIKE';
- }
- else
- {
- $op = '=';
- }
-
- if ($email == '') bb_die($lang['SEARCH_INVALID_EMAIL']);
-
- $total_sql .= "SELECT COUNT(user_id) AS total FROM ".BB_USERS." WHERE {$lower_b}user_email{$lower_e} $op '".DB()->escape($email)."' AND user_id <> ".GUEST_UID;
- $select_sql .= " WHERE {$lower_b}u.user_email{$lower_e} $op '".DB()->escape($email)."' AND u.user_id <> ".GUEST_UID;
- break;
-
- case 'search_ip':
- $base_url .= '&search_ip=true&ip_address='.rawurlencode(stripslashes($ip_address));
-
- $ip_address = trim($ip_address);
-
- $text = sprintf($lang['SEARCH_FOR_IP'], strip_tags(htmlspecialchars(stripslashes($ip_address))));
-
- unset($users);
- $users = array();
-
- // Let's see if they entered a full valid IPv4 address
- if (preg_match('/^([0-9]{1,2}|[0-2][0-9]{0,2})(\.([0-9]{1,2}|[0-2][0-9]{0,2})){3}$/', $ip_address))
- {
- $ip = encode_ip($ip_address);
- $users[] = $ip;
- }
- elseif (preg_match('/^([0-9]{1,2}|[0-2][0-9]{0,2})(\.([0-9]{1,2}|[0-2][0-9]{0,2})){0,2}\.\*/', $ip_address))
- {
- $ip_split = explode('.', $ip_address);
- switch (count($ip_split))
- {
- case 4:
- $users[] = encode_ip($ip_split[0].".".$ip_split[1].".".$ip_split[2].".255");
- break;
- case 3:
- $users[] = encode_ip($ip_split[0].".".$ip_split[1].".255.255");
- break;
- case 2:
- $users[] = encode_ip($ip_split[0].".255.255.255");
- break;
- }
- }
- elseif (preg_match('/^([0-9]{1,2}|[0-2][0-9]{0,2})(\.([0-9]{1,2}|[0-2][0-9]{0,2})){3}(\s)*-(\s)*([0-9]{1,2}|[0-2][0-9]{0,2})(\.([0-9]{1,2}|[0-2][0-9]{0,2})){3}$/', $ip_address))
- {
- $range = preg_split('/[-\s]+/', $ip_address);
- $start_range = explode('.', $range[0]);
- $end_range = explode('.', $range[1]);
- if (($start_range[0].$start_range[1].$start_range[2] != $end_range[0].$end_range[1].$end_range[2]) || ($start_range[3] > $end_range[3])) bb_die($lang['SEARCH_INVALID_IP']);
- for ($i = $start_range[3]; $i <= $end_range[3]; $i++)
- {
- $users[] = encode_ip($start_range[0].".".$start_range[1 ].".".$start_range[2].".".$i);
- }
- }
- else
- {
- bb_die($lang['SEARCH_INVALID_IP']);
- }
-
- $ip_in_sql = $ip_like_sql = $ip_like_sql_flylast = $ip_like_sql_flyreg = '';
-
- foreach ($users as $address)
- {
- if (preg_match('/(ff){1,3}$/i', $address))
- {
- if (preg_match('/[0-9a-f]{2}ffffff/i', $address))
- {
- $ip_start = substr($address, 0, 2);
- }
- elseif (preg_match('/[0-9a-f]{4}ffff/i', $address))
- {
- $ip_start = substr($address, 0, 4);
- }
- elseif (preg_match('/[0-9a-f]{6}ff/i', $address))
- {
- $ip_start = substr($address, 0, 6);
- }
- $ip_like_sql_flylast = $ip_like_sql . ( $ip_like_sql != '' ) ? " OR user_last_ip LIKE '".$ip_start."%'" : "user_last_ip LIKE '".$ip_start."%'";
- $ip_like_sql_flyreg = $ip_like_sql . ( $ip_like_sql != '' ) ? " OR user_reg_ip LIKE '".$ip_start."%'" : "user_reg_ip LIKE '".$ip_start."%'";
- $ip_like_sql .= ( $ip_like_sql != '' ) ? " OR poster_ip LIKE '".$ip_start."%'" : "poster_ip LIKE '".$ip_start."%'";
- }
- else
- {
- $ip_in_sql .= ( $ip_in_sql == '' ) ? "'$address'" : ", '$address'";
- }
- }
-
- $where_sql = '';
- $where_sql .= ( $ip_in_sql != '' ) ? "poster_ip IN ($ip_in_sql)": "";
- $where_sql .= ( $ip_like_sql != '' ) ? ( $where_sql != "" ) ? " OR $ip_like_sql" : "$ip_like_sql": "";
-
- if (!$where_sql) bb_die('invalid request');
-
- // start search
- $no_result_search = false;
- $ip_users_sql = '';
- $sql = "SELECT poster_id FROM ".BB_POSTS." WHERE poster_id <> ".GUEST_UID." AND ($where_sql) GROUP BY poster_id";
-
- if (!$result = DB()->sql_query($sql))
- {
- bb_die('Could not count users #1');
- }
-
- if (DB()->num_rows($result) == 0)
- {
- $no_result_search = true;
- }
- else
- {
- $total_pages['total'] = DB()->num_rows($result);
- $total_sql = NULL;
- $ip_users_sql = '';
- while($row = DB()->sql_fetchrow($result))
- {
- $ip_users_sql .= ( $ip_users_sql == '' ) ? $row['poster_id'] : ', '.$row['poster_id'];
- }
- }
- $where_sql = '';
- $where_sql .= ( $ip_in_sql != '' ) ? "user_last_ip IN ($ip_in_sql)": "";
- $where_sql .= ( $ip_like_sql_flylast != '' ) ? ( $where_sql != "" ) ? " OR $ip_like_sql_flylast" : "$ip_like_sql_flylast": "";
- $sql = "SELECT user_id FROM ".BB_USERS." WHERE user_id <> ".GUEST_UID." AND ($where_sql) GROUP BY user_id";
- if (!$result = DB()->sql_query($sql))
- {
- bb_die('Could not count users #2');
- }
- if (DB()->num_rows($result) != 0)
- {
- if ($no_result_search == true) $no_result_search = false;
- $total_pages['total'] = DB()->num_rows($result);
- $total_sql = NULL;
- while ($row = DB()->sql_fetchrow($result))
- {
- $ip_users_sql .= ( $ip_users_sql == '' ) ? $row['user_id'] : ', '.$row['user_id'];
- }
- }
- $where_sql = '';
- $where_sql .= ( $ip_in_sql != '' ) ? "user_reg_ip IN ($ip_in_sql)": "";
- $where_sql .= ( $ip_like_sql_flyreg != '' ) ? ( $where_sql != "" ) ? " OR $ip_like_sql_flyreg" : "$ip_like_sql_flyreg": "";
- $sql = "SELECT user_id FROM ".BB_USERS." WHERE user_id <> ".GUEST_UID." AND ($where_sql) GROUP BY user_id";
- if (!$result = DB()->sql_query($sql))
- {
- bb_die('Could not count users #3');
- }
- if (DB()->num_rows($result) != 0)
- {
- if ($no_result_search == true) $no_result_search = false;
- $total_pages['total'] = DB()->num_rows($result);
- $total_sql = NULL;
- while ($row = DB()->sql_fetchrow($result))
- {
- $ip_users_sql .= ( $ip_users_sql == '' ) ? $row['user_id'] : ', '.$row['user_id'];
- }
- }
- if ($no_result_search == true)
- {
- bb_die($lang['SEARCH_NO_RESULTS']);
- }
-
- $select_sql .= " WHERE u.user_id IN ($ip_users_sql)";
- break;
-
- case 'search_joindate':
- $base_url .= '&search_joindate=true&date_type='. rawurlencode($date_type) .'&date_day='. rawurlencode($date_day) .'&date_month='. rawurlencode($date_month) .'&date_year='. rawurlencode(stripslashes($date_year));
-
- $date_type = trim(strtolower($date_type));
-
- if ($date_type != 'before' && $date_type != 'after')
- {
- bb_die($lang['SEARCH_INVALID_DATE']);
- }
-
- $date_day = intval($date_day);
-
- if (!preg_match('/^([1-9]|[0-2][0-9]|3[0-1])$/', $date_day))
- {
- bb_die($lang['SEARCH_INVALID_DAY']);
- }
-
- $date_month = intval($date_month);
-
- if (!preg_match('/^(0?[1-9]|1[0-2])$/', $date_month))
- {
- bb_die($lang['SEARCH_INVALID_MONTH']);
- }
-
- $date_year = intval($date_year);
-
- if (!preg_match('/^(20[0-9]{2}|19[0-9]{2})$/', $date_year))
- {
- bb_die($lang['SEARCH_INVALID_YEAR']);
- }
-
- $text = sprintf($lang['SEARCH_FOR_DATE'], strip_tags(htmlspecialchars(stripslashes($date_type))), $date_year, $date_month, $date_day);
-
- $time = mktime(0,0,0,$date_month, $date_day, $date_year);
-
- if ($date_type == 'before')
- {
- $arg = '<';
- }
- else
- {
- $arg = '>';
- }
-
- $total_sql .= "SELECT COUNT(user_id) AS total FROM ".BB_USERS." WHERE user_regdate $arg $time AND user_id <> ".GUEST_UID;
- $select_sql .= " WHERE u.user_regdate $arg $time AND u.user_id <> ".GUEST_UID;
- break;
-
- case 'search_group':
- $group_id = intval($group_id);
-
- $base_url .= '&search_group=true&group_id='. rawurlencode($group_id);
-
- if (!$group_id)
- {
- bb_die($lang['SEARCH_INVALID_GROUP']);
- }
-
- $sql = "SELECT group_name FROM ".BB_GROUPS." WHERE group_id = $group_id AND group_single_user = 0";
-
- if (!$result = DB()->sql_query($sql))
- {
- bb_die('Could not select group data #2');
- }
-
- if (DB()->num_rows($result)==0)
- {
- bb_die($lang['SEARCH_INVALID_GROUP']);
- }
-
- $group_name = DB()->sql_fetchrow($result);
-
- $text = sprintf($lang['SEARCH_FOR_GROUP'], strip_tags(htmlspecialchars($group_name['group_name'])));
-
- $total_sql .= "SELECT COUNT(u.user_id) AS total
- FROM ".BB_USERS." AS u, ".BB_USER_GROUP." AS ug
+ ORDER BY group_name ASC';
+
+ if (!$result = DB()->sql_query($sql)) {
+ bb_die('Could not select group data #1');
+ }
+
+ $group_list = '';
+
+ if (DB()->num_rows($result) != 0) {
+ $template->assign_block_vars('groups_exist', []);
+
+ while ($row = DB()->sql_fetchrow($result)) {
+ $group_list .= '' . strip_tags(htmlspecialchars($row['group_name'])) . ' ';
+ }
+ }
+
+ $sql = 'SELECT * FROM ' . BB_RANKS . ' ORDER BY rank_title';
+ if (!($result = DB()->sql_query($sql))) {
+ bb_die('Could not obtain ranks data');
+ }
+ $rank_select_box = '';
+ if (DB()->num_rows($result) != 0) {
+ $template->assign_block_vars('ranks_exist', []);
+ while ($row = DB()->sql_fetchrow($result)) {
+ $rank = $row['rank_title'];
+ $rank_id = $row['rank_id'];
+ $rank_select_box .= '' . $rank . ' ';
+ }
+ }
+
+ $language_list = \TorrentPier\Legacy\Common\Select::language('', 'language_type');
+ $timezone_list = \TorrentPier\Legacy\Common\Select::timezone('', 'timezone_type');
+
+ $sql = 'SELECT f.forum_id, f.forum_name, f.forum_parent, c.cat_id, c.cat_title
+ FROM ( ' . BB_FORUMS . ' AS f INNER JOIN ' . BB_CATEGORIES . ' AS c ON c.cat_id = f.cat_id )
+ ORDER BY c.cat_order, f.forum_order ASC';
+
+ if (!$result = DB()->sql_query($sql)) {
+ bb_die('Could not select forum data');
+ }
+
+ $forums = [];
+ $last_cat_id = -1;
+ $forums_list = '';
+
+ if (DB()->num_rows($result) != 0) {
+ $template->assign_block_vars('forums_exist', []);
+
+ while ($row = DB()->sql_fetchrow($result)) {
+ if ($row['cat_id'] != $last_cat_id) {
+ $forums_list .= '';
+ $last_cat_id = $row['cat_id'];
+ }
+
+ $forums_list .= '' . ($row['forum_parent'] ? HTML_SF_SPACER : '') . htmlCHR($row['forum_name']) . ' ';
+ }
+ }
+
+ $lastvisited = [1, 7, 14, 30, 60, 120, 365, 500, 730, 1000];
+ $lastvisited_list = '';
+
+ foreach ($lastvisited as $days) {
+ $lastvisited_list .= '' . delta_time((TIMENOW - 86400 * $days), TIMENOW, 'days') . ' ';
+ }
+
+ $template->assign_vars([
+ 'TPL_ADMIN_USER_SEARCH_MAIN' => true,
+
+ 'YEAR' => date('Y'),
+ 'MONTH' => date('m'),
+ 'DAY' => date('d'),
+ 'GROUP_LIST' => $group_list,
+ 'RANK_SELECT_BOX' => $rank_select_box,
+ 'LANGUAGE_LIST' => $language_list,
+ 'TIMEZONE_LIST' => $timezone_list,
+ 'FORUMS_LIST' => $forums_list,
+ 'LASTVISITED_LIST' => $lastvisited_list,
+
+ 'U_SEARCH_USER' => BB_ROOT . 'search.php?mode=searchuser',
+ 'S_SEARCH_ACTION' => 'admin_user_search.php'
+ ]);
+} else {
+ $mode = '';
+
+ // validate mode
+ if (isset($_REQUEST['search_username'])) {
+ $mode = 'search_username';
+ } elseif (isset($_REQUEST['search_email'])) {
+ $mode = 'search_email';
+ } elseif (isset($_REQUEST['search_ip'])) {
+ $mode = 'search_ip';
+ } elseif (isset($_REQUEST['search_joindate'])) {
+ $mode = 'search_joindate';
+ } elseif (isset($_REQUEST['search_group'])) {
+ $mode = 'search_group';
+ } elseif (isset($_REQUEST['search_rank'])) {
+ $mode = 'search_rank';
+ } elseif (isset($_REQUEST['search_postcount'])) {
+ $mode = 'search_postcount';
+ } elseif (isset($_REQUEST['search_userfield'])) {
+ $mode = 'search_userfield';
+ } elseif (isset($_REQUEST['search_lastvisited'])) {
+ $mode = 'search_lastvisited';
+ } elseif (isset($_REQUEST['search_language'])) {
+ $mode = 'search_language';
+ } elseif (isset($_REQUEST['search_timezone'])) {
+ $mode = 'search_timezone';
+ } elseif (isset($_REQUEST['search_moderators'])) {
+ $mode = 'search_moderators';
+ } elseif (isset($_REQUEST['search_misc'])) {
+ $mode = 'search_misc';
+ }
+
+ // validate fields (that they exist)
+ switch ($mode) {
+ case 'search_username':
+ $username = $_REQUEST['username'];
+ if (!$username) {
+ bb_die($lang['SEARCH_INVALID_USERNAME']);
+ }
+ break;
+
+ case 'search_email':
+ $email = $_REQUEST['email'];
+ if (!$email) {
+ bb_die($lang['SEARCH_INVALID_EMAIL']);
+ }
+ break;
+
+ case 'search_ip':
+ $ip_address = $_REQUEST['ip_address'];
+ if (!$ip_address) {
+ bb_die($lang['SEARCH_INVALID_IP']);
+ }
+ break;
+
+ case 'search_joindate':
+ $date_type = $_REQUEST['date_type'];
+ $date_day = $_REQUEST['date_day'];
+ $date_month = $_REQUEST['date_month'];
+ $date_year = $_REQUEST['date_year'];
+ if (!($date_type || $date_day || $date_month || $date_year)) {
+ bb_die($lang['SEARCH_INVALID_DATE']);
+ }
+ break;
+
+ case 'search_group':
+ $group_id = $_REQUEST['group_id'];
+ if (!$group_id) {
+ bb_die($lang['SEARCH_INVALID_GROUP']);
+ }
+ break;
+
+ case 'search_rank':
+ $rank_id = $_REQUEST['rank_id'];
+ if (!$rank_id) {
+ bb_die($lang['SEARCH_INVALID_RANK']);
+ }
+ break;
+
+ case 'search_postcount':
+ $postcount_type = $_REQUEST['postcount_type'];
+ $postcount_value = $_REQUEST['postcount_value'];
+ if (!$postcount_type || (!$postcount_value && $postcount_value != 0)) {
+ bb_die($lang['SEARCH_INVALID_POSTCOUNT']);
+ }
+ break;
+
+ case 'search_userfield':
+ $userfield_type = $_REQUEST['userfield_type'];
+ $userfield_value = $_REQUEST['userfield_value'];
+ if (!$userfield_type || !$userfield_value) {
+ bb_die($lang['SEARCH_INVALID_USERFIELD']);
+ }
+ break;
+
+ case 'search_lastvisited':
+ $lastvisited_days = $_REQUEST['lastvisited_days'];
+ $lastvisited_type = $_REQUEST['lastvisited_type'];
+ if (!$lastvisited_days || !$lastvisited_type) {
+ bb_die($lang['SEARCH_INVALID_LASTVISITED']);
+ }
+ break;
+
+ case 'search_language':
+ $language_type = $_REQUEST['language_type'];
+ if (!$language_type) {
+ bb_die($lang['SEARCH_INVALID_LANGUAGE']);
+ }
+ break;
+
+ case 'search_timezone':
+ $timezone_type = $_REQUEST['timezone_type'];
+ if (!$timezone_type && $timezone_type != 0) {
+ bb_die($lang['SEARCH_INVALID_TIMEZONE']);
+ }
+ break;
+
+ case 'search_moderators':
+ $moderators_forum = $_REQUEST['moderators_forum'];
+ if (!$moderators_forum) {
+ bb_die($lang['SEARCH_INVALID_MODERATORS']);
+ }
+ break;
+
+ case 'search_misc':
+ $misc = $_REQUEST['misc'];
+ if (!$misc) {
+ bb_die($lang['SEARCH_INVALID']);
+ }
+ break;
+
+ default:
+ bb_die('Invalid mode');
+ }
+
+ $base_url = 'admin_user_search.php?dosearch=true';
+
+ $select_sql = 'SELECT u.user_id, u.username, u.user_rank, u.user_email, u.user_posts, u.user_regdate, u.user_level, u.user_active, u.user_lastvisit FROM ' . BB_USERS . ' AS u';
+
+ $lower_b = 'LOWER(';
+ $lower_e = ')';
+
+ // validate data & prepare sql
+ switch ($mode) {
+ case 'search_username':
+ $base_url .= '&search_username=true&username=' . rawurlencode(stripslashes($username));
+
+ $text = sprintf($lang['SEARCH_FOR_USERNAME'], strip_tags(htmlspecialchars(stripslashes($username))));
+
+ $username = str_replace('*', '%', trim(strip_tags(strtolower($username))));
+ if (str_contains($username, '%')) {
+ $op = 'LIKE';
+ } else {
+ $op = '=';
+ }
+
+ if ($username == '') {
+ bb_die($lang['SEARCH_INVALID_USERNAME']);
+ }
+
+ $total_sql .= 'SELECT COUNT(user_id) AS total FROM ' . BB_USERS . " WHERE {$lower_b}username{$lower_e} $op '" . DB()->escape($username) . "' AND user_id <> " . GUEST_UID;
+ $select_sql .= " WHERE {$lower_b}u.username{$lower_e} $op '" . DB()->escape($username) . "' AND u.user_id <> " . GUEST_UID;
+ break;
+
+ case 'search_email':
+ $base_url .= '&search_email=true&email=' . rawurlencode(stripslashes($email));
+
+ $text = sprintf($lang['SEARCH_FOR_EMAIL'], strip_tags(htmlspecialchars(stripslashes($email))));
+
+ $email = str_replace('*', '%', trim(strip_tags(strtolower($email))));
+ if (str_contains($email, '%')) {
+ $op = 'LIKE';
+ } else {
+ $op = '=';
+ }
+
+ if ($email == '') {
+ bb_die($lang['SEARCH_INVALID_EMAIL']);
+ }
+
+ $total_sql .= 'SELECT COUNT(user_id) AS total FROM ' . BB_USERS . " WHERE {$lower_b}user_email{$lower_e} $op '" . DB()->escape($email) . "' AND user_id <> " . GUEST_UID;
+ $select_sql .= " WHERE {$lower_b}u.user_email{$lower_e} $op '" . DB()->escape($email) . "' AND u.user_id <> " . GUEST_UID;
+ break;
+
+ case 'search_ip':
+ $base_url .= '&search_ip=true&ip_address=' . rawurlencode(stripslashes($ip_address));
+
+ $ip_address = trim($ip_address);
+
+ $text = sprintf($lang['SEARCH_FOR_IP'], strip_tags(htmlspecialchars(stripslashes($ip_address))));
+
+ unset($users);
+ $users = [];
+
+ if (\TorrentPier\Helpers\IPHelper::isValid($ip_address)) {
+ $ip = \TorrentPier\Helpers\IPHelper::ip2long($ip_address);
+ $users[] = $ip;
+ } else {
+ bb_die($lang['SEARCH_INVALID_IP']);
+ }
+
+ $ip_in_sql = $ip_like_sql = $ip_like_sql_flylast = $ip_like_sql_flyreg = '';
+
+ foreach ($users as $address) {
+ $ip_in_sql .= ($ip_in_sql == '') ? "'$address'" : ", '$address'";
+ }
+
+ $where_sql = '';
+ $where_sql .= ($ip_in_sql != '') ? "poster_ip IN ($ip_in_sql)" : '';
+ $where_sql .= ($ip_like_sql != '') ? ($where_sql != '') ? " OR $ip_like_sql" : (string)$ip_like_sql : '';
+
+ if (!$where_sql) {
+ bb_die('invalid request');
+ }
+
+ // start search
+ $no_result_search = false;
+ $ip_users_sql = '';
+ $sql = 'SELECT poster_id FROM ' . BB_POSTS . ' WHERE poster_id <> ' . GUEST_UID . " AND ($where_sql) GROUP BY poster_id";
+
+ if (!$result = DB()->sql_query($sql)) {
+ bb_die('Could not count users #1');
+ }
+
+ if (DB()->num_rows($result) == 0) {
+ $no_result_search = true;
+ } else {
+ $total_pages['total'] = DB()->num_rows($result);
+ $total_sql = null;
+ $ip_users_sql = '';
+ while ($row = DB()->sql_fetchrow($result)) {
+ $ip_users_sql .= ($ip_users_sql == '') ? $row['poster_id'] : ', ' . $row['poster_id'];
+ }
+ }
+ $where_sql = '';
+ $where_sql .= ($ip_in_sql != '') ? "user_last_ip IN ($ip_in_sql)" : '';
+ $where_sql .= ($ip_like_sql_flylast != '') ? ($where_sql != '') ? " OR $ip_like_sql_flylast" : (string)$ip_like_sql_flylast : '';
+ $sql = 'SELECT user_id FROM ' . BB_USERS . ' WHERE user_id <> ' . GUEST_UID . " AND ($where_sql) GROUP BY user_id";
+ if (!$result = DB()->sql_query($sql)) {
+ bb_die('Could not count users #2');
+ }
+ if (DB()->num_rows($result) != 0) {
+ if ($no_result_search == true) {
+ $no_result_search = false;
+ }
+ $total_pages['total'] = DB()->num_rows($result);
+ $total_sql = null;
+ while ($row = DB()->sql_fetchrow($result)) {
+ $ip_users_sql .= ($ip_users_sql == '') ? $row['user_id'] : ', ' . $row['user_id'];
+ }
+ }
+ $where_sql = '';
+ $where_sql .= ($ip_in_sql != '') ? "user_reg_ip IN ($ip_in_sql)" : '';
+ $where_sql .= ($ip_like_sql_flyreg != '') ? ($where_sql != '') ? " OR $ip_like_sql_flyreg" : (string)$ip_like_sql_flyreg : '';
+ $sql = 'SELECT user_id FROM ' . BB_USERS . ' WHERE user_id <> ' . GUEST_UID . " AND ($where_sql) GROUP BY user_id";
+ if (!$result = DB()->sql_query($sql)) {
+ bb_die('Could not count users #3');
+ }
+ if (DB()->num_rows($result) != 0) {
+ if ($no_result_search == true) {
+ $no_result_search = false;
+ }
+ $total_pages['total'] = DB()->num_rows($result);
+ $total_sql = null;
+ while ($row = DB()->sql_fetchrow($result)) {
+ $ip_users_sql .= ($ip_users_sql == '') ? $row['user_id'] : ', ' . $row['user_id'];
+ }
+ }
+ if ($no_result_search == true) {
+ bb_die($lang['SEARCH_NO_RESULTS']);
+ }
+
+ $select_sql .= " WHERE u.user_id IN ($ip_users_sql)";
+ break;
+
+ case 'search_joindate':
+ $base_url .= '&search_joindate=true&date_type=' . rawurlencode($date_type) . '&date_day=' . rawurlencode($date_day) . '&date_month=' . rawurlencode($date_month) . '&date_year=' . rawurlencode(stripslashes($date_year));
+
+ $date_type = strtolower(trim($date_type));
+
+ if ($date_type != 'before' && $date_type != 'after') {
+ bb_die($lang['SEARCH_INVALID_DATE']);
+ }
+
+ $date_day = (int)$date_day;
+
+ if (!preg_match('/^([1-9]|[0-2][0-9]|3[0-1])$/', $date_day)) {
+ bb_die($lang['SEARCH_INVALID_DAY']);
+ }
+
+ $date_month = (int)$date_month;
+
+ if (!preg_match('/^(0?[1-9]|1[0-2])$/', $date_month)) {
+ bb_die($lang['SEARCH_INVALID_MONTH']);
+ }
+
+ $date_year = (int)$date_year;
+
+ if (!preg_match('/^(20[0-9]{2}|19[0-9]{2})$/', $date_year)) {
+ bb_die($lang['SEARCH_INVALID_YEAR']);
+ }
+
+ $text = sprintf($lang['SEARCH_FOR_DATE'], strip_tags(htmlspecialchars(stripslashes($date_type))), $date_year, $date_month, $date_day);
+
+ $time = mktime(0, 0, 0, $date_month, $date_day, $date_year);
+
+ if ($date_type == 'before') {
+ $arg = '<';
+ } else {
+ $arg = '>';
+ }
+
+ $total_sql .= 'SELECT COUNT(user_id) AS total FROM ' . BB_USERS . " WHERE user_regdate $arg $time AND user_id <> " . GUEST_UID;
+ $select_sql .= " WHERE u.user_regdate $arg $time AND u.user_id <> " . GUEST_UID;
+ break;
+
+ case 'search_group':
+ $group_id = (int)$group_id;
+
+ $base_url .= '&search_group=true&group_id=' . rawurlencode($group_id);
+
+ if (!$group_id) {
+ bb_die($lang['SEARCH_INVALID_GROUP']);
+ }
+
+ $sql = 'SELECT group_name FROM ' . BB_GROUPS . " WHERE group_id = $group_id AND group_single_user = 0";
+
+ if (!$result = DB()->sql_query($sql)) {
+ bb_die('Could not select group data #2');
+ }
+
+ if (DB()->num_rows($result) == 0) {
+ bb_die($lang['SEARCH_INVALID_GROUP']);
+ }
+
+ $group_name = DB()->sql_fetchrow($result);
+
+ $text = sprintf($lang['SEARCH_FOR_GROUP'], strip_tags(htmlspecialchars($group_name['group_name'])));
+
+ $total_sql .= 'SELECT COUNT(u.user_id) AS total
+ FROM ' . BB_USERS . ' AS u, ' . BB_USER_GROUP . " AS ug
WHERE u.user_id = ug.user_id
AND ug.group_id = $group_id
- AND u.user_id <> ".GUEST_UID;
+ AND u.user_id <> " . GUEST_UID;
- $select_sql .= ", ".BB_USER_GROUP." AS ug
+ $select_sql .= ', ' . BB_USER_GROUP . " AS ug
WHERE u.user_id = ug.user_id
AND ug.group_id = $group_id
- AND u.user_id <> ".GUEST_UID;
- break;
+ AND u.user_id <> " . GUEST_UID;
+ break;
- case 'search_rank':
- $rank_id = intval($rank_id);
+ case 'search_rank':
+ $rank_id = (int)$rank_id;
- $base_url .= '&search_rank=true&rank_id='. rawurlencode($rank_id);
+ $base_url .= '&search_rank=true&rank_id=' . rawurlencode($rank_id);
- if (!$rank_id)
- {
- bb_die($lang['SEARCH_INVALID_RANK']);
- }
+ if (!$rank_id) {
+ bb_die($lang['SEARCH_INVALID_RANK']);
+ }
- $sql = "SELECT rank_title FROM ".BB_RANKS." WHERE rank_id = $rank_id AND rank_special = 1";
+ $sql = 'SELECT rank_title FROM ' . BB_RANKS . " WHERE rank_id = $rank_id";
- if (!$result = DB()->sql_query($sql))
- {
- bb_die('Could not select rank data');
- }
+ if (!$result = DB()->sql_query($sql)) {
+ bb_die('Could not select rank data');
+ }
- if (DB()->num_rows($result)==0)
- {
- bb_die($lang['SEARCH_INVALID_RANK']);
- }
+ if (DB()->num_rows($result) == 0) {
+ bb_die($lang['SEARCH_INVALID_RANK']);
+ }
- $rank_title = DB()->sql_fetchrow($result);
+ $rank_title = DB()->sql_fetchrow($result);
- $text = sprintf($lang['SEARCH_FOR_RANK'], strip_tags(htmlspecialchars($rank_title['rank_title'])));
+ $text = sprintf($lang['SEARCH_FOR_RANK'], strip_tags(htmlspecialchars($rank_title['rank_title'])));
- $total_sql .= "SELECT COUNT(user_id) AS total
- FROM ".BB_USERS."
+ $total_sql .= 'SELECT COUNT(user_id) AS total
+ FROM ' . BB_USERS . "
WHERE user_rank = $rank_id
- AND user_id <> ".GUEST_UID;
+ AND user_id <> " . GUEST_UID;
- $select_sql .= " WHERE u.user_rank = $rank_id
- AND u.user_id <> ".GUEST_UID;
- break;
+ $select_sql .= " WHERE u.user_rank = $rank_id
+ AND u.user_id <> " . GUEST_UID;
+ break;
- case 'search_postcount':
- $postcount_type = trim(strtolower($postcount_type));
- $postcount_value = trim(strtolower($postcount_value));
+ case 'search_postcount':
+ $postcount_type = strtolower(trim($postcount_type));
+ $postcount_value = strtolower(trim($postcount_value));
- $base_url .= '&search_postcount=true&postcount_type='. rawurlencode($postcount_type) .'&postcount_value='. rawurlencode(stripslashes($postcount_value));
+ $base_url .= '&search_postcount=true&postcount_type=' . rawurlencode($postcount_type) . '&postcount_value=' . rawurlencode(stripslashes($postcount_value));
- switch($postcount_type)
- {
- case 'greater':
- $postcount_value = intval($postcount_value);
+ switch ($postcount_type) {
+ case 'greater':
+ $postcount_value = (int)$postcount_value;
- $text = sprintf($lang['SEARCH_FOR_POSTCOUNT_GREATER'], $postcount_value);
+ $text = sprintf($lang['SEARCH_FOR_POSTCOUNT_GREATER'], $postcount_value);
- $total_sql .= "SELECT COUNT(user_id) AS total
- FROM ".BB_USERS."
+ $total_sql .= 'SELECT COUNT(user_id) AS total
+ FROM ' . BB_USERS . "
WHERE user_posts > $postcount_value
- AND user_id <> ".GUEST_UID;
+ AND user_id <> " . GUEST_UID;
- $select_sql .= " WHERE u.user_posts > $postcount_value
- AND u.user_id <> ".GUEST_UID;
- break;
- case 'lesser':
- $postcount_value = intval($postcount_value);
+ $select_sql .= " WHERE u.user_posts > $postcount_value
+ AND u.user_id <> " . GUEST_UID;
+ break;
+ case 'lesser':
+ $postcount_value = (int)$postcount_value;
- $text = sprintf($lang['SEARCH_FOR_POSTCOUNT_LESSER'], $postcount_value);
+ $text = sprintf($lang['SEARCH_FOR_POSTCOUNT_LESSER'], $postcount_value);
- $total_sql .= "SELECT COUNT(user_id) AS total
- FROM ".BB_USERS."
+ $total_sql .= 'SELECT COUNT(user_id) AS total
+ FROM ' . BB_USERS . "
WHERE user_posts < $postcount_value
- AND user_id <> ".GUEST_UID;
+ AND user_id <> " . GUEST_UID;
- $select_sql .= " WHERE u.user_posts < $postcount_value
- AND u.user_id <> ".GUEST_UID;
- break;
- case 'equals':
- // looking for a -
- if (strstr($postcount_value, '-'))
- {
- $range = preg_split('/[-\s]+/', $postcount_value);
+ $select_sql .= " WHERE u.user_posts < $postcount_value
+ AND u.user_id <> " . GUEST_UID;
+ break;
+ case 'equals':
+ // looking for a -
+ if (str_contains($postcount_value, '-')) {
+ $range = preg_split('/[-\s]+/', $postcount_value);
- $range_begin = intval($range[0]);
- $range_end = intval($range[1]);
+ $range_begin = (int)$range[0];
+ $range_end = (int)$range[1];
- if ($range_begin > $range_end)
- {
- bb_die($lang['SEARCH_INVALID_POSTCOUNT']);
- }
+ if ($range_begin > $range_end) {
+ bb_die($lang['SEARCH_INVALID_POSTCOUNT']);
+ }
- $text = sprintf($lang['SEARCH_FOR_POSTCOUNT_RANGE'], $range_begin, $range_end);
+ $text = sprintf($lang['SEARCH_FOR_POSTCOUNT_RANGE'], $range_begin, $range_end);
- $total_sql .= "SELECT COUNT(user_id) AS total
- FROM ".BB_USERS."
+ $total_sql .= 'SELECT COUNT(user_id) AS total
+ FROM ' . BB_USERS . "
WHERE user_posts >= $range_begin
AND user_posts <= $range_end
- AND user_id <> ".GUEST_UID;
+ AND user_id <> " . GUEST_UID;
- $select_sql .= " WHERE u.user_posts >= $range_begin
+ $select_sql .= " WHERE u.user_posts >= $range_begin
AND u.user_posts <= $range_end
- AND u.user_id <> ".GUEST_UID;
- }
- else
- {
- $postcount_value = intval($postcount_value);
+ AND u.user_id <> " . GUEST_UID;
+ } else {
+ $postcount_value = (int)$postcount_value;
- $text = sprintf($lang['SEARCH_FOR_POSTCOUNT_EQUALS'], $postcount_value);
+ $text = sprintf($lang['SEARCH_FOR_POSTCOUNT_EQUALS'], $postcount_value);
- $total_sql .= "SELECT COUNT(user_id) AS total
- FROM ".BB_USERS."
+ $total_sql .= 'SELECT COUNT(user_id) AS total
+ FROM ' . BB_USERS . "
WHERE user_posts = $postcount_value
- AND user_id <> ".GUEST_UID;
+ AND user_id <> " . GUEST_UID;
- $select_sql .= " WHERE u.user_posts = $postcount_value
- AND u.user_id <> ".GUEST_UID;
- }
- break;
- default:
- bb_die($lang['SEARCH_INVALID']);
- }
- break;
+ $select_sql .= " WHERE u.user_posts = $postcount_value
+ AND u.user_id <> " . GUEST_UID;
+ }
+ break;
+ default:
+ bb_die($lang['SEARCH_INVALID']);
+ }
+ break;
- case 'search_userfield':
- $base_url .= '&search_userfield=true&userfield_type='. rawurlencode($userfield_type) .'&userfield_value='. rawurlencode(stripslashes($userfield_value));
+ case 'search_userfield':
+ $base_url .= '&search_userfield=true&userfield_type=' . rawurlencode($userfield_type) . '&userfield_value=' . rawurlencode(stripslashes($userfield_value));
- $text = strip_tags(htmlspecialchars(stripslashes($userfield_value)));
+ $text = strip_tags(htmlspecialchars(stripslashes($userfield_value)));
- $userfield_value = preg_replace('/\*/', '%', trim(strip_tags(strtolower($userfield_value))));
+ $userfield_value = str_replace('*', '%', trim(strip_tags(strtolower($userfield_value))));
+ if (str_contains($userfield_value, '%')) {
+ $op = 'LIKE';
+ } else {
+ $op = '=';
+ }
- if (strstr($userfield_value, '%'))
- {
- $op = 'LIKE';
- }
- else
- {
- $op = '=';
- }
+ if ($userfield_value == '') {
+ bb_die($lang['SEARCH_INVALID_USERFIELD']);
+ }
- if ($userfield_value == '') bb_die($lang['SEARCH_INVALID_USERFIELD']);
+ $userfield_type = strtolower(trim($userfield_type));
- $userfield_type = trim(strtolower($userfield_type));
+ switch ($userfield_type) {
+ case 'icq':
+ $text = sprintf($lang['SEARCH_FOR_USERFIELD_ICQ'], $text);
+ $field = 'user_icq';
+ break;
+ case 'skype':
+ $text = sprintf($lang['SEARCH_FOR_USERFIELD_SKYPE'], $text);
+ $field = 'user_skype';
+ break;
+ case 'twitter':
+ $text = sprintf($lang['SEARCH_FOR_USERFIELD_TWITTER'], $text);
+ $field = 'user_twitter';
+ break;
+ case 'website':
+ $text = sprintf($lang['SEARCH_FOR_USERFIELD_WEBSITE'], $text);
+ $field = 'user_website';
+ break;
+ case 'location':
+ $text = sprintf($lang['SEARCH_FOR_USERFIELD_LOCATION'], $text);
+ $field = 'user_from';
+ break;
+ case 'interests':
+ $text = sprintf($lang['SEARCH_FOR_USERFIELD_INTERESTS'], $text);
+ $field = 'user_interests';
+ break;
+ case 'occupation':
+ $text = sprintf($lang['SEARCH_FOR_USERFIELD_OCCUPATION'], $text);
+ $field = 'user_occ';
+ break;
+ default:
+ bb_die($lang['SEARCH_INVALID']);
+ }
- switch ($userfield_type)
- {
- case 'icq':
- $text = sprintf($lang['SEARCH_FOR_USERFIELD_ICQ'],$text);
- $field = 'user_icq';
- break;
- case 'skype':
- $text = sprintf($lang['SEARCH_FOR_USERFIELD_SKYPE'],$text);
- $field = 'user_skype';
- break;
- case 'twitter':
- $text = sprintf($lang['SEARCH_FOR_USERFIELD_TWITTER'],$text);
- $field = 'user_twitter';
- break;
- case 'website':
- $text = sprintf($lang['SEARCH_FOR_USERFIELD_WEBSITE'],$text);
- $field = 'user_website';
- break;
- case 'location':
- $text = sprintf($lang['SEARCH_FOR_USERFIELD_LOCATION'],$text);
- $field = 'user_from';
- break;
- case 'interests':
- $text = sprintf($lang['SEARCH_FOR_USERFIELD_INTERESTS'],$text);
- $field = 'user_interests';
- break;
- case 'occupation':
- $text = sprintf($lang['SEARCH_FOR_USERFIELD_OCCUPATION'],$text);
- $field = 'user_occ';
- break;
- default:
- bb_die( $lang['SEARCH_INVALID']);
- }
+ $total_sql .= 'SELECT COUNT(user_id) AS total
+ FROM ' . BB_USERS . "
+ WHERE {$lower_b}$field{$lower_e} $op '" . DB()->escape($userfield_value) . "'
+ AND user_id <> " . GUEST_UID;
- $total_sql .= "SELECT COUNT(user_id) AS total
- FROM ".BB_USERS."
- WHERE {$lower_b}$field{$lower_e} $op '".DB()->escape($userfield_value)."'
- AND user_id <> ".GUEST_UID;
+ $select_sql .= " WHERE {$lower_b}u.$field{$lower_e} $op '" . DB()->escape($userfield_value) . "'
+ AND u.user_id <> " . GUEST_UID;
+ break;
- $select_sql .= " WHERE {$lower_b}u.$field{$lower_e} $op '".DB()->escape($userfield_value)."'
- AND u.user_id <> ".GUEST_UID;
- break;
+ case 'search_lastvisited':
+ $lastvisited_type = strtolower(trim($lastvisited_type));
+ $lastvisited_days = (int)$lastvisited_days;
- case 'search_lastvisited':
- $lastvisited_type = trim(strtolower($lastvisited_type));
- $lastvisited_days = intval($lastvisited_days);
+ $base_url .= '&search_lastvisited=true&lastvisited_type=' . rawurlencode(stripslashes($lastvisited_type)) . '&lastvisited_days=' . rawurlencode($lastvisited_days);
- $base_url .= '&search_lastvisited=true&lastvisited_type='. rawurlencode(stripslashes($lastvisited_type)) .'&lastvisited_days='. rawurlencode($lastvisited_days);
+ $lastvisited_seconds = (TIMENOW - ((($lastvisited_days * 24) * 60) * 60));
- $lastvisited_seconds = ( TIMENOW - ( ( ( $lastvisited_days * 24 ) * 60 ) * 60 ) );
+ switch ($lastvisited_type) {
+ case 'in':
+ $text = sprintf($lang['SEARCH_FOR_LASTVISITED_INTHELAST'], delta_time((TIMENOW - 86400 * $lastvisited_days), TIMENOW, 'days'));
- switch($lastvisited_type)
- {
- case 'in':
- $text = sprintf($lang['SEARCH_FOR_LASTVISITED_INTHELAST'], $lastvisited_days, ( ( $lastvisited_days > 1 ) ? $lang['DAYS'] : $lang['DAY'] ) );
-
- $total_sql .= "SELECT COUNT(user_id) AS total
- FROM ".BB_USERS."
+ $total_sql .= 'SELECT COUNT(user_id) AS total
+ FROM ' . BB_USERS . "
WHERE user_lastvisit >= $lastvisited_seconds
- AND user_id <> ".GUEST_UID;
+ AND user_id <> " . GUEST_UID;
- $select_sql .= " WHERE u.user_lastvisit >= $lastvisited_seconds
- AND u.user_id <> ".GUEST_UID;
- break;
- case 'after':
- $text = sprintf($lang['SEARCH_FOR_LASTVISITED_AFTERTHELAST'], $lastvisited_days, ( ( $lastvisited_days > 1 ) ? $lang['DAYS'] : $lang['DAY'] ));
+ $select_sql .= " WHERE u.user_lastvisit >= $lastvisited_seconds
+ AND u.user_id <> " . GUEST_UID;
+ break;
+ case 'after':
+ $text = sprintf($lang['SEARCH_FOR_LASTVISITED_AFTERTHELAST'], delta_time((TIMENOW - 86400 * $lastvisited_days), TIMENOW, 'days'));
- $total_sql .= "SELECT COUNT(user_id) AS total
- FROM ".BB_USERS."
+ $total_sql .= 'SELECT COUNT(user_id) AS total
+ FROM ' . BB_USERS . "
WHERE user_lastvisit < $lastvisited_seconds
- AND user_id <> ".GUEST_UID;
+ AND user_id <> " . GUEST_UID;
- $select_sql .= " WHERE u.user_lastvisit < $lastvisited_seconds
- AND u.user_id <> ".GUEST_UID;
+ $select_sql .= " WHERE u.user_lastvisit < $lastvisited_seconds
+ AND u.user_id <> " . GUEST_UID;
- break;
- default:
- bb_die($lang['SEARCH_INVALID_LASTVISITED']);
- }
- break;
+ break;
+ default:
+ bb_die($lang['SEARCH_INVALID_LASTVISITED']);
+ }
+ break;
- case 'search_language':
- $base_url .= '&search_language=true&language_type='. rawurlencode(stripslashes($language_type));
+ case 'search_language':
+ $base_url .= '&search_language=true&language_type=' . rawurlencode(stripslashes($language_type));
- $language_type = trim(strtolower(stripslashes($language_type)));
+ $language_type = strtolower(trim(stripslashes($language_type)));
- if ($language_type == '')
- {
- bb_die($lang['SEARCH_INVALID_LANGUAGE']);
- }
+ if ($language_type == '') {
+ bb_die($lang['SEARCH_INVALID_LANGUAGE']);
+ }
- $text = sprintf($lang['SEARCH_FOR_LANGUAGE'], strip_tags(htmlspecialchars($language_type)));
+ $text = sprintf($lang['SEARCH_FOR_LANGUAGE'], strip_tags(htmlspecialchars($language_type)));
- $total_sql .= "SELECT COUNT(user_id) AS total
- FROM ".BB_USERS."
- WHERE user_lang = '".DB()->escape($language_type)."'
- AND user_id <> ".GUEST_UID;
+ $total_sql .= 'SELECT COUNT(user_id) AS total
+ FROM ' . BB_USERS . "
+ WHERE user_lang = '" . DB()->escape($language_type) . "'
+ AND user_id <> " . GUEST_UID;
- $select_sql .= " WHERE u.user_lang = '".DB()->escape($language_type)."'
- AND u.user_id <> ".GUEST_UID;
- break;
+ $select_sql .= " WHERE u.user_lang = '" . DB()->escape($language_type) . "'
+ AND u.user_id <> " . GUEST_UID;
+ break;
- case 'search_timezone':
- $base_url .= '&search_timezone=true&timezone_type='. rawurlencode(stripslashes($timezone_type));
- $text = sprintf($lang['SEARCH_FOR_TIMEZONE'], strip_tags(htmlspecialchars(stripslashes($timezone_type))));
+ case 'search_timezone':
+ $base_url .= '&search_timezone=true&timezone_type=' . rawurlencode(stripslashes($timezone_type));
+ $text = sprintf($lang['SEARCH_FOR_TIMEZONE'], strip_tags(htmlspecialchars(stripslashes($timezone_type))));
- $timezone_type = intval($timezone_type);
+ $timezone_type = (int)$timezone_type;
- $total_sql .= "SELECT COUNT(user_id) AS total
- FROM ".BB_USERS."
+ $total_sql .= 'SELECT COUNT(user_id) AS total
+ FROM ' . BB_USERS . "
WHERE user_timezone = $timezone_type
- AND user_id <> ".GUEST_UID;
+ AND user_id <> " . GUEST_UID;
- $select_sql .= " WHERE u.user_timezone = $timezone_type
- AND u.user_id <> ".GUEST_UID;
- break;
+ $select_sql .= " WHERE u.user_timezone = $timezone_type
+ AND u.user_id <> " . GUEST_UID;
+ break;
- case 'search_moderators':
- $base_url .= '&search_moderators=true&moderators_forum='. rawurlencode(stripslashes($moderators_forum));
- $moderators_forum = intval($moderators_forum);
+ case 'search_moderators':
+ $base_url .= '&search_moderators=true&moderators_forum=' . rawurlencode(stripslashes($moderators_forum));
+ $moderators_forum = (int)$moderators_forum;
- $sql = "SELECT forum_name FROM ".BB_FORUMS." WHERE forum_id = ".$moderators_forum;
+ $sql = 'SELECT forum_name FROM ' . BB_FORUMS . ' WHERE forum_id = ' . $moderators_forum;
- if (!$result = DB()->sql_query($sql))
- {
- bb_die('Could not select forum data');
- }
+ if (!$result = DB()->sql_query($sql)) {
+ bb_die('Could not select forum data');
+ }
- if (DB()->num_rows($result)==0)
- {
- bb_die($lang['SEARCH_INVALID_MODERATORS']);
- }
+ if (DB()->num_rows($result) == 0) {
+ bb_die($lang['SEARCH_INVALID_MODERATORS']);
+ }
- $forum_name = DB()->sql_fetchrow($result);
+ $forum_name = DB()->sql_fetchrow($result);
- $text = sprintf($lang['SEARCH_FOR_MODERATORS'], htmlCHR($forum_name['forum_name']));
+ $text = sprintf($lang['SEARCH_FOR_MODERATORS'], htmlCHR($forum_name['forum_name']));
- $total_sql .= "SELECT COUNT(DISTINCT u.user_id) AS total
- FROM ".BB_USERS." AS u, ".BB_GROUPS." AS g, ".BB_USER_GROUP." AS ug, ".BB_AUTH_ACCESS." AS aa
+ $total_sql .= 'SELECT COUNT(DISTINCT u.user_id) AS total
+ FROM ' . BB_USERS . ' AS u, ' . BB_GROUPS . ' AS g, ' . BB_USER_GROUP . ' AS ug, ' . BB_AUTH_ACCESS . ' AS aa
WHERE u.user_id = ug.user_id
AND ug.group_id = g.group_id
AND g.group_id = aa.group_id
- AND aa.forum_id = ". $moderators_forum ."
- AND aa.forum_perm & ". BF_AUTH_MOD ."
- AND u.user_id <> ".GUEST_UID;
+ AND aa.forum_id = ' . $moderators_forum . '
+ AND aa.forum_perm & ' . BF_AUTH_MOD . '
+ AND u.user_id <> ' . GUEST_UID;
- $select_sql .= ", ".BB_GROUPS." AS g, ".BB_USER_GROUP." AS ug, ".BB_AUTH_ACCESS." AS aa
+ $select_sql .= ', ' . BB_GROUPS . ' AS g, ' . BB_USER_GROUP . ' AS ug, ' . BB_AUTH_ACCESS . ' AS aa
WHERE u.user_id = ug.user_id
AND ug.group_id = g.group_id
AND g.group_id = aa.group_id
- AND aa.forum_id = ". $moderators_forum ."
- AND aa.forum_perm & ". BF_AUTH_MOD ."
- AND u.user_id <> ".GUEST_UID."
- GROUP BY u.user_id, u.username, u.user_email, u.user_posts, u.user_regdate, u.user_level, u.user_active, u.user_lastvisit";
- break;
+ AND aa.forum_id = ' . $moderators_forum . '
+ AND aa.forum_perm & ' . BF_AUTH_MOD . '
+ AND u.user_id <> ' . GUEST_UID . '
+ GROUP BY u.user_id, u.username, u.user_email, u.user_posts, u.user_regdate, u.user_level, u.user_active, u.user_lastvisit';
+ break;
- case 'search_misc':
- default:
- $misc = trim(strtolower($misc));
+ case 'search_misc':
+ default:
+ $misc = strtolower(trim($misc));
- $base_url .= '&search_misc=true&misc='. rawurlencode(stripslashes($misc));
+ $base_url .= '&search_misc=true&misc=' . rawurlencode(stripslashes($misc));
- switch ($misc)
- {
- case 'admins':
- $text = $lang['SEARCH_FOR_ADMINS'];
+ switch ($misc) {
+ case 'admins':
+ $text = $lang['SEARCH_FOR_ADMINS'];
- $total_sql .= "SELECT COUNT(user_id) AS total
- FROM ".BB_USERS."
- WHERE user_level = ".ADMIN."
- AND user_id <> ".GUEST_UID;
+ $total_sql .= 'SELECT COUNT(user_id) AS total
+ FROM ' . BB_USERS . '
+ WHERE user_level = ' . ADMIN . '
+ AND user_id <> ' . GUEST_UID;
- $select_sql .= " WHERE u.user_level = ".ADMIN."
- AND u.user_id <> ".GUEST_UID;
- break;
- case 'mods':
- $text = $lang['SEARCH_FOR_MODS'];
+ $select_sql .= ' WHERE u.user_level = ' . ADMIN . '
+ AND u.user_id <> ' . GUEST_UID;
+ break;
+ case 'mods':
+ $text = $lang['SEARCH_FOR_MODS'];
- $total_sql .= "SELECT COUNT(user_id) AS total
- FROM ".BB_USERS."
- WHERE user_level = ".MOD."
- AND user_id <> ".GUEST_UID;
+ $total_sql .= 'SELECT COUNT(user_id) AS total
+ FROM ' . BB_USERS . '
+ WHERE user_level = ' . MOD . '
+ AND user_id <> ' . GUEST_UID;
- $select_sql .= " WHERE u.user_level = ".MOD."
- AND u.user_id <> ".GUEST_UID;
- break;
- case 'banned':
- $text = $lang['SEARCH_FOR_BANNED'];
+ $select_sql .= ' WHERE u.user_level = ' . MOD . '
+ AND u.user_id <> ' . GUEST_UID;
+ break;
+ case 'banned':
+ $text = $lang['SEARCH_FOR_BANNED'];
- $total_sql .= "SELECT COUNT(u.user_id) AS total
- FROM ".BB_USERS." AS u, ".BB_BANLIST." AS b
+ $total_sql .= 'SELECT COUNT(u.user_id) AS total
+ FROM ' . BB_USERS . ' AS u, ' . BB_BANLIST . ' AS b
WHERE u.user_id = b.ban_userid
- AND u.user_id <> ".GUEST_UID;
+ AND u.user_id <> ' . GUEST_UID;
- $select_sql .= ", ".BB_BANLIST." AS b
+ $select_sql .= ', ' . BB_BANLIST . ' AS b
WHERE u.user_id = b.ban_userid
- AND u.user_id <> ".GUEST_UID;
+ AND u.user_id <> ' . GUEST_UID;
- break;
- case 'disabled':
- $text = $lang['SEARCH_FOR_DISABLED'];
+ break;
+ case 'disabled':
+ $text = $lang['SEARCH_FOR_DISABLED'];
- $total_sql .= "SELECT COUNT(user_id) AS total
- FROM ".BB_USERS."
+ $total_sql .= 'SELECT COUNT(user_id) AS total
+ FROM ' . BB_USERS . '
WHERE user_active = 0
- AND user_id <> ".GUEST_UID;
+ AND user_id <> ' . GUEST_UID;
- $select_sql .= " WHERE u.user_active = 0
- AND u.user_id <> ".GUEST_UID;
+ $select_sql .= ' WHERE u.user_active = 0
+ AND u.user_id <> ' . GUEST_UID;
- break;
- default:
- bb_die($lang['SEARCH_INVALID']);
- }
- }
+ break;
+ default:
+ bb_die($lang['SEARCH_INVALID']);
+ }
+ }
- $select_sql .= " ORDER BY ";
+ $select_sql .= ' ORDER BY ';
- switch (strtolower(@$_GET['sort']))
- {
- case 'regdate':
- $sort = 'regdate';
- $select_sql .= 'u.user_regdate';
- break;
+ if (isset($_GET['sort'])) {
+ switch (strtolower($_GET['sort'])) {
+ case 'regdate':
+ $sort = 'regdate';
+ $select_sql .= 'u.user_regdate';
+ break;
- case 'posts':
- $sort = 'posts';
- $select_sql .= 'u.user_posts';
- break;
+ case 'posts':
+ $sort = 'posts';
+ $select_sql .= 'u.user_posts';
+ break;
- case 'user_email':
- $sort = 'user_email';
- $select_sql .= 'u.user_email';
- break;
+ case 'user_email':
+ $sort = 'user_email';
+ $select_sql .= 'u.user_email';
+ break;
- case 'lastvisit':
- $sort = 'lastvisit';
- $select_sql .= 'u.user_lastvisit';
- break;
+ case 'lastvisit':
+ $sort = 'lastvisit';
+ $select_sql .= 'u.user_lastvisit';
+ break;
- case 'username':
- default:
- $sort = 'username';
- $select_sql .= 'u.username';
- }
+ case 'username':
+ $sort = 'username';
+ $select_sql .= 'u.username';
+ }
+ } else {
+ $sort = 'username';
+ $select_sql .= 'u.username';
+ }
- switch (@$_GET['order'])
- {
- case 'DESC':
- $order = 'DESC';
- $o_order = 'ASC';
- break;
+ if (isset($_GET['order'])) {
+ $o_order = 'ASC';
+ $order = 'DESC';
+ } else {
+ $o_order = 'DESC';
+ $order = 'ASC';
+ }
- default:
- $o_order = 'DESC';
- $order = 'ASC';
- }
+ $select_sql .= " $order";
- $select_sql .= " $order";
+ $page = isset($_GET['page']) ? (int)$_GET['page'] : 0;
- $page = ( isset($_GET['page']) ) ? intval($_GET['page']) : intval(trim(@$_POST['page']));
+ if ($page < 1) {
+ $page = 1;
+ }
- if ($page < 1)
- {
- $page = 1;
- }
+ if ($page == 1) {
+ $offset = 0;
+ } else {
+ $offset = (($page - 1) * config()->get('topics_per_page'));
+ }
- if ($page == 1)
- {
- $offset = 0;
- }
- else
- {
- $offset = ( ($page - 1) * $bb_cfg['topics_per_page']);
- }
+ $limit = "LIMIT $offset, " . config()->get('topics_per_page');
- $limit = "LIMIT $offset, ".$bb_cfg['topics_per_page'];
+ $select_sql .= " $limit";
- $select_sql .= " $limit";
+ if (null !== $total_sql) {
+ if (!$result = DB()->sql_query($total_sql)) {
+ bb_die('Could not count users');
+ }
- if (!is_null($total_sql))
- {
- if (!$result = DB()->sql_query($total_sql))
- {
- bb_die('Could not count users');
- }
+ $total_pages = DB()->sql_fetchrow($result);
- $total_pages = DB()->sql_fetchrow($result);
+ if ($total_pages['total'] == 0) {
+ bb_die($lang['SEARCH_NO_RESULTS']);
+ }
+ }
+ $num_pages = ceil($total_pages['total'] / config()->get('topics_per_page'));
- if ($total_pages['total'] == 0)
- {
- bb_die($lang['SEARCH_NO_RESULTS']);
- }
- }
- $num_pages = ceil( ( $total_pages['total'] / $bb_cfg['topics_per_page'] ) );
+ $pagination = '';
- $pagination = '';
+ if ($page > 1) {
+ $pagination .= '' . $lang['BACK'] . ' ';
+ }
+ if ($page < $num_pages) {
+ $pagination .= ($pagination == '') ? '' . $lang['NEXT'] . ' ' : ' | ' . $lang['NEXT'] . ' ';
+ }
+ if ($num_pages > 2) {
+ $pagination .= ' ';
+ }
+ $template->assign_vars([
+ 'TPL_ADMIN_USER_SEARCH_RESULTS' => true,
- if ($page > 1)
- {
- $pagination .= ''. $lang['PREVIOUS'] .' ';
- }
- if ($page < $num_pages)
- {
- $pagination .= ( $pagination == '' ) ? ''.$lang['NEXT'].' ' : ' | '.$lang['NEXT'].' ';
- }
- if ($num_pages > 2)
- {
- $pagination .= ' ';
- }
- $template->assign_vars(array(
- 'TPL_ADMIN_USER_SEARCH_RESULTS' => true,
+ 'PAGE_NUMBER' => sprintf($lang['PAGE_OF'], $page, $num_pages),
+ 'PAGINATION' => $pagination,
+ 'NEW_SEARCH' => sprintf($lang['SEARCH_USERS_NEW'], $text, $total_pages['total'], 'admin_user_search.php'),
- 'PAGE_NUMBER' => sprintf($lang['PAGE_OF'], $page, $num_pages),
- 'PAGINATION' => $pagination,
- 'NEW_SEARCH' => sprintf($lang['SEARCH_USERS_NEW'],$text, $total_pages['total'], 'admin_user_search.php'),
+ 'U_USERNAME' => ($sort == 'username') ? "$base_url&sort=$sort&order=$o_order" : "$base_url&sort=username&order=$order",
+ 'U_EMAIL' => ($sort == 'user_email') ? "$base_url&sort=$sort&order=$o_order" : "$base_url&sort=user_email&order=$order",
+ 'U_POSTS' => ($sort == 'posts') ? "$base_url&sort=$sort&order=$o_order" : "$base_url&sort=posts&order=$order",
+ 'U_JOINDATE' => ($sort == 'regdate') ? "$base_url&sort=$sort&order=$o_order" : "$base_url&sort=regdate&order=$order",
+ 'U_LASTVISIT' => ($sort == 'lastvisit') ? "$base_url&sort=$sort&order=$o_order" : "$base_url&sort=lastvisit&order=$order",
- 'U_USERNAME' => ($sort == 'username') ? "$base_url&sort=$sort&order=$o_order" : "$base_url&sort=username&order=$order",
- 'U_EMAIL' => ($sort == 'user_email') ? "$base_url&sort=$sort&order=$o_order" : "$base_url&sort=user_email&order=$order",
- 'U_POSTS' => ($sort == 'posts') ? "$base_url&sort=$sort&order=$o_order" : "$base_url&sort=posts&order=$order",
- 'U_JOINDATE' => ($sort == 'regdate') ? "$base_url&sort=$sort&order=$o_order" : "$base_url&sort=regdate&order=$order",
- 'U_LASTVISIT' => ($sort == 'lastvisit') ? "$base_url&sort=$sort&order=$o_order" : "$base_url&sort=lastvisit&order=$order",
+ 'S_POST_ACTION' => "$base_url&sort=$sort&order=$order"
+ ]);
- 'S_POST_ACTION' => "$base_url&sort=$sort&order=$order"
- ));
+ if (!$result = DB()->sql_query($select_sql)) {
+ bb_die('Could not select user data');
+ }
- if (!$result = DB()->sql_query($select_sql))
- {
- bb_die('Could not select user data');
- }
+ $rowset = DB()->sql_fetchrowset($result);
- $rowset = DB()->sql_fetchrowset($result);
+ $users_sql = '';
- $users_sql = '';
+ foreach ($rowset as $array) {
+ $users_sql .= ($users_sql == '') ? $array['user_id'] : ', ' . $array['user_id'];
+ }
- foreach ($rowset as $array)
- {
- $users_sql .= ( $users_sql == '' ) ? $array['user_id'] : ', '.$array['user_id'];
- }
+ $sql = 'SELECT ban_userid AS user_id FROM ' . BB_BANLIST . " WHERE ban_userid IN ($users_sql)";
- $sql = "SELECT ban_userid AS user_id FROM ". BB_BANLIST ." WHERE ban_userid IN ($users_sql)";
+ if (!$result = DB()->sql_query($sql)) {
+ bb_die('Could not select banned data');
+ }
- if (!$result = DB()->sql_query($sql))
- {
- bb_die('Could not select banned data');
- }
+ unset($banned);
- unset($banned);
+ $banned = [];
- $banned = array();
+ while ($row = DB()->sql_fetchrow($result)) {
+ $banned[$row['user_id']] = true;
+ }
- while ($row = DB()->sql_fetchrow($result))
- {
- $banned[$row['user_id']] = true;
- }
+ for ($i = 0, $iMax = count($rowset); $i < $iMax; $i++) {
+ $row_class = !($i % 2) ? 'row1' : 'row2';
- for ($i = 0; $i < count($rowset); $i++)
- {
- $row_class = !($i % 2) ? 'row1' : 'row2';
+ $template->assign_block_vars('userrow', [
+ 'ROW_CLASS' => $row_class,
+ 'USER' => profile_url($rowset[$i], true),
+ 'EMAIL' => $rowset[$i]['user_email'],
+ 'JOINDATE' => bb_date($rowset[$i]['user_regdate']),
+ 'LASTVISIT' => $rowset[$i]['user_lastvisit'] ? bb_date($rowset[$i]['user_lastvisit']) : $lang['NEVER'],
+ 'POSTS' => $rowset[$i]['user_posts'],
+ 'BAN' => (!isset($banned[$rowset[$i]['user_id']])) ? $lang['NOT_BANNED'] : $lang['BANNED'],
+ 'ABLED' => $rowset[$i]['user_active'] ? $lang['ENABLED'] : $lang['DISABLED'],
- $template->assign_block_vars('userrow', array(
- 'ROW_CLASS' => $row_class,
- 'USER' => profile_url($rowset[$i]),
- 'EMAIL' => $rowset[$i]['user_email'],
- 'JOINDATE' => bb_date($rowset[$i]['user_regdate']),
- 'LASTVISIT' => bb_date($rowset[$i]['user_lastvisit']),
- 'POSTS' => $rowset[$i]['user_posts'],
- 'BAN' => ( ( !isset($banned[$rowset[$i]['user_id']]) ) ? $lang['NOT_BANNED'] : $lang['BANNED'] ),
- 'ABLED' => ( ( $rowset[$i]['user_active'] ) ? $lang['ENABLED'] : $lang['DISABLED'] ),
-
- 'U_VIEWPOSTS' => "../search.php?search_author=1&uid={$rowset[$i]['user_id']}",
- 'U_MANAGE' => '../profile.php?mode=editprofile&'. POST_USERS_URL .'='.$rowset[$i]['user_id'].'&admin=1',
- 'U_PERMISSIONS' => 'admin_ug_auth.php?mode=user&'. POST_USERS_URL .'='. $rowset[$i]['user_id'],
- ));
- }
+ 'U_VIEWPOSTS' => "../search.php?search_author=1&uid={$rowset[$i]['user_id']}",
+ 'U_MANAGE' => '../profile.php?mode=editprofile&' . POST_USERS_URL . '=' . $rowset[$i]['user_id'] . '&admin=1',
+ 'U_PERMISSIONS' => 'admin_ug_auth.php?mode=user&' . POST_USERS_URL . '=' . $rowset[$i]['user_id'],
+ ]);
+ }
}
-print_page('admin_user_search.tpl', 'admin');
\ No newline at end of file
+print_page('admin_user_search.tpl', 'admin');
diff --git a/admin/admin_words.php b/admin/admin_words.php
index e46de3025..94f11caba 100644
--- a/admin/admin_words.php
+++ b/admin/admin_words.php
@@ -1,157 +1,138 @@
($bb_cfg[\'use_word_censor\'] in config.php)');
+require __DIR__ . '/pagestart.php';
+
+if (!config()->get('use_word_censor')) {
+ bb_die('Word censor disabled (use_word_censor in config.php)');
}
$mode = request_var('mode', '');
$mode = htmlspecialchars($mode);
-if (isset($_POST['add']))
-{
- $mode = 'add';
-}
-else if (isset($_POST['save']))
-{
- $mode = 'save';
+if (isset($_POST['add'])) {
+ $mode = 'add';
+} elseif (isset($_POST['save'])) {
+ $mode = 'save';
}
-if ($mode != '')
-{
- if ($mode == 'edit' || $mode == 'add')
- {
- $word_id = intval(request_var('id', 0));
+if ($mode != '') {
+ if ($mode == 'edit' || $mode == 'add') {
+ $word_id = (int)request_var('id', 0);
- $s_hidden_fields = $word = $replacement = '';
+ $s_hidden_fields = $word = $replacement = '';
- if ($mode == 'edit')
- {
- if ($word_id)
- {
- $sql = "SELECT * FROM " . BB_WORDS . " WHERE word_id = $word_id";
- if (!$result = DB()->sql_query($sql))
- {
- bb_die('Could not query words table #1');
- }
+ if ($mode == 'edit') {
+ if ($word_id) {
+ $sql = 'SELECT * FROM ' . BB_WORDS . " WHERE word_id = $word_id";
+ if (!$result = DB()->sql_query($sql)) {
+ bb_die('Could not query words table #1');
+ }
- $word_info = DB()->sql_fetchrow($result);
- $s_hidden_fields .= ' ';
- $word = $word_info['word'];
- $replacement = $word_info['replacement'];
- }
- else
- {
- bb_die($lang['NO_WORD_SELECTED']);
- }
- }
+ $word_info = DB()->sql_fetchrow($result);
+ $s_hidden_fields .= ' ';
+ $word = $word_info['word'];
+ $replacement = $word_info['replacement'];
+ } else {
+ bb_die($lang['NO_WORD_SELECTED']);
+ }
+ }
- $template->assign_vars(array(
- 'TPL_ADMIN_WORDS_EDIT' => true,
- 'WORD' => $word,
- 'REPLACEMENT' => $replacement,
- 'S_WORDS_ACTION' => 'admin_words.php',
- 'S_HIDDEN_FIELDS' => $s_hidden_fields,
- ));
- }
- else if ($mode == 'save')
- {
- $word_id = intval(request_var('id', 0));
- $word = trim(request_var('word', ''));
- $replacement = trim(request_var('replacement', ''));
+ $template->assign_vars([
+ 'TPL_ADMIN_WORDS_EDIT' => true,
+ 'WORD' => $word,
+ 'REPLACEMENT' => $replacement,
+ 'S_WORDS_ACTION' => 'admin_words.php',
+ 'S_HIDDEN_FIELDS' => $s_hidden_fields,
+ ]);
+ } elseif ($mode == 'save') {
+ $word_id = (int)request_var('id', 0);
+ $word = trim(request_var('word', ''));
+ $replacement = trim(request_var('replacement', ''));
- if ($word == '' || $replacement == '')
- {
- bb_die($lang['MUST_ENTER_WORD']);
- }
+ if ($word == '' || $replacement == '') {
+ bb_die($lang['MUST_ENTER_WORD']);
+ }
- if ($word_id)
- {
- $sql = "UPDATE " . BB_WORDS . "
+ if ($word_id) {
+ $sql = 'UPDATE ' . BB_WORDS . "
SET word = '" . DB()->escape($word) . "', replacement = '" . DB()->escape($replacement) . "'
WHERE word_id = $word_id";
- $message = $lang['WORD_UPDATED'];
- }
- else
- {
- $sql = "INSERT INTO " . BB_WORDS . " (word, replacement)
+ $message = $lang['WORD_UPDATED'];
+ } else {
+ $sql = 'INSERT INTO ' . BB_WORDS . " (word, replacement)
VALUES ('" . DB()->escape($word) . "', '" . DB()->escape($replacement) . "')";
- $message = $lang['WORD_ADDED'];
- }
+ $message = $lang['WORD_ADDED'];
+ }
- if (!$result = DB()->sql_query($sql))
- {
- bb_die('Could not insert data into words table');
- }
+ if (!$result = DB()->sql_query($sql)) {
+ bb_die('Could not insert data into words table');
+ }
- CACHE('bb_cache')->rm('censored');
- $message .= ' ' . sprintf($lang['CLICK_RETURN_WORDADMIN'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' ');
+ $datastore->update('censor');
+ censor()->reload(); // Reload the singleton instance with updated words
+ $message .= ' ' . sprintf($lang['CLICK_RETURN_WORDADMIN'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' ');
- bb_die($message);
- }
- else if ($mode == 'delete')
- {
- $word_id = intval(request_var('id', 0));
+ bb_die($message);
+ } elseif ($mode == 'delete') {
+ $word_id = (int)request_var('id', 0);
- if ($word_id)
- {
- $sql = "DELETE FROM " . BB_WORDS . " WHERE word_id = $word_id";
+ if ($word_id) {
+ $sql = 'DELETE FROM ' . BB_WORDS . " WHERE word_id = $word_id";
- if (!$result = DB()->sql_query($sql))
- {
- bb_die('Could not remove data from words table');
- }
+ if (!$result = DB()->sql_query($sql)) {
+ bb_die('Could not remove data from words table');
+ }
- CACHE('bb_cache')->rm('censored');
+ $datastore->update('censor');
+ censor()->reload(); // Reload the singleton instance with updated words
- bb_die($lang['WORD_REMOVED'] . ' ' . sprintf($lang['CLICK_RETURN_WORDADMIN'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '));
- }
- else
- {
- bb_die($lang['NO_WORD_SELECTED']);
- }
- }
-}
-else
-{
- $sql = "SELECT * FROM " . BB_WORDS . " ORDER BY word";
- if (!$result = DB()->sql_query($sql))
- {
- bb_die('Could not query words table #2');
- }
+ bb_die($lang['WORD_REMOVED'] . ' ' . sprintf($lang['CLICK_RETURN_WORDADMIN'], '', ' ') . ' ' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ' '));
+ } else {
+ bb_die($lang['NO_WORD_SELECTED']);
+ }
+ }
+} else {
+ $sql = 'SELECT * FROM ' . BB_WORDS . ' ORDER BY word';
+ if (!$result = DB()->sql_query($sql)) {
+ bb_die('Could not query words table #2');
+ }
- $word_rows = DB()->sql_fetchrowset($result);
- $word_count = count($word_rows);
+ $word_rows = DB()->sql_fetchrowset($result);
+ $word_count = count($word_rows);
- $template->assign_vars(array(
- 'TPL_ADMIN_WORDS_LIST' => true,
- 'S_WORDS_ACTION' => 'admin_words.php',
- 'S_HIDDEN_FIELDS' => '',
- ));
+ $template->assign_vars([
+ 'TPL_ADMIN_WORDS_LIST' => true,
+ 'S_WORDS_ACTION' => 'admin_words.php',
+ 'S_HIDDEN_FIELDS' => ''
+ ]);
- for ($i = 0; $i < $word_count; $i++)
- {
- $word = $word_rows[$i]['word'];
- $replacement = $word_rows[$i]['replacement'];
- $word_id = $word_rows[$i]['word_id'];
+ for ($i = 0; $i < $word_count; $i++) {
+ $word = $word_rows[$i]['word'];
+ $replacement = $word_rows[$i]['replacement'];
+ $word_id = $word_rows[$i]['word_id'];
- $row_class = !($i % 2) ? 'row1' : 'row2';
+ $row_class = !($i % 2) ? 'row1' : 'row2';
- $template->assign_block_vars('words', array(
- 'ROW_CLASS' => $row_class,
- 'WORD' => $word,
- 'REPLACEMENT' => $replacement,
- 'U_WORD_EDIT' => "admin_words.php?mode=edit&id=$word_id",
- 'U_WORD_DELETE' => "admin_words.php?mode=delete&id=$word_id",
- ));
- }
+ $template->assign_block_vars('words', [
+ 'ROW_CLASS' => $row_class,
+ 'WORD' => $word,
+ 'REPLACEMENT' => $replacement,
+ 'U_WORD_EDIT' => "admin_words.php?mode=edit&id=$word_id",
+ 'U_WORD_DELETE' => "admin_words.php?mode=delete&id=$word_id"
+ ]);
+ }
}
-print_page('admin_words.tpl', 'admin');
\ No newline at end of file
+print_page('admin_words.tpl', 'admin');
diff --git a/admin/index.php b/admin/index.php
index 1334f3d8b..33cb3411d 100644
--- a/admin/index.php
+++ b/admin/index.php
@@ -1,291 +1,228 @@
get('stats')) {
+ $datastore->update('stats');
+ $stats = $datastore->get('stats');
+}
+
+// Check for updates
+if (!$update_data = $datastore->get('check_updates')) {
+ $datastore->update('check_updates');
+ $update_data = $datastore->get('check_updates');
+}
// Generate relevant output
-if (isset($_GET['pane']) && $_GET['pane'] == 'left')
-{
- if (!$module = CACHE('bb_cache')->get('admin_module'))
- {
- $dir = @opendir('.');
- $setmodules = 1;
- while ($file = @readdir($dir))
- {
- if (preg_match('/^admin_.*?\.php$/', $file))
- {
- include('./' . $file);
- }
- }
- unset($setmodules);
- @closedir($dir);
- CACHE('bb_cache')->set('admin_module', $module, 600);
- }
+if (isset($_GET['pane']) && $_GET['pane'] == 'left') {
+ $module = [];
- $template->assign_vars(array(
- 'TPL_ADMIN_NAVIGATE' => true,
- 'U_FORUM_INDEX' => '../index.php',
- 'U_ADMIN_INDEX' => 'index.php?pane=right',
- ));
+ // Scan modules
+ if (!CACHE('bb_cache')->get('admin_module_' . $user->id)) {
+ $dir = opendir('.');
+ $setmodules = true;
+ while ($file = readdir($dir)) {
+ if (preg_match('/^admin_.*?\.php$/', $file)) {
+ include './' . $file;
+ }
+ }
+ unset($setmodules);
+ closedir($dir);
- ksort($module);
+ // Set modules into cache
+ CACHE('bb_cache')->set('admin_module_' . $user->id, $module, 600);
+ }
- while (list($cat, $action_array) = each($module))
- {
- $cat = (!empty($lang[$cat])) ? $lang[$cat] : preg_replace('/_/', ' ', $cat);
+ // Get modules from cache
+ $module = CACHE('bb_cache')->get('admin_module_' . $user->id);
- $template->assign_block_vars('catrow', array(
- 'ADMIN_CATEGORY' => $cat,
- ));
+ $template->assign_vars([
+ 'TPL_ADMIN_NAVIGATE' => true,
+ 'U_FORUM_INDEX' => '../index.php',
+ 'U_ADMIN_INDEX' => 'index.php?pane=right',
+ ]);
- ksort($action_array);
+ ksort($module);
- $row_count = 0;
- while (list($action, $file) = each($action_array))
- {
- $row_class = !($row_count % 2) ? 'row1' : 'row2';
+ foreach ($module as $cat => $action_array) {
+ $cat = (!empty($lang[$cat])) ? $lang[$cat] : str_replace("_", ' ', $cat);
- $action = (!empty($lang[$action])) ? $lang[$action] : preg_replace('/_/', ' ', $action);
+ $template->assign_block_vars('catrow', [
+ 'ADMIN_CATEGORY' => $cat,
+ ]);
- $template->assign_block_vars('catrow.modulerow', array(
- 'ROW_CLASS' => $row_class,
- 'ADMIN_MODULE' => $action,
- 'U_ADMIN_MODULE' => $file,
- ));
- $row_count++;
- }
- }
-}
-elseif (isset($_GET['pane']) && $_GET['pane'] == 'right')
-{
- $template->assign_vars(array(
- 'TPL_ADMIN_MAIN' => true,
- 'ADMIN_LOCK' => ($bb_cfg['board_disable']) ? true : false,
- 'ADMIN_LOCK_CRON' => (file_exists(BB_DISABLED)) ? true :false,
- ));
+ ksort($action_array);
- // Get forum statistics
- $total_posts = get_db_stat('postcount');
- $total_users = get_db_stat('usercount');
- $total_topics = get_db_stat('topiccount');
- $start_date = bb_date($bb_cfg['board_startdate']);
- $boarddays = (TIMENOW - $bb_cfg['board_startdate']) / 86400;
+ $row_count = 0;
+ foreach ($action_array as $action => $file) {
+ $row_class = !($row_count % 2) ? 'row1' : 'row2';
- $posts_per_day = sprintf('%.2f', $total_posts / $boarddays);
- $topics_per_day = sprintf('%.2f', $total_topics / $boarddays);
- $users_per_day = sprintf('%.2f', $total_users / $boarddays);
+ $action = (!empty($lang[$action])) ? $lang[$action] : str_replace("_", ' ', $action);
- $avatar_dir_size = 0;
+ $template->assign_block_vars('catrow.modulerow', [
+ 'ROW_CLASS' => $row_class,
+ 'ADMIN_MODULE' => $action,
+ 'U_ADMIN_MODULE' => $file,
+ ]);
+ $row_count++;
+ }
+ }
+} elseif (isset($_GET['pane']) && $_GET['pane'] == 'right') {
+ $template->assign_vars([
+ 'TPL_ADMIN_MAIN' => true,
+ 'ADMIN_LOCK' => (bool)config()->get('board_disable'),
+ 'ADMIN_LOCK_CRON' => is_file(BB_DISABLED),
+ ]);
- if ($avatar_dir = @opendir(BB_ROOT . $bb_cfg['avatar_path']))
- {
- while( $file = @readdir($avatar_dir) )
- {
- if( $file != '.' && $file != '..' )
- {
- $avatar_dir_size += @filesize(BB_ROOT . $bb_cfg['avatar_path'] . '/' . $file);
- }
- }
- @closedir($avatar_dir);
+ // Check for updates
+ if (isset($update_data['available_update'])) {
+ $template->assign_block_vars('updater', [
+ 'UPDATE_AVAILABLE' => $update_data['available_update'],
+ 'NEW_VERSION_NUMBER' => $update_data['latest_version'],
+ 'NEW_VERSION_SIZE' => $update_data['latest_version_size'],
+ 'NEW_VERSION_DL_LINK' => $update_data['latest_version_dl_link'],
+ 'NEW_VERSION_LINK' => $update_data['latest_version_link'],
+ 'NEW_VERSION_HASH' => $update_data['latest_version_checksum']
+ ]);
+ }
- $avatar_dir_size = humn_size($avatar_dir_size);
- }
- else
- {
- $avatar_dir_size = $lang['NOT_AVAILABLE'];
- }
+ // Get forum statistics
+ $total_posts = $stats['postcount'];
+ $total_topics = $stats['topiccount'];
+ $total_users = $stats['usercount'];
+ $start_date = bb_date(config()->get('board_startdate'));
+ $boarddays = (TIMENOW - config()->get('board_startdate')) / 86400;
- if (intval($posts_per_day) > $total_posts)
- {
- $posts_per_day = $total_posts;
- }
+ $posts_per_day = sprintf('%.2f', $total_posts / $boarddays);
+ $topics_per_day = sprintf('%.2f', $total_topics / $boarddays);
+ $users_per_day = sprintf('%.2f', $total_users / $boarddays);
- if (intval($topics_per_day) > $total_topics)
- {
- $topics_per_day = $total_topics;
- }
+ $avatar_dir_size = 0;
- if ($users_per_day > $total_users)
- {
- $users_per_day = $total_users;
- }
+ if ($avatar_dir = opendir(config()->get('avatars.upload_path'))) {
+ while ($file = readdir($avatar_dir)) {
+ if ($file != '.' && $file != '..') {
+ $avatar_dir_size += @filesize(config()->get('avatars.upload_path') . $file);
+ }
+ }
+ closedir($avatar_dir);
- // DB size ... MySQL only
- $sql = "SELECT VERSION() AS mysql_version";
- if ($result = DB()->sql_query($sql))
- {
- $row = DB()->sql_fetchrow($result);
- $version = $row['mysql_version'];
+ $avatar_dir_size = humn_size($avatar_dir_size);
+ } else {
+ $avatar_dir_size = $lang['NOT_AVAILABLE'];
+ }
- if (preg_match('/^(3\.23|4\.|5\.|10\.)/', $version))
- {
- $dblist = array();
- foreach ($bb_cfg['db'] as $name => $row)
- {
- $sql = "SHOW TABLE STATUS FROM {$row[1]}";
- if ($result = DB()->sql_query($sql))
- {
- $tabledata_ary = DB()->sql_fetchrowset($result);
+ if ((int)$posts_per_day > $total_posts) {
+ $posts_per_day = $total_posts;
+ }
- $dbsize = 0;
- for ($i = 0; $i < count($tabledata_ary); $i++)
- {
- if( @$tabledata_ary[$i]['Type'] != 'MRG_MYISAM' )
- {
- $dbsize += $tabledata_ary[$i]['Data_length'] + $tabledata_ary[$i]['Index_length'];
- }
- }
- $dblist[] = ''. humn_size($dbsize) .' ';
- }
- }
- $dbsize = implode(' | ', $dblist);
- }
- else
- {
- $dbsize = $lang['NOT_AVAILABLE'];
- }
- }
- else
- {
- $dbsize = $lang['NOT_AVAILABLE'];
- }
+ if ((int)$topics_per_day > $total_topics) {
+ $topics_per_day = $total_topics;
+ }
- $template->assign_vars(array(
- 'NUMBER_OF_POSTS' => $total_posts,
- 'NUMBER_OF_TOPICS' => $total_topics,
- 'NUMBER_OF_USERS' => $total_users,
- 'START_DATE' => $start_date,
- 'POSTS_PER_DAY' => $posts_per_day,
- 'TOPICS_PER_DAY' => $topics_per_day,
- 'USERS_PER_DAY' => $users_per_day,
- 'AVATAR_DIR_SIZE' => $avatar_dir_size,
- 'DB_SIZE' => $dbsize,
- 'GZIP_COMPRESSION' => ($bb_cfg['gzip_compress']) ? $lang['ON'] : $lang['OFF'],
- ));
+ if ($users_per_day > $total_users) {
+ $users_per_day = $total_users;
+ }
- if (@$_GET['users_online'])
- {
- $template->assign_vars(array(
- 'SHOW_USERS_ONLINE' => true,
- ));
+ $template->assign_vars([
+ 'NUMBER_OF_POSTS' => $total_posts,
+ 'NUMBER_OF_TOPICS' => $total_topics,
+ 'NUMBER_OF_USERS' => $total_users,
+ 'START_DATE' => $start_date,
+ 'POSTS_PER_DAY' => $posts_per_day,
+ 'TOPICS_PER_DAY' => $topics_per_day,
+ 'USERS_PER_DAY' => $users_per_day,
+ 'AVATAR_DIR_SIZE' => $avatar_dir_size,
+ ]);
- // Get users online information.
- $sql = "SELECT u.user_id, u.username, u.user_rank, s.session_time AS user_session_time, u.user_opt, s.session_logged_in, s.session_ip, s.session_start
- FROM " . BB_USERS . " u, " . BB_SESSIONS . " s
+ if (isset($_GET['users_online'])) {
+ $template->assign_vars([
+ 'SHOW_USERS_ONLINE' => true,
+ ]);
+
+ // Get users online information.
+ $sql = 'SELECT u.user_id, u.username, u.user_rank, s.session_time AS user_session_time, u.user_opt, s.session_logged_in, s.session_ip, s.session_start
+ FROM ' . BB_USERS . ' u, ' . BB_SESSIONS . ' s
WHERE s.session_logged_in = 1
AND u.user_id = s.session_user_id
- AND u.user_id <> " . GUEST_UID . "
- AND s.session_time >= " . ( TIMENOW - 300 ) . "
- ORDER BY s.session_ip ASC, s.session_time DESC";
- if (!$result = DB()->sql_query($sql))
- {
- bb_die('Could not obtain reged user / online information');
- }
- $onlinerow_reg = DB()->sql_fetchrowset($result);
+ AND u.user_id <> ' . GUEST_UID . '
+ AND s.session_time >= ' . (TIMENOW - 300) . '
+ ORDER BY s.session_ip ASC, s.session_time DESC';
+ if (!$result = DB()->sql_query($sql)) {
+ bb_die('Could not obtain reged user / online information');
+ }
+ $onlinerow_reg = DB()->sql_fetchrowset($result);
- $sql = "SELECT session_logged_in, session_time, session_ip, session_start
- FROM " . BB_SESSIONS . "
+ // Get guests online information.
+ $sql = 'SELECT session_logged_in, session_time, session_ip, session_start
+ FROM ' . BB_SESSIONS . '
WHERE session_logged_in = 0
- AND session_time >= " . ( TIMENOW - 300 ) . "
- ORDER BY session_ip ASC, session_time DESC";
- if (!$result = DB()->sql_query($sql))
- {
- bb_die('Could not obtain guest user / online information');
- }
- $onlinerow_guest = DB()->sql_fetchrowset($result);
+ AND session_time >= ' . (TIMENOW - 300) . '
+ ORDER BY session_ip ASC, session_time DESC';
+ if (!$result = DB()->sql_query($sql)) {
+ bb_die('Could not obtain guest user / online information');
+ }
+ $onlinerow_guest = DB()->sql_fetchrowset($result);
- $reg_userid_ary = array();
+ // Reg users
+ if (count($onlinerow_reg)) {
+ $users_count = 0;
- if (count($onlinerow_reg))
- {
- $registered_users = $hidden_users = 0;
+ for ($i = 0, $iMax = count($onlinerow_reg); $i < $iMax; $i++) {
+ $users_count++;
+ $row_class = 'row1';
+ $reg_ip = \TorrentPier\Helpers\IPHelper::long2ip_extended($onlinerow_reg[$i]['session_ip']);
- for ($i = 0, $cnt = count($onlinerow_reg); $i < $cnt; $i++)
- {
- if (!in_array($onlinerow_reg[$i]['user_id'], $reg_userid_ary))
- {
- $reg_userid_ary[] = $onlinerow_reg[$i]['user_id'];
+ $template->assign_block_vars('reg_user_row', [
+ 'ROW_CLASS' => $row_class,
+ 'USER' => profile_url($onlinerow_reg[$i], true),
+ 'STARTED' => bb_date($onlinerow_reg[$i]['session_start'], 'd-M-Y H:i', false),
+ 'LASTUPDATE' => bb_date($onlinerow_reg[$i]['user_session_time'], 'd-M-Y H:i', false),
+ 'IP_ADDRESS' => $reg_ip,
+ 'U_WHOIS_IP' => config()->get('whois_info') . $reg_ip,
+ ]);
+ }
+ }
- $username = $onlinerow_reg[$i]['username'];
+ // Guest users
+ if (count($onlinerow_guest)) {
+ $guest_users = 0;
- if (bf($onlinerow_reg[$i]['user_opt'], 'user_opt', 'user_viewonline'))
- {
- $hidden_users++;
- $hidden = TRUE;
- }
- else
- {
- $registered_users++;
- $hidden = FALSE;
- }
+ for ($i = 0, $iMax = count($onlinerow_guest); $i < $iMax; $i++) {
+ $guest_users++;
+ $row_class = 'row2';
+ $guest_ip = \TorrentPier\Helpers\IPHelper::long2ip_extended($onlinerow_guest[$i]['session_ip']);
- $row_class = 'row1';
-
- $reg_ip = decode_ip($onlinerow_reg[$i]['session_ip']);
-
- $template->assign_block_vars('reg_user_row', array(
- 'ROW_CLASS' => $row_class,
- 'USER' => profile_url($onlinerow_reg[$i]),
- 'STARTED' => bb_date($onlinerow_reg[$i]['session_start'], 'H:i', false),
- 'LASTUPDATE' => bb_date($onlinerow_reg[$i]['user_session_time'], 'H:i', false),
- 'IP_ADDRESS' => $reg_ip,
- 'U_WHOIS_IP' => $bb_cfg['whois_info'] . $reg_ip,
- ));
- }
- }
- }
-
- // Guest users
- if (count($onlinerow_guest))
- {
- $guest_users = 0;
-
- for ($i = 0; $i < count($onlinerow_guest); $i++)
- {
- $guest_userip_ary[] = $onlinerow_guest[$i]['session_ip'];
- $guest_users++;
-
- $row_class = 'row2';
-
- $guest_ip = decode_ip($onlinerow_guest[$i]['session_ip']);
-
- $template->assign_block_vars('guest_user_row', array(
- 'ROW_CLASS' => $row_class,
- 'STARTED' => bb_date($onlinerow_guest[$i]['session_start'], 'H:i', false),
- 'LASTUPDATE' => bb_date($onlinerow_guest[$i]['session_time'], 'H:i' , false),
- 'IP_ADDRESS' => $guest_ip,
- 'U_WHOIS_IP' => $bb_cfg['whois_info'] . $guest_ip,
- ));
- }
- }
- }
- else
- {
- $template->assign_vars(array(
- 'USERS_ONLINE_HREF' => 'index.php?pane=right&users_online=1',
- ));
- }
-}
-else
-{
- // Generate frameset
- $template->assign_vars(array(
- 'TPL_ADMIN_FRAMESET' => true,
- ));
- send_no_cache_headers();
- print_page('index.tpl', 'admin', 'no_header');
+ $template->assign_block_vars('guest_user_row', [
+ 'ROW_CLASS' => $row_class,
+ 'STARTED' => bb_date($onlinerow_guest[$i]['session_start'], 'd-M-Y H:i', false),
+ 'LASTUPDATE' => bb_date($onlinerow_guest[$i]['session_time'], 'd-M-Y H:i', false),
+ 'IP_ADDRESS' => $guest_ip,
+ 'U_WHOIS_IP' => config()->get('whois_info') . $guest_ip,
+ ]);
+ }
+ }
+ } else {
+ $template->assign_vars([
+ 'USERS_ONLINE_HREF' => 'index.php?pane=right&users_online=1',
+ ]);
+ }
+} else {
+ // Generate frameset
+ $template->assign_vars([
+ 'CONTENT_ENCODING' => DEFAULT_CHARSET,
+ 'TPL_ADMIN_FRAMESET' => true,
+ ]);
+ send_no_cache_headers();
+ print_page('index.tpl', 'admin', 'no_header');
}
print_page('index.tpl', 'admin');
-
-// Functions
-function inarray ($needle, $haystack)
-{
- for ($i = 0; $i < sizeof($haystack); $i++)
- {
- if ($haystack[$i] == $needle)
- {
- return true;
- }
- }
- return false;
-}
\ No newline at end of file
diff --git a/admin/pagestart.php b/admin/pagestart.php
index 40449b461..e9f0378fd 100644
--- a/admin/pagestart.php
+++ b/admin/pagestart.php
@@ -1,28 +1,30 @@
session_start();
-if (IS_GUEST)
-{
- redirect(LOGIN_URL . "?redirect=admin/index.php");
+if (IS_GUEST) {
+ redirect(LOGIN_URL . '?redirect=admin/index.php');
}
-if (!IS_ADMIN)
-{
- bb_die($lang['NOT_ADMIN']);
+if (!IS_ADMIN) {
+ bb_die($lang['NOT_ADMIN']);
}
-if (!$userdata['session_admin'])
-{
- $redirect = url_arg($_SERVER['REQUEST_URI'], 'admin', 1);
- redirect("login.php?redirect=$redirect");
-}
\ No newline at end of file
+if (!$userdata['session_admin']) {
+ $redirect = url_arg($_SERVER['REQUEST_URI'], 'admin', 1);
+ redirect(LOGIN_URL . "?redirect=$redirect");
+}
diff --git a/admin/stats/tr_stats.php b/admin/stats/tr_stats.php
index 4655acff6..db1fc444d 100644
--- a/admin/stats/tr_stats.php
+++ b/admin/stats/tr_stats.php
@@ -1,48 +1,46 @@
session_start();
-if (!IS_ADMIN) bb_die($lang['NOT_AUTHORISED']);
+if (!IS_ADMIN) {
+ bb_die($lang['NOT_AUTHORISED']);
+}
-$sql[] = 'SELECT count(*) FROM `'.BB_USERS.'` WHERE `user_lastvisit` < UNIX_TIMESTAMP()-2592000';
-$sql[] = 'SELECT count(*) FROM `'.BB_USERS.'` WHERE `user_lastvisit` < UNIX_TIMESTAMP()-7776000';
-$sql[] = 'SELECT round(avg(size)/1048576) FROM `'.BB_BT_TORRENTS.'`';
-$sql[] = 'SELECT count(*) FROM `'.BB_BT_TORRENTS.'`';
-$sql[] = 'SELECT count(distinct(topic_id)) FROM `'.BB_BT_TRACKER_SNAP.'` WHERE seeders > 0';
-$sql[] = 'SELECT count(distinct(topic_id)) FROM `'.BB_BT_TRACKER_SNAP.'` WHERE seeders > 5';
-$sql[] = 'SELECT count(distinct(poster_id)) FROM `'.BB_BT_TORRENTS.'`';
-$sql[] = 'SELECT count(distinct(poster_id)) FROM `'.BB_BT_TORRENTS.'` WHERE reg_time >= UNIX_TIMESTAMP()-2592000';
+$sql[] = 'SELECT count(*) FROM `' . BB_USERS . '` WHERE `user_lastvisit` < UNIX_TIMESTAMP()-2592000 AND user_id NOT IN (' . EXCLUDED_USERS . ')';
+$sql[] = 'SELECT count(*) FROM `' . BB_USERS . '` WHERE `user_lastvisit` < UNIX_TIMESTAMP()-7776000 AND user_id NOT IN (' . EXCLUDED_USERS . ')';
+$sql[] = 'SELECT round(avg(size)) FROM `' . BB_BT_TORRENTS . '`';
+$sql[] = 'SELECT count(*) FROM `' . BB_BT_TORRENTS . '`';
+$sql[] = 'SELECT count(distinct(topic_id)) FROM `' . BB_BT_TRACKER_SNAP . '` WHERE seeders > 0';
+$sql[] = 'SELECT count(distinct(topic_id)) FROM `' . BB_BT_TRACKER_SNAP . '` WHERE seeders > 5';
+$sql[] = 'SELECT count(distinct(poster_id)) FROM `' . BB_BT_TORRENTS . '`';
+$sql[] = 'SELECT count(distinct(poster_id)) FROM `' . BB_BT_TORRENTS . '` WHERE reg_time >= UNIX_TIMESTAMP()-2592000';
echo '';
-echo '
-
-';
+echo '';
-foreach ($sql as $i => $query)
-{
- $row = mysql_fetch_row(DB()->query($query));
- echo "{$lang['TR_STATS'][$i]} {$row[0]} ";
+foreach ($sql as $i => $query) {
+ $result = DB()->fetch_row($query);
+ $row = array_values($result)[0]; // Get first column value
+ $row = ($i == 2) ? humn_size($row) : $row;
+ echo "{$lang['TR_STATS'][$i]} $row ";
}
echo '
';
-
echo '';
-if ($l = sys('la'))
-{
- $l = explode(' ', $l);
- for ($i=0; $i < 3; $i++)
- {
- $l[$i] = round($l[$i], 1);
- }
- echo "\n\nloadavg: $l[0] $l[1] $l[2]\n\n";
-}
-
-echo 'gen time: '. sprintf('%.3f', (array_sum(explode(' ', microtime())) - TIMESTART)) ." sec\n";
+echo 'gen time: ' . sprintf('%.3f', array_sum(explode(' ', microtime())) - TIMESTART) . " sec\n";
echo ' ';
-echo '';
\ No newline at end of file
+echo '