Získání seznamu konstant pro tabulky phpBB3

V souboru constant.php

se vyskytuje tento text:

// Captcha code length
define('CAPTCHA_MIN_CHARS', 4);
define('CAPTCHA_MAX_CHARS', 7);

// Additional constants
define('VOTE_CONVERTED', 127);

// BC global FTW
global $table_prefix;

// Table names
define('ACL_GROUPS_TABLE', $table_prefix . 'acl_groups');
define('ACL_OPTIONS_TABLE', $table_prefix . 'acl_options');
define('ACL_ROLES_DATA_TABLE', $table_prefix . 'acl_roles_data');
define('ACL_ROLES_TABLE', $table_prefix . 'acl_roles');
define('ACL_USERS_TABLE', $table_prefix . 'acl_users');
define('ATTACHMENTS_TABLE', $table_prefix . 'attachments');
define('BANLIST_TABLE', $table_prefix . 'banlist');
define('BBCODES_TABLE', $table_prefix . 'bbcodes');
define('BOOKMARKS_TABLE', $table_prefix . 'bookmarks');
define('BOTS_TABLE', $table_prefix . 'bots');
if (!defined('CONFIG_TABLE'))
{
define('CONFIG_TABLE', $table_prefix . 'config');
}
define('CONFIG_TEXT_TABLE', $table_prefix . 'config_text');
define('CONFIRM_TABLE', $table_prefix . 'confirm');
define('DISALLOW_TABLE', $table_prefix . 'disallow');
define('DRAFTS_TABLE', $table_prefix . 'drafts');
define('EXT_TABLE', $table_prefix . 'ext');
define('EXTENSIONS_TABLE', $table_prefix . 'extensions');
define('EXTENSION_GROUPS_TABLE', $table_prefix . 'extension_groups');
define('FORUMS_TABLE', $table_prefix . 'forums');
define('FORUMS_ACCESS_TABLE', $table_prefix . 'forums_access');
define('FORUMS_TRACK_TABLE', $table_prefix . 'forums_track');
define('FORUMS_WATCH_TABLE', $table_prefix . 'forums_watch');
define('GROUPS_TABLE', $table_prefix . 'groups');
define('ICONS_TABLE', $table_prefix . 'icons');
define('LANG_TABLE', $table_prefix . 'lang');
define('LOG_TABLE', $table_prefix . 'log');
define('LOGIN_ATTEMPT_TABLE', $table_prefix . 'login_attempts');
define('MIGRATIONS_TABLE', $table_prefix . 'migrations');
define('MODERATOR_CACHE_TABLE', $table_prefix . 'moderator_cache');
define('MODULES_TABLE', $table_prefix . 'modules');
define('NOTIFICATION_TYPES_TABLE', $table_prefix . 'notification_types');
define('NOTIFICATIONS_TABLE', $table_prefix . 'notifications');
define('POLL_OPTIONS_TABLE', $table_prefix . 'poll_options');
define('POLL_VOTES_TABLE', $table_prefix . 'poll_votes');
define('POSTS_TABLE', $table_prefix . 'posts');
define('PRIVMSGS_TABLE', $table_prefix . 'privmsgs');
define('PRIVMSGS_FOLDER_TABLE', $table_prefix . 'privmsgs_folder');
define('PRIVMSGS_RULES_TABLE', $table_prefix . 'privmsgs_rules');
define('PRIVMSGS_TO_TABLE', $table_prefix . 'privmsgs_to');
define('PROFILE_FIELDS_TABLE', $table_prefix . 'profile_fields');
define('PROFILE_FIELDS_DATA_TABLE', $table_prefix . 'profile_fields_data');
define('PROFILE_FIELDS_LANG_TABLE', $table_prefix . 'profile_fields_lang');
define('PROFILE_LANG_TABLE', $table_prefix . 'profile_lang');
define('RANKS_TABLE', $table_prefix . 'ranks');
define('REPORTS_TABLE', $table_prefix . 'reports');
define('REPORTS_REASONS_TABLE', $table_prefix . 'reports_reasons');
define('SEARCH_RESULTS_TABLE', $table_prefix . 'search_results');
define('SEARCH_WORDLIST_TABLE', $table_prefix . 'search_wordlist');
define('SEARCH_WORDMATCH_TABLE', $table_prefix . 'search_wordmatch');
define('SESSIONS_TABLE', $table_prefix . 'sessions');
define('SESSIONS_KEYS_TABLE', $table_prefix . 'sessions_keys');
define('SITELIST_TABLE', $table_prefix . 'sitelist');
define('SMILIES_TABLE', $table_prefix . 'smilies');
define('SPHINX_TABLE', $table_prefix . 'sphinx');
define('STYLES_TABLE', $table_prefix . 'styles');
define('STYLES_TEMPLATE_TABLE', $table_prefix . 'styles_template');
define('STYLES_TEMPLATE_DATA_TABLE',$table_prefix . 'styles_template_data');
define('STYLES_THEME_TABLE', $table_prefix . 'styles_theme');
define('STYLES_IMAGESET_TABLE', $table_prefix . 'styles_imageset');
define('STYLES_IMAGESET_DATA_TABLE',$table_prefix . 'styles_imageset_data');
define('TEAMPAGE_TABLE', $table_prefix . 'teampage');
define('TOPICS_TABLE', $table_prefix . 'topics');
define('TOPICS_POSTED_TABLE', $table_prefix . 'topics_posted');
define('TOPICS_TRACK_TABLE', $table_prefix . 'topics_track');
define('TOPICS_WATCH_TABLE', $table_prefix . 'topics_watch');
define('USER_GROUP_TABLE', $table_prefix . 'user_group');
define('USER_NOTIFICATIONS_TABLE', $table_prefix . 'user_notifications');
define('USERS_TABLE', $table_prefix . 'users');
define('WARNINGS_TABLE', $table_prefix . 'warnings');
define('WORDS_TABLE', $table_prefix . 'words');
define('ZEBRA_TABLE', $table_prefix . 'zebra');

