Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8e0ead48bf | ||
| 9624271935 | |||
|
|
61bf43e842 | ||
|
|
053830ac93 | ||
|
|
2e427ed0ff | ||
| 3f3a44d8c1 | |||
|
|
013f19b97b | ||
|
|
4e0967602e | ||
| 672cdb56a0 |
@@ -5,9 +5,6 @@ on:
|
|||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
schedule:
|
|
||||||
- cron: '28 5 * * *'
|
|
||||||
# workflow_run support in Gitea can be tricky, keeping it but might need adjustment
|
|
||||||
workflow_run:
|
workflow_run:
|
||||||
workflows: ["Sync Repo"]
|
workflows: ["Sync Repo"]
|
||||||
types:
|
types:
|
||||||
@@ -19,7 +16,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container:
|
container:
|
||||||
image: catthehacker/ubuntu:act-latest
|
image: catthehacker/ubuntu:act-latest
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
packages: write
|
packages: write
|
||||||
@@ -139,7 +136,7 @@ jobs:
|
|||||||
LATEST_RELEASE_TAG=$(curl -sL -H "Accept: application/json" \
|
LATEST_RELEASE_TAG=$(curl -sL -H "Accept: application/json" \
|
||||||
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
||||||
"${{ gitea.api_url }}/repos/${{ gitea.repository }}/releases/latest" | jq -r .tag_name)
|
"${{ gitea.api_url }}/repos/${{ gitea.repository }}/releases/latest" | jq -r .tag_name)
|
||||||
|
|
||||||
if [ -z "$LATEST_RELEASE_TAG" ] || [ "$LATEST_RELEASE_TAG" = "null" ]; then
|
if [ -z "$LATEST_RELEASE_TAG" ] || [ "$LATEST_RELEASE_TAG" = "null" ]; then
|
||||||
LATEST_RELEASE_TAG="v1.0.0"
|
LATEST_RELEASE_TAG="v1.0.0"
|
||||||
fi
|
fi
|
||||||
@@ -245,7 +242,7 @@ jobs:
|
|||||||
AUTHOR="Ivan Carlos"
|
AUTHOR="Ivan Carlos"
|
||||||
VERSION_FILE="manifest.json"
|
VERSION_FILE="manifest.json"
|
||||||
UPSTREAM_SHA="${{ steps.check_upstream.outputs.upstream_sha }}"
|
UPSTREAM_SHA="${{ steps.check_upstream.outputs.upstream_sha }}"
|
||||||
|
|
||||||
if [ -f "$VERSION_FILE" ]; then
|
if [ -f "$VERSION_FILE" ]; then
|
||||||
jq --arg v "$VERSION" \
|
jq --arg v "$VERSION" \
|
||||||
--arg a "$AUTHOR" \
|
--arg a "$AUTHOR" \
|
||||||
@@ -265,6 +262,11 @@ jobs:
|
|||||||
git commit -m "Update manifest version to ${{ steps.version.outputs.VERSION }} [▶️]" || echo "Nothing to commit"
|
git commit -m "Update manifest version to ${{ steps.version.outputs.VERSION }} [▶️]" || echo "Nothing to commit"
|
||||||
git push origin main
|
git push origin main
|
||||||
|
|
||||||
|
- name: 🛠 Install zip
|
||||||
|
if: steps.check_commits.outputs.commit_count != '0'
|
||||||
|
run: |
|
||||||
|
apt-get update && apt-get install -y zip
|
||||||
|
|
||||||
- name: 📦 Create ZIP package (excluding certain files)
|
- name: 📦 Create ZIP package (excluding certain files)
|
||||||
if: steps.check_commits.outputs.commit_count != '0'
|
if: steps.check_commits.outputs.commit_count != '0'
|
||||||
run: |
|
run: |
|
||||||
@@ -279,11 +281,11 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
TAG_NAME="v${{ steps.version.outputs.VERSION }}"
|
TAG_NAME="v${{ steps.version.outputs.VERSION }}"
|
||||||
RELEASE_NAME="${{ steps.version.outputs.REPO_NAME }} v${{ steps.version.outputs.VERSION }}"
|
RELEASE_NAME="${{ steps.version.outputs.REPO_NAME }} v${{ steps.version.outputs.VERSION }}"
|
||||||
|
|
||||||
# Construct Markdown body safely using env var
|
# Construct Markdown body safely using env var
|
||||||
# We use printf to avoid interpreting backslashes in the file list
|
# We use printf to avoid interpreting backslashes in the file list
|
||||||
BODY=$(printf "### Changelog\nFiles changed in this release:\n%s" "$CHANGELOG_LIST")
|
BODY=$(printf "### Changelog\nFiles changed in this release:\n%s" "$CHANGELOG_LIST")
|
||||||
|
|
||||||
# Create JSON payload using jq
|
# Create JSON payload using jq
|
||||||
jq -n \
|
jq -n \
|
||||||
--arg tag_name "$TAG_NAME" \
|
--arg tag_name "$TAG_NAME" \
|
||||||
@@ -299,13 +301,13 @@ jobs:
|
|||||||
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d @release_payload.json > api_response.json
|
-d @release_payload.json > api_response.json
|
||||||
|
|
||||||
echo "DEBUG: API Response:"
|
echo "DEBUG: API Response:"
|
||||||
cat api_response.json || true
|
cat api_response.json || true
|
||||||
|
|
||||||
RELEASE_ID=$(jq -r .id api_response.json)
|
RELEASE_ID=$(jq -r .id api_response.json)
|
||||||
echo "RELEASE_ID=$RELEASE_ID" >> "$GITHUB_OUTPUT"
|
echo "RELEASE_ID=$RELEASE_ID" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
if [ "$RELEASE_ID" == "null" ] || [ -z "$RELEASE_ID" ]; then
|
if [ "$RELEASE_ID" == "null" ] || [ -z "$RELEASE_ID" ]; then
|
||||||
echo "Failed to create release. Response content:"
|
echo "Failed to create release. Response content:"
|
||||||
cat api_response.json
|
cat api_response.json
|
||||||
@@ -318,19 +320,18 @@ jobs:
|
|||||||
RELEASE_ID="${{ steps.create_release.outputs.RELEASE_ID }}"
|
RELEASE_ID="${{ steps.create_release.outputs.RELEASE_ID }}"
|
||||||
ZIP_NAME="${{ steps.version.outputs.ZIP_NAME }}"
|
ZIP_NAME="${{ steps.version.outputs.ZIP_NAME }}"
|
||||||
FILE_PATH="./$ZIP_NAME"
|
FILE_PATH="./$ZIP_NAME"
|
||||||
|
|
||||||
curl -s -X POST "${{ gitea.api_url }}/repos/${{ gitea.repository }}/releases/$RELEASE_ID/assets" \
|
curl --fail -s -X POST "${{ gitea.api_url }}/repos/${{ gitea.repository }}/releases/$RELEASE_ID/assets?name=$ZIP_NAME" \
|
||||||
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
||||||
-H "Content-Type: application/zip" \
|
-H "Content-Type: application/zip" \
|
||||||
--data-binary @"$FILE_PATH" \
|
--data-binary @"$FILE_PATH"
|
||||||
-o /dev/null
|
|
||||||
|
|
||||||
# ----- Docker steps -----
|
# ----- Docker steps -----
|
||||||
- name: Clone Upstream Code (if needed)
|
- name: Clone Upstream Code (if needed)
|
||||||
if: steps.check_commits.outputs.commit_count != '0' && (steps.check_upstream.outputs.upstream_needs_update == 'true' || steps.check_upstream.outputs.repo_url != '')
|
if: steps.check_commits.outputs.commit_count != '0' && (steps.check_upstream.outputs.upstream_needs_update == 'true' || steps.check_upstream.outputs.repo_url != '')
|
||||||
run: |
|
run: |
|
||||||
rm -rf upstream_src
|
rm -rf upstream_src
|
||||||
git clone --depth 1 --branch ${{ steps.check_upstream.outputs.repo_branch }} ${{ steps.check_upstream.outputs.repo_url }} upstream_src
|
git clone --depth 1 --branch ${{ steps.check_upstream.outputs.repo_branch }} ${{ steps.check_upstream.outputs.repo_url }} upstream_src
|
||||||
|
|
||||||
- name: 🔍 Check if Dockerfile exists
|
- name: 🔍 Check if Dockerfile exists
|
||||||
if: steps.check_commits.outputs.commit_count != '0' || steps.check_upstream.outputs.upstream_needs_update == 'true'
|
if: steps.check_commits.outputs.commit_count != '0' || steps.check_upstream.outputs.upstream_needs_update == 'true'
|
||||||
|
|||||||
59
.gitea/workflows/update_readme.yml
Normal file
59
.gitea/workflows/update_readme.yml
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
name: Update README
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
schedule:
|
||||||
|
- cron: "0 4 * * *" # Every day at 4 AM UTC
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
update-readme:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: catthehacker/ubuntu:act-latest
|
||||||
|
|
||||||
|
env:
|
||||||
|
SOURCE_REPO: ivancarlos/.gitea
|
||||||
|
SOURCE_BRANCH: main
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout current repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Checkout source README template
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
repository: ${{ env.SOURCE_REPO }}
|
||||||
|
ref: ${{ env.SOURCE_BRANCH }}
|
||||||
|
token: ${{ secrets.CR_PAT }}
|
||||||
|
path: source_readme
|
||||||
|
|
||||||
|
- name: Update README.md (footer only)
|
||||||
|
run: |
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# --- Extract footer block from source (everything from <!-- footer --> onward) ---
|
||||||
|
FOOTER=$(awk '/<!-- footer -->/{flag=1}flag' source_readme/README.md)
|
||||||
|
|
||||||
|
# --- Replace everything after <!-- footer --> with FOOTER ---
|
||||||
|
awk -v footer="$FOOTER" '
|
||||||
|
/<!-- footer -->/ {
|
||||||
|
print footer
|
||||||
|
found=1
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
{ print }
|
||||||
|
' README.md > README.tmp && mv README.tmp README.md
|
||||||
|
|
||||||
|
- name: Remove source_readme from git index
|
||||||
|
run: rm -rf source_readme
|
||||||
|
|
||||||
|
- name: Commit and push changes
|
||||||
|
run: |
|
||||||
|
git config user.name "Gitea Actions"
|
||||||
|
git config user.email "actions@git.icc.gg"
|
||||||
|
git add README.md
|
||||||
|
git commit -m "Sync README from template [▶️]" || echo "Nothing to commit"
|
||||||
|
git push origin ${{ github.ref_name }}
|
||||||
14
README.md
14
README.md
@@ -60,17 +60,9 @@ input {
|
|||||||
## 🩷 Project support
|
## 🩷 Project support
|
||||||
| If you found this project helpful, consider |
|
| If you found this project helpful, consider |
|
||||||
| :---: |
|
| :---: |
|
||||||
[**buying me a coffee**][buymeacoffee], [**donate by paypal**][paypal], [**sponsor this project**][sponsor] or just [**leave a star**](../..)⭐
|
[**buying me a coffee**][buymeacoffee] or [**supporting me on Patreon**][patreon]
|
||||||
|Thanks for your support, it is much appreciated!|
|
|Thanks for your support, it is much appreciated!|
|
||||||
|
|
||||||
[cc]: https://docs.github.com/en/communities/setting-up-your-project-for-healthy-contributions/adding-a-code-of-conduct-to-your-project
|
[ivancarlos]: https://ivancarlos.me
|
||||||
[contributing]: https://docs.github.com/en/articles/setting-guidelines-for-repository-contributors
|
|
||||||
[security]: https://docs.github.com/en/code-security/getting-started/adding-a-security-policy-to-your-repository
|
|
||||||
[support]: https://docs.github.com/en/articles/adding-support-resources-to-your-project
|
|
||||||
[it]: https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/configuring-issue-templates-for-your-repository#configuring-the-template-chooser
|
|
||||||
[prt]: https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/creating-a-pull-request-template-for-your-repository
|
|
||||||
[funding]: https://docs.github.com/en/articles/displaying-a-sponsor-button-in-your-repository
|
|
||||||
[ivancarlos]: https://ivancarlos.it
|
|
||||||
[buymeacoffee]: https://www.buymeacoffee.com/ivancarlos
|
[buymeacoffee]: https://www.buymeacoffee.com/ivancarlos
|
||||||
[paypal]: https://icc.gg/donate
|
[patreon]: https://patreon.com/ivancarlos
|
||||||
[sponsor]: https://github.com/sponsors/ivancarlosti
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
"version": "1.3.0",
|
"version": "1.4.1",
|
||||||
"author": "Ivan Carlos"
|
"author": "Ivan Carlos"
|
||||||
}
|
}
|
||||||
|
|||||||
327
plugin.php
327
plugin.php
@@ -2,37 +2,46 @@
|
|||||||
/*
|
/*
|
||||||
Plugin Name: ICC Webmaster Settings
|
Plugin Name: ICC Webmaster Settings
|
||||||
Plugin URI: https://github.com/ivancarlosti/yourlsiccwebmastersettings
|
Plugin URI: https://github.com/ivancarlosti/yourlsiccwebmastersettings
|
||||||
Description: Change Logo, Title, Page Footer, add custom CSS, and customize favicon lines
|
Description: Customize Logo, Title, Footer, CSS & Favicons. Add reCAPTCHA v3, Meta Redirects (delayed), and Force 302 Redirects.
|
||||||
Version: 1.01
|
Version: 2.0
|
||||||
Author: Ivan Carlos
|
Author: Ivan Carlos
|
||||||
Author URI: https://ivancarlos.com.br/
|
Author URI: https://ivancarlos.com.br/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// No direct call
|
// No direct call
|
||||||
if( !defined( 'YOURLS_ABSPATH' ) ) die();
|
if (!defined('YOURLS_ABSPATH'))
|
||||||
|
die();
|
||||||
|
|
||||||
|
// Default redirect delay in seconds (used when option unset)
|
||||||
|
define('ICC_MRDR_DEFAULT_DELAY', 1);
|
||||||
|
|
||||||
// Register unified config page
|
// Register unified config page
|
||||||
yourls_add_action( 'plugins_loaded', 'icc_config_add_page' );
|
yourls_add_action('plugins_loaded', 'icc_config_add_page');
|
||||||
function icc_config_add_page() {
|
function icc_config_add_page()
|
||||||
yourls_register_plugin_page( 'icc_logo_title_footer_favicon_config', 'Webmaster Settings', 'icc_config_do_page' );
|
{
|
||||||
|
yourls_register_plugin_page('icc_logo_title_footer_favicon_config', 'Webmaster Settings', 'icc_config_do_page');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle and display unified config page
|
// Handle and display unified config page
|
||||||
function icc_config_do_page() {
|
function icc_config_do_page()
|
||||||
if( isset( $_POST['icc_submit'] ) ) icc_config_update_option();
|
{
|
||||||
|
if (isset($_POST['icc_submit']))
|
||||||
|
icc_config_update_option();
|
||||||
|
|
||||||
// Options
|
// Options
|
||||||
$icc_logo_imageurl = yourls_get_option( 'icc_logo_imageurl' );
|
$icc_logo_imageurl = yourls_get_option('icc_logo_imageurl');
|
||||||
$icc_logo_imageurl_tag = yourls_get_option( 'icc_logo_imageurl_tag' );
|
$icc_logo_imageurl_tag = yourls_get_option('icc_logo_imageurl_tag');
|
||||||
$icc_logo_imageurl_title = yourls_get_option( 'icc_logo_imageurl_title' );
|
$icc_logo_imageurl_title = yourls_get_option('icc_logo_imageurl_title');
|
||||||
$icc_title_custom = yourls_get_option( 'icc_title_custom' );
|
$icc_title_custom = yourls_get_option('icc_title_custom');
|
||||||
$icc_footer_text = yourls_get_option( 'icc_footer_text' );
|
$icc_footer_text = yourls_get_option('icc_footer_text');
|
||||||
if ($icc_footer_text === false) $icc_footer_text = '';
|
if ($icc_footer_text === false)
|
||||||
|
$icc_footer_text = '';
|
||||||
$footer_text_escaped = htmlspecialchars($icc_footer_text);
|
$footer_text_escaped = htmlspecialchars($icc_footer_text);
|
||||||
|
|
||||||
// Custom CSS option
|
// Custom CSS option
|
||||||
$icc_custom_css = yourls_get_option( 'icc_custom_css' );
|
$icc_custom_css = yourls_get_option('icc_custom_css');
|
||||||
if ($icc_custom_css === false) $icc_custom_css = '';
|
if ($icc_custom_css === false)
|
||||||
|
$icc_custom_css = '';
|
||||||
$custom_css_escaped = htmlspecialchars($icc_custom_css);
|
$custom_css_escaped = htmlspecialchars($icc_custom_css);
|
||||||
|
|
||||||
$defaults = [
|
$defaults = [
|
||||||
@@ -43,13 +52,36 @@ function icc_config_do_page() {
|
|||||||
$favicon_options = [];
|
$favicon_options = [];
|
||||||
foreach ($defaults as $key => $default_value) {
|
foreach ($defaults as $key => $default_value) {
|
||||||
$val = yourls_get_option($key);
|
$val = yourls_get_option($key);
|
||||||
if ($val === false) $val = $default_value;
|
if ($val === false)
|
||||||
|
$val = $default_value;
|
||||||
$favicon_options[$key] = $val;
|
$favicon_options[$key] = $val;
|
||||||
}
|
}
|
||||||
$escape_attr = function($str) {
|
|
||||||
|
// reCAPTCHA options
|
||||||
|
$icc_recaptcha_enabled = yourls_get_option('icc_recaptcha_enabled');
|
||||||
|
$icc_recaptcha_site_key = yourls_get_option('icc_recaptcha_site_key');
|
||||||
|
$icc_recaptcha_secret_key = yourls_get_option('icc_recaptcha_secret_key');
|
||||||
|
|
||||||
|
$recaptcha_checked = $icc_recaptcha_enabled ? 'checked' : '';
|
||||||
|
$escape_attr = function ($str) {
|
||||||
return htmlspecialchars($str, ENT_QUOTES | ENT_HTML5);
|
return htmlspecialchars($str, ENT_QUOTES | ENT_HTML5);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Meta Redirect options
|
||||||
|
$icc_mrdr_url_prefix = yourls_get_option('icc_mrdr_url_prefix');
|
||||||
|
if ($icc_mrdr_url_prefix === false)
|
||||||
|
$icc_mrdr_url_prefix = '.';
|
||||||
|
|
||||||
|
$icc_mrdr_delay = yourls_get_option('icc_mrdr_delay');
|
||||||
|
if ($icc_mrdr_delay === false || !is_numeric($icc_mrdr_delay) || (int) $icc_mrdr_delay < 0) {
|
||||||
|
$icc_mrdr_delay = ICC_MRDR_DEFAULT_DELAY;
|
||||||
|
}
|
||||||
|
$escaped_delay = (int) $icc_mrdr_delay;
|
||||||
|
|
||||||
|
// 302 Redirect options
|
||||||
|
$icc_302_redirect_enabled = yourls_get_option('icc_302_redirect_enabled');
|
||||||
|
$redirect_302_checked = $icc_302_redirect_enabled ? 'checked' : '';
|
||||||
|
|
||||||
echo <<<HTML
|
echo <<<HTML
|
||||||
<h2>Webmaster Settings</h2>
|
<h2>Webmaster Settings</h2>
|
||||||
<form method="post">
|
<form method="post">
|
||||||
@@ -82,6 +114,35 @@ function icc_config_do_page() {
|
|||||||
<p><label for="favicon_shortcut_icon" style="display: inline-block; width: 200px;">Shortcut Icon (favicon.ico) URL</label>
|
<p><label for="favicon_shortcut_icon" style="display: inline-block; width: 200px;">Shortcut Icon (favicon.ico) URL</label>
|
||||||
<input type="text" id="favicon_shortcut_icon" name="favicon_shortcut_icon" value="{$escape_attr($favicon_options['favicon_shortcut_icon'])}" size="80" /></p>
|
<input type="text" id="favicon_shortcut_icon" name="favicon_shortcut_icon" value="{$escape_attr($favicon_options['favicon_shortcut_icon'])}" size="80" /></p>
|
||||||
|
|
||||||
|
<h3>reCAPTCHA v3 Settings</h3>
|
||||||
|
<p>
|
||||||
|
<label for="icc_recaptcha_enabled" style="display: inline-block; width: 200px;">Enable reCAPTCHA v3</label>
|
||||||
|
<input type="checkbox" id="icc_recaptcha_enabled" name="icc_recaptcha_enabled" value="1" {$recaptcha_checked} />
|
||||||
|
</p>
|
||||||
|
<p><label for="icc_recaptcha_site_key" style="display: inline-block; width: 200px;">Site Key</label>
|
||||||
|
<input type="text" id="icc_recaptcha_site_key" name="icc_recaptcha_site_key" value="{$escape_attr($icc_recaptcha_site_key)}" size="80" placeholder="Required if enabled" /></p>
|
||||||
|
<p><label for="icc_recaptcha_secret_key" style="display: inline-block; width: 200px;">Secret Key</label>
|
||||||
|
<input type="text" id="icc_recaptcha_secret_key" name="icc_recaptcha_secret_key" value="{$escape_attr($icc_recaptcha_secret_key)}" size="80" placeholder="Required if enabled" /></p>
|
||||||
|
|
||||||
|
<h3>Meta Redirect Settings</h3>
|
||||||
|
<p>
|
||||||
|
<label for="icc_mrdr_url_prefix" style="display:inline-block; width:200px;">Redirect Prefix Character</label>
|
||||||
|
<input type="text" id="icc_mrdr_url_prefix" name="icc_mrdr_url_prefix" value="{$escape_attr($icc_mrdr_url_prefix)}" maxlength="1" size="80" />
|
||||||
|
<br><span style="padding-left: 205px;"><small>Single character prefix to trigger meta redirect. Default is a dot (.)</small></span>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<label for="icc_mrdr_delay" style="display:inline-block; width:200px;">Redirect Delay (seconds)</label>
|
||||||
|
<input type="number" id="icc_mrdr_delay" name="icc_mrdr_delay" value="{$escaped_delay}" min="0" step="1" size="80" />
|
||||||
|
<br><span style="padding-left: 205px;"><small>Delay before redirecting. Default is 1 second. Use 0 for immediate redirect.</small></span>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h3>Redirect Code Settings</h3>
|
||||||
|
<p>
|
||||||
|
<label for="icc_302_redirect_enabled" style="display: inline-block; width: 200px;">Force 302 Redirect</label>
|
||||||
|
<input type="checkbox" id="icc_302_redirect_enabled" name="icc_302_redirect_enabled" value="1" {$redirect_302_checked} />
|
||||||
|
<br><span style="padding-left: 205px;"><small>Use 302 (Temporary) instead of 301 (Permanent) for standard redirects.</small></span>
|
||||||
|
</p>
|
||||||
|
|
||||||
<p><input type="submit" name="icc_submit" value="Update values" /></p>
|
<p><input type="submit" name="icc_submit" value="Update values" /></p>
|
||||||
</form>
|
</form>
|
||||||
<hr style="margin-top: 40px" />
|
<hr style="margin-top: 40px" />
|
||||||
@@ -92,75 +153,253 @@ HTML;
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update options
|
// Update options
|
||||||
function icc_config_update_option() {
|
function icc_config_update_option()
|
||||||
|
{
|
||||||
$fields_logo = ['icc_logo_imageurl', 'icc_logo_imageurl_tag', 'icc_logo_imageurl_title'];
|
$fields_logo = ['icc_logo_imageurl', 'icc_logo_imageurl_tag', 'icc_logo_imageurl_title'];
|
||||||
foreach ($fields_logo as $key) {
|
foreach ($fields_logo as $key) {
|
||||||
if (isset($_POST[$key])) yourls_update_option($key, strval($_POST[$key]));
|
if (isset($_POST[$key]))
|
||||||
|
yourls_update_option($key, strval($_POST[$key]));
|
||||||
}
|
}
|
||||||
if (isset($_POST['icc_title_custom'])) yourls_update_option('icc_title_custom', strval($_POST['icc_title_custom']));
|
if (isset($_POST['icc_title_custom']))
|
||||||
if (isset($_POST['icc_footer_text'])) yourls_update_option('icc_footer_text', $_POST['icc_footer_text']);
|
yourls_update_option('icc_title_custom', strval($_POST['icc_title_custom']));
|
||||||
if (isset($_POST['icc_custom_css'])) yourls_update_option('icc_custom_css', $_POST['icc_custom_css']);
|
if (isset($_POST['icc_footer_text']))
|
||||||
$fields_favicon = ['favicon_icon32','favicon_icon16','favicon_shortcut_icon'];
|
yourls_update_option('icc_footer_text', $_POST['icc_footer_text']);
|
||||||
|
if (isset($_POST['icc_custom_css']))
|
||||||
|
yourls_update_option('icc_custom_css', $_POST['icc_custom_css']);
|
||||||
|
$fields_favicon = ['favicon_icon32', 'favicon_icon16', 'favicon_shortcut_icon'];
|
||||||
foreach ($fields_favicon as $key) {
|
foreach ($fields_favicon as $key) {
|
||||||
if (isset($_POST[$key])) yourls_update_option($key, strval($_POST[$key]));
|
if (isset($_POST[$key]))
|
||||||
|
yourls_update_option($key, strval($_POST[$key]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// reCAPTCHA update
|
||||||
|
$recaptcha_enabled = isset($_POST['icc_recaptcha_enabled']);
|
||||||
|
$site_key = isset($_POST['icc_recaptcha_site_key']) ? trim($_POST['icc_recaptcha_site_key']) : '';
|
||||||
|
$secret_key = isset($_POST['icc_recaptcha_secret_key']) ? trim($_POST['icc_recaptcha_secret_key']) : '';
|
||||||
|
|
||||||
|
if ($recaptcha_enabled && (empty($site_key) || empty($secret_key))) {
|
||||||
|
echo '<div class="error"><p><strong>Error:</strong> both Site Key and Secret Key are required to enable reCAPTCHA.</p></div>';
|
||||||
|
// Do not update enabled status if validation fails
|
||||||
|
} else {
|
||||||
|
yourls_update_option('icc_recaptcha_enabled', $recaptcha_enabled);
|
||||||
|
yourls_update_option('icc_recaptcha_site_key', $site_key);
|
||||||
|
yourls_update_option('icc_recaptcha_secret_key', $secret_key);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Meta Redirect update
|
||||||
|
if (isset($_POST['icc_mrdr_url_prefix'])) {
|
||||||
|
$prefix = substr(trim($_POST['icc_mrdr_url_prefix']), 0, 1);
|
||||||
|
if ($prefix === '') {
|
||||||
|
yourls_delete_option('icc_mrdr_url_prefix');
|
||||||
|
} else {
|
||||||
|
yourls_update_option('icc_mrdr_url_prefix', $prefix);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isset($_POST['icc_mrdr_delay'])) {
|
||||||
|
$delay = intval($_POST['icc_mrdr_delay']);
|
||||||
|
if ($delay < 0)
|
||||||
|
$delay = ICC_MRDR_DEFAULT_DELAY;
|
||||||
|
yourls_update_option('icc_mrdr_delay', $delay);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 302 Redirect update
|
||||||
|
$redirect_302_enabled = isset($_POST['icc_302_redirect_enabled']);
|
||||||
|
yourls_update_option('icc_302_redirect_enabled', $redirect_302_enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show custom logo
|
// Show custom logo
|
||||||
yourls_add_filter( 'pre_html_logo', 'icc_hideoriginallogo' );
|
yourls_add_filter('pre_html_logo', 'icc_hideoriginallogo');
|
||||||
function icc_hideoriginallogo() {
|
function icc_hideoriginallogo()
|
||||||
|
{
|
||||||
echo '<span id="hideYourlsLogo" style="display:none">';
|
echo '<span id="hideYourlsLogo" style="display:none">';
|
||||||
}
|
}
|
||||||
yourls_add_filter( 'html_logo', 'icc_logo' );
|
yourls_add_filter('html_logo', 'icc_logo');
|
||||||
function icc_logo() {
|
function icc_logo()
|
||||||
|
{
|
||||||
echo '</span>';
|
echo '</span>';
|
||||||
echo '<h1 id="yourls.logo">';
|
echo '<h1 id="yourls.logo">';
|
||||||
echo '<a href="'.yourls_admin_url( 'index.php' ).'" title="'.yourls_get_option( 'icc_logo_imageurl_title' ).'"><span>';
|
echo '<a href="' . yourls_admin_url('index.php') . '" title="' . yourls_get_option('icc_logo_imageurl_title') . '"><span>';
|
||||||
echo '<img src="'.yourls_get_option( 'icc_logo_imageurl' ).'" alt="'.yourls_get_option( 'icc_logo_imageurl_tag' ).'" title="'.yourls_get_option( 'icc_logo_imageurl_title' ).'" border="0" style="border: 0px; max-width: 100px;" /></a>';
|
echo '<img src="' . yourls_get_option('icc_logo_imageurl') . '" alt="' . yourls_get_option('icc_logo_imageurl_tag') . '" title="' . yourls_get_option('icc_logo_imageurl_title') . '" border="0" style="border: 0px; max-width: 100px;" /></a>';
|
||||||
echo '</h1>';
|
echo '</h1>';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show custom title
|
// Show custom title
|
||||||
yourls_add_filter( 'html_title', 'icc_change_title' );
|
yourls_add_filter('html_title', 'icc_change_title');
|
||||||
function icc_change_title( $value ) {
|
function icc_change_title($value)
|
||||||
$custom = yourls_get_option( 'icc_title_custom' );
|
{
|
||||||
if ($custom !== '') return $custom;
|
$custom = yourls_get_option('icc_title_custom');
|
||||||
|
if ($custom !== '')
|
||||||
|
return $custom;
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replace footer text with custom footer from option
|
// Replace footer text with custom footer from option
|
||||||
yourls_add_filter( 'html_footer_text', 'icc_change_footer' );
|
yourls_add_filter('html_footer_text', 'icc_change_footer');
|
||||||
function icc_change_footer( $value ) {
|
function icc_change_footer($value)
|
||||||
$custom_footer = yourls_get_option( 'icc_footer_text' );
|
{
|
||||||
if ( !empty($custom_footer) ) return $custom_footer;
|
$custom_footer = yourls_get_option('icc_footer_text');
|
||||||
|
if (!empty($custom_footer))
|
||||||
|
return $custom_footer;
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Output favicon lines (only if set)
|
// Output favicon lines (only if set)
|
||||||
yourls_add_filter('shunt_html_favicon', 'icc_plugin_favicon');
|
yourls_add_filter('shunt_html_favicon', 'icc_plugin_favicon');
|
||||||
function icc_plugin_favicon() {
|
function icc_plugin_favicon()
|
||||||
|
{
|
||||||
$opts = [
|
$opts = [
|
||||||
'favicon_icon32' => yourls_get_option('favicon_icon32'),
|
'favicon_icon32' => yourls_get_option('favicon_icon32'),
|
||||||
'favicon_icon16' => yourls_get_option('favicon_icon16'),
|
'favicon_icon16' => yourls_get_option('favicon_icon16'),
|
||||||
'favicon_shortcut_icon' => yourls_get_option('favicon_shortcut_icon'),
|
'favicon_shortcut_icon' => yourls_get_option('favicon_shortcut_icon'),
|
||||||
];
|
];
|
||||||
if (!empty($opts['favicon_icon32'])) {
|
if (!empty($opts['favicon_icon32'])) {
|
||||||
echo '<link rel="icon" type="image/png" sizes="32x32" href="' . htmlspecialchars($opts['favicon_icon32'], ENT_QUOTES | ENT_HTML5) . '">'."\n";
|
echo '<link rel="icon" type="image/png" sizes="32x32" href="' . htmlspecialchars($opts['favicon_icon32'], ENT_QUOTES | ENT_HTML5) . '">' . "\n";
|
||||||
}
|
}
|
||||||
if (!empty($opts['favicon_icon16'])) {
|
if (!empty($opts['favicon_icon16'])) {
|
||||||
echo '<link rel="icon" type="image/png" sizes="16x16" href="' . htmlspecialchars($opts['favicon_icon16'], ENT_QUOTES | ENT_HTML5) . '">'."\n";
|
echo '<link rel="icon" type="image/png" sizes="16x16" href="' . htmlspecialchars($opts['favicon_icon16'], ENT_QUOTES | ENT_HTML5) . '">' . "\n";
|
||||||
}
|
}
|
||||||
if (!empty($opts['favicon_shortcut_icon'])) {
|
if (!empty($opts['favicon_shortcut_icon'])) {
|
||||||
echo '<link rel="shortcut icon" href="' . htmlspecialchars($opts['favicon_shortcut_icon'], ENT_QUOTES | ENT_HTML5) . '">'."\n";
|
echo '<link rel="shortcut icon" href="' . htmlspecialchars($opts['favicon_shortcut_icon'], ENT_QUOTES | ENT_HTML5) . '">' . "\n";
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Output custom CSS if set
|
// Output custom CSS if set
|
||||||
yourls_add_action('html_head', 'icc_print_custom_css');
|
yourls_add_action('html_head', 'icc_print_custom_css');
|
||||||
function icc_print_custom_css() {
|
function icc_print_custom_css()
|
||||||
|
{
|
||||||
$css = yourls_get_option('icc_custom_css');
|
$css = yourls_get_option('icc_custom_css');
|
||||||
if ($css !== false && trim($css) !== '') {
|
if ($css !== false && trim($css) !== '') {
|
||||||
echo "<style>\n" . $css . "\n</style>\n";
|
echo "<style>\n" . $css . "\n</style>\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// reCAPTCHA v3 Integration
|
||||||
|
yourls_add_action('html_head', 'icc_recaptcha_v3_html_head');
|
||||||
|
function icc_recaptcha_v3_html_head()
|
||||||
|
{
|
||||||
|
if (!yourls_get_option('icc_recaptcha_enabled'))
|
||||||
|
return;
|
||||||
|
$site_key = yourls_get_option('icc_recaptcha_site_key');
|
||||||
|
if ($site_key) {
|
||||||
|
echo '<script src="https://www.google.com/recaptcha/api.js?render=' . htmlspecialchars($site_key, ENT_QUOTES) . '"></script>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
yourls_add_action('login_form_bottom', 'icc_recaptcha_v3_login_form');
|
||||||
|
function icc_recaptcha_v3_login_form()
|
||||||
|
{
|
||||||
|
if (!yourls_get_option('icc_recaptcha_enabled'))
|
||||||
|
return;
|
||||||
|
echo '<div id="recaptcha"></div>';
|
||||||
|
echo '<input type="hidden" name="token" id="tokenInput">';
|
||||||
|
}
|
||||||
|
|
||||||
|
yourls_add_action('login_form_end', 'icc_recaptcha_v3_inject_script');
|
||||||
|
function icc_recaptcha_v3_inject_script()
|
||||||
|
{
|
||||||
|
if (!yourls_get_option('icc_recaptcha_enabled'))
|
||||||
|
return;
|
||||||
|
$site_key = yourls_get_option('icc_recaptcha_site_key');
|
||||||
|
if ($site_key) {
|
||||||
|
echo '<script>
|
||||||
|
grecaptcha.ready(function() {
|
||||||
|
grecaptcha.execute(\'' . htmlspecialchars($site_key, ENT_QUOTES) . '\', {action: \'submit\'}).then(function(token) {
|
||||||
|
document.getElementById(\'tokenInput\').value = token;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
yourls_add_action('pre_login_username_password', 'icc_recaptcha_v3_validation');
|
||||||
|
function icc_recaptcha_v3_validation()
|
||||||
|
{
|
||||||
|
if (!yourls_get_option('icc_recaptcha_enabled'))
|
||||||
|
return;
|
||||||
|
|
||||||
|
$site_key = yourls_get_option('icc_recaptcha_site_key');
|
||||||
|
$secret_key = yourls_get_option('icc_recaptcha_secret_key');
|
||||||
|
|
||||||
|
if (empty($site_key) || empty($secret_key))
|
||||||
|
return; // Should not happen if validation works, but safety net
|
||||||
|
|
||||||
|
$token = isset($_POST['token']) ? $_POST['token'] : '';
|
||||||
|
|
||||||
|
// call curl to POST request
|
||||||
|
$ch = curl_init();
|
||||||
|
curl_setopt($ch, CURLOPT_URL, "https://www.google.com/recaptcha/api/siteverify");
|
||||||
|
curl_setopt($ch, CURLOPT_POST, 1);
|
||||||
|
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array('secret' => $secret_key, 'response' => $token)));
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
$response = curl_exec($ch);
|
||||||
|
curl_close($ch);
|
||||||
|
$arrResponse = json_decode($response, true);
|
||||||
|
|
||||||
|
// verify the response
|
||||||
|
if (isset($arrResponse["success"]) && $arrResponse["success"] == '1' && isset($arrResponse["score"]) && $arrResponse["score"] >= 0.5) {
|
||||||
|
// reCAPTCHA succeeded
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
// reCAPTCHA failed
|
||||||
|
yourls_login_screen($error_msg = 'reCAPTCHA verification failed');
|
||||||
|
yourls_die('reCAPTCHA verification failed. Please try again.');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Meta Redirect Logic
|
||||||
|
yourls_add_action('loader_failed', 'icc_mrdr_redirect');
|
||||||
|
function icc_mrdr_redirect($args)
|
||||||
|
{
|
||||||
|
// Get prefix from option or fallback default
|
||||||
|
$prefix = yourls_get_option('icc_mrdr_url_prefix');
|
||||||
|
if ($prefix === false || $prefix === '') {
|
||||||
|
$prefix = '.';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get delay from option or fallback default
|
||||||
|
$delay = yourls_get_option('icc_mrdr_delay');
|
||||||
|
if ($delay === false || !is_numeric($delay) || (int) $delay < 0) {
|
||||||
|
$delay = ICC_MRDR_DEFAULT_DELAY;
|
||||||
|
}
|
||||||
|
$delay = (int) $delay;
|
||||||
|
|
||||||
|
// Escape prefix safely for regex
|
||||||
|
$escaped_prefix = preg_quote($prefix, '!');
|
||||||
|
|
||||||
|
// Check if requested keyword starts with prefix
|
||||||
|
if (isset($args[0]) && preg_match('!^' . $escaped_prefix . '(.*)!', $args[0], $matches)) {
|
||||||
|
$keyword = yourls_sanitize_keyword($matches[1]);
|
||||||
|
|
||||||
|
// Load YOURLS core to use the URL functions if not already available (usually available in this hook context)
|
||||||
|
// require_once(dirname(__FILE__) . '/../../../includes/load-yourls.php'); // Not typically needed inside a plugin hook
|
||||||
|
|
||||||
|
$url = yourls_get_keyword_longurl($keyword);
|
||||||
|
if (!$url) {
|
||||||
|
return; // No redirect
|
||||||
|
}
|
||||||
|
|
||||||
|
// Output meta refresh redirect with configured delay
|
||||||
|
echo '<!DOCTYPE html><html><head><meta http-equiv="refresh" content="' . $delay . '; url=' . htmlspecialchars($url, ENT_QUOTES) . '"></head><body>';
|
||||||
|
echo 'You will be redirected to <a href="' . htmlspecialchars($url, ENT_QUOTES) . '">' . htmlspecialchars($url) . '</a>.';
|
||||||
|
echo '</body></html>';
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 302 Redirect Logic
|
||||||
|
yourls_add_action('pre_redirect', 'icc_force_302_redirect');
|
||||||
|
function icc_force_302_redirect($args)
|
||||||
|
{
|
||||||
|
if (!yourls_get_option('icc_302_redirect_enabled'))
|
||||||
|
return;
|
||||||
|
|
||||||
|
$url = $args[0];
|
||||||
|
$code = $args[1];
|
||||||
|
if ($code != 302) {
|
||||||
|
// Redirect with 302 instead
|
||||||
|
yourls_redirect($url, 302);
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user