Cílem následkujícího skriptu pro bash je získat seznam párů názvů konstant a názvů tabulek:
 
 

ACL_GROUPS_TABLE:acl_groups
ACL_OPTIONS_TABLE:acl_options
ACL_ROLES_DATA_TABLE:acl_roles_data
ACL_ROLES_TABLE:acl_roles
ACL_USERS_TABLE:acl_users
ATTACHMENTS_TABLE:attachments
BANLIST_TABLE:banlist
BBCODES_TABLE:bbcodes
BOOKMARKS_TABLE:bookmarks
BOTS_TABLE:bots
CONFIG_TABLE:config
CONFIG_TEXT_TABLE:config_text
CONFIRM_TABLE:confirm
DISALLOW_TABLE:disallow
DRAFTS_TABLE:drafts
EXT_TABLE:ext
EXTENSIONS_TABLE:extensions
EXTENSION_GROUPS_TABLE:extension_groups
FORUMS_TABLE:forums
FORUMS_ACCESS_TABLE:forums_access
FORUMS_TRACK_TABLE:forums_track
FORUMS_WATCH_TABLE:forums_watch
GROUPS_TABLE:groups
ICONS_TABLE:icons
LANG_TABLE:lang
LOG_TABLE:log
LOGIN_ATTEMPT_TABLE:login_attempts
MIGRATIONS_TABLE:migrations
MODERATOR_CACHE_TABLE:moderator_cache
MODULES_TABLE:modules
NOTIFICATION_TYPES_TABLE:notification_types
NOTIFICATIONS_TABLE:notifications
POLL_OPTIONS_TABLE:poll_options
POLL_VOTES_TABLE:poll_votes
POSTS_TABLE:posts
PRIVMSGS_TABLE:privmsgs
PRIVMSGS_FOLDER_TABLE:privmsgs_folder
PRIVMSGS_RULES_TABLE:privmsgs_rules
PRIVMSGS_TO_TABLE:privmsgs_to
PROFILE_FIELDS_TABLE:profile_fields
PROFILE_FIELDS_DATA_TABLE:profile_fields_data
PROFILE_FIELDS_LANG_TABLE:profile_fields_lang
PROFILE_LANG_TABLE:profile_lang
RANKS_TABLE:ranks
REPORTS_TABLE:reports
REPORTS_REASONS_TABLE:reports_reasons
SEARCH_RESULTS_TABLE:search_results
SEARCH_WORDLIST_TABLE:search_wordlist
SEARCH_WORDMATCH_TABLE:search_wordmatch
SESSIONS_TABLE:sessions
SESSIONS_KEYS_TABLE:sessions_keys
SITELIST_TABLE:sitelist
SMILIES_TABLE:smilies
SPHINX_TABLE:sphinx
STYLES_TABLE:styles
STYLES_TEMPLATE_TABLE:styles_template
STYLES_TEMPLATE_DATA_TABLE:styles_template_data
STYLES_THEME_TABLE:styles_theme
STYLES_IMAGESET_TABLE:styles_imageset
STYLES_IMAGESET_DATA_TABLE:styles_imageset_data
TEAMPAGE_TABLE:teampage
TOPICS_TABLE:topics
TOPICS_POSTED_TABLE:topics_posted
TOPICS_TRACK_TABLE:topics_track
TOPICS_WATCH_TABLE:topics_watch
USER_GROUP_TABLE:user_group
USER_NOTIFICATIONS_TABLE:user_notifications
USERS_TABLE:users
WARNINGS_TABLE:warnings
WORDS_TABLE:words
ZEBRA_TABLE:zebra


 

 

 #!/bin/bash

# Cesta k souboru constants.php
CONSTANTS_FILE="/var/www/phpBB3/includes/constants.php"

# Výstupní soubor pro tabulku
OUTPUT_FILE="forum_constants_tables_info.txt"


# Regulární výraz pro hledání konstant
# CONSTANT_PATTERN="define\('([^']+)',\s*'\$table_prefix\s*\.\s*'([^']+)"

# Použití grep pro filtrování řádků obsahujících $table_prefix, ale vynechat výskyt se slovem "global"
GREPPED_LINES=$(grep "\$table_prefix" "$CONSTANTS_FILE" | grep -v "global" )

# Odstranění "define(' ze začátku řádků
CLEANED_LINES=$(echo "$GREPPED_LINES" | sed "s/define('//g")

# Odstranění "');" z konce řádků
CLEANED_LINES=$(echo "$CLEANED_LINES" | sed "s/');//g")

# Odstranění mezer a tabulátorů
CLEANED_LINES=$(echo "$CLEANED_LINES" | sed 's/[[:space:]]//g')

# Odstranění "',$table_prefix .'" z řádků
CLEANED_LINES=$(echo "$CLEANED_LINES" | sed "s/,\$table_prefix\.//g")

# Oddělení konstanty a názvu tabulky dvojtečkou a odstranění dvojitých apostrofů
FINAL_LINES=$(echo "$CLEANED_LINES" | sed "s/''/:/g")
echo "$FINAL_LINES"

# Vymazání starého souboru, pokud existuje
rm -f $OUTPUT_FILE

# Vytvoření textové tabulky
echo "$FINAL_LINES" | tr ' ' '\t' >> "$OUTPUT_FILE"

echo "Textová tabulka byla vytvořena v souboru $OUTPUT_FILE"

Komentáře

Oblíbené příspěvky