### Minimal Configuration Example Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/06_configuration-reference.md Sets up essential database, cache, and authentication key for a basic setup. ```php ``` -------------------------------- ### PHP File Structure Example Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/05_coding-standards.md Illustrates a standard PHP file structure with header comments, function/class definitions, main execution logic, and return statements. ```php ``` -------------------------------- ### Program Link Module Example Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/01_plugin-system-api.md Specifies a plugin menu item for the main navigation bar, linking to a module file. ```text Plugin Menu → Main Navigation Module: mymodule File: source/plugin/myplugin/mymodule.inc.php ``` -------------------------------- ### Production Configuration Example Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/06_configuration-reference.md Disables debugging and plugin development, uses 'redis' or 'memcache' for cache, and enforces secure, HttpOnly cookies. ```php $"_config['debug'] = 0; $"_config['plugindeveloper'] = 0; $"_config['cache']['type'] = 'redis'; // Or Memcache $"_config['cookie']['secure'] = 1; // HTTPS only $"_config['cookie']['httponly'] = 1; ``` -------------------------------- ### PHP Class Structure Example Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/05_coding-standards.md Demonstrates the recommended structure for PHP classes, including properties with visibility, constructor, and methods organized by scope (public, protected, private). ```php class MyClass { // Properties with visibility public $public_prop; private $private_prop; // Constructor public function __construct() { // Initialization } // Public methods first public function publicMethod() { } // Protected methods protected function protectedMethod() { } // Private methods last private function privateMethod() { } } ``` -------------------------------- ### Example Compiled Template Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/08_template-system.md This is an example of a compiled template file, showing typical PHP logic for conditional rendering. ```php Hello, '.$_G['member']['username'].'
'; } else { echo 'Please log in
'; } ?> ``` -------------------------------- ### Variable Initialization: Numeric and String Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/05_coding-standards.md All variables must be initialized before use. This example shows initialization for numeric and string types. ```php // Numeric $number = 0; $count = 0; $total = 0.0; // String $string = ''; $message = ''; $name = ''; ``` -------------------------------- ### Logging Hook Example Source: https://github.com/lovespark/disucz_doc/blob/master/dev_plugin.md An example of a custom hook function named `logging_test_output` that is called during login. It demonstrates how to access and print debugging information, including POST data. ```php function logging_test_output($a) { print_r($a); print_r($_POST); } ``` -------------------------------- ### Template Directory Structure Example Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/08_template-system.md Illustrates the hierarchical organization of template files within the Discuz! X theme structure. This helps in understanding where different types of HTML templates are located. ```text template/default/ ├── common/ # Global templates used across all modules │ ├── footer.htm │ ├── header.htm │ ├── userabout.htm │ └── userstatus.htm ├── forum/ # Forum-specific templates │ ├── discuz.htm # Forum index │ ├── forumdisplay.htm # Thread list │ ├── post.htm # New thread/reply form │ └── ... ├── member/ # User management templates ├── home/ # User space templates ├── portal/ # Portal/CMS templates ├── search/ # Search page templates └── touch/ # Mobile/responsive templates ``` -------------------------------- ### Plugin Directory Path Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/07_directory-structure.md Construct plugin paths using `DISCUZ_ROOT` for the Discuz! installation root and the plugin's unique identifier. ```php // Plugin directory (from plugin context) $pluginpath = DISCUZ_ROOT . 'source/plugin/identifier/'; ``` -------------------------------- ### C::t() Plugin Table Call Example Source: https://github.com/lovespark/disucz_doc/blob/master/construct_db_merged.md Example of how to call a method on a table class for a plugin using the C::t() syntax. The plugin ID and table name are specified within the call. ```php C::t('#mypluginid#mytablename')->method(); ``` -------------------------------- ### Example Hook Points in Templates Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/08_template-system.md Illustrates how to use hook tags within template files to allow for plugin content injection at specific locations, such as the top and bottom of the forum index or thread view. ```html{substr($text, 0, 100)}
{strtoupper($name)}
{strlen($title)} characters
``` -------------------------------- ### Fetching All Users with Specific Criteria Source: https://github.com/lovespark/disucz_doc/blob/master/construct_db_merged.md Example of using DB::fetch_all with format specifiers to query multiple user records, ordering them by UID and limiting the results. The 'uid' field is used as the key for the returned array. ```php //例:查询10个用户uid大于100的用户数据,以uid为返回结果数组的key $arr = DB::fetch_all('SELECT * FROM %t WHERE uid>%d LIMIT %d', array('common_member', '100', '10'), 'uid'); ``` -------------------------------- ### Initialize Application Core Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/INDEX.md Use `class_core::init()` for main application initialization. This is a foundational step for the Discuz! X framework. ```php class_core::init() ``` -------------------------------- ### Project-Level Entry Points Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/07_directory-structure.md Lists the main PHP files that serve as entry points for different sections of the application. ```php index.php → Loads forum home forum.php → Forum board listing member.php → User profiles home.php → User space group.php → User groups portal.php → Portal/CMS search.php → Search misc.php → Extensions plugin.php → Plugin router admin.php → Admin panel api.php → API services connect.php → Cloud integration ``` -------------------------------- ### Core Classes Initialization Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/INDEX.md Initializes the Discuz! X application. ```APIDOC ## class_core::init() ### Description Initializes the Discuz! X application. ### Method ```php class_core::init() ``` ``` -------------------------------- ### Database Table Operations Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/INDEX.md Provides functions for interacting with the database, including getting table names, executing queries, inserting, updating, deleting records, and fetching results. Use `DB::table()` to get prefixed table names and `DB::query()` for custom SQL. ```php DB::table($name) ``` ```php DB::query($sql) ``` ```php DB::insert($table, $data) ``` ```php DB::update($table, $data, $where) ``` ```php DB::delete($table, $where) ``` ```php DB::fetch($result) ``` ```php DB::fetch_all($sql, $params) ``` ```php DB::fetch_first($sql) ``` ```php DB::result_first($sql) ``` -------------------------------- ### Module Entry Point Pattern Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/07_directory-structure.md Illustrates the basic PHP structure for module entry points, including core initialization, setting the CURSCRIPT constant, processing logic, and outputting results. ```php ``` -------------------------------- ### UCenter Server Directory Structure Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/07_directory-structure.md Represents the UCenter server, which is a separate installation for centralized user management. ```directory uc_server/ ├── api/ # UCenter API endpoints ├── cache/ # UCenter cache ├── data/ # UCenter data ├── language/ # UCenter language files └── ... (complete separate application) ``` -------------------------------- ### Set Authentication Key Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/06_configuration-reference.md Define the authentication key used for security calculations. This should be a unique string generated during installation. ```php $"_config['authkey'] = 'discuzauthkey'; // Auth key for security calculations ``` -------------------------------- ### Basic Site Settings Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/06_configuration-reference.md Configure the site's display name, base URL, and HTTP port. ```php $"__config['sitename'] = 'Discuz! Forum'; // Site display name $"__config['siteurl'] = 'http://example.com'; // Site base URL $"__config['siteport'] = 80; // HTTP port ``` -------------------------------- ### Script Execution Timeout Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/06_configuration-reference.md Set the maximum script execution time in seconds. This example sets a limit of 300 seconds. ```php set_time_limit(300); // Script execution limit (seconds) ``` -------------------------------- ### Optimize Database Queries with Batch Access Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/INDEX.md Demonstrates efficient database querying by fetching multiple records at once using 'fetch_all', contrasting with inefficient N+1 query patterns. ```php // Good: Cached access $user = C::t('common_member')->fetch($uid); // Bad: N+1 queries foreach($uids as $uid) { $user = C::t('common_member')->fetch($uid); // Multiple queries } // Good: Batch access $users = C::t('common_member')->fetch_all($uids); ``` -------------------------------- ### Using a Table Class Instance Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/04_database-schema.md This demonstrates how to retrieve an instance of a table class using the `C::t()` method and then call methods on it, such as `fetch`. ```php C::t('common_member')->fetch($uid); ``` -------------------------------- ### DB::num_rows Method Usage Source: https://github.com/lovespark/disucz_doc/blob/master/construct_db_merged.md Demonstrates how to get the total number of rows in a query result set using DB::num_rows. ```php DB::num_rows(查询后的资源) ``` -------------------------------- ### UCenter Client Directory Structure Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/07_directory-structure.md Includes the UCenter API client library for centralized user authentication across multiple Discuz! installations. ```directory uc_client/ ├── client.php # UCenter API client ├── lib/ # Client libraries └── data/ # Client cache ``` -------------------------------- ### Configure Database Host and Credentials Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/06_configuration-reference.md Set the database server hostname, username, password, database name, and character set. Use `utf8mb4` for emoji support. Configure persistent connections with `pconnect`. ```php $"config['db']['1']['dbhost'] = 'localhost'; // Database server hostname $"config['db']['1']['dbuser'] = 'root'; // Database username $"config['db']['1']['dbpw'] = ''; // Database password $"config['db']['1']['dbname'] = 'discuz'; // Database name $"config['db']['1']['dbcharset'] = 'utf8mb4'; // Character set (utf8mb4 for emoji support) $"config['db']['1']['pconnect'] = 0; // 0=new connection, 1=persistent ``` -------------------------------- ### Site Settings Configuration Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/INDEX.md Define the site name, base URL, and registration status (open/closed). ```php $_config['sitename'] $_config['siteurl'] $_config['regstatus'] ``` -------------------------------- ### DB::order Method Usage Source: https://github.com/lovespark/disucz_doc/blob/master/construct_db_merged.md Demonstrates how to create an ORDER BY clause string for SQL queries using DB::order, specifying the alias and method of ordering. ```php DB::order(别名, 方法) ``` -------------------------------- ### PHP Variable Naming (Clarity) Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/05_coding-standards.md Variable names should clearly describe their purpose. Use prefixes like 'get' for boolean flags indicating retrieval. ```php $threaddata = array(); // Thread information ``` ```php $postdata = array(); // Post information ``` ```php $forumid = 123; // Forum identifier ``` ```php $getuser = FALSE; // Whether to get user (Boolean prefix) ``` -------------------------------- ### Loop Patterns: Initialization and Array Functions Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/05_coding-standards.md Initialize loop accumulators before the loop. Demonstrates using common array functions like `count`, `array_keys`, and `array_values`. ```php // Initialize before loop $total = 0; foreach($items as $item) { $total += $item['count']; } // Use array functions $count = count($array); $keys = array_keys($array); $values = array_values($array); ``` -------------------------------- ### Clearfix for Parent Overflow with Floats Source: https://github.com/lovespark/disucz_doc/blob/master/dev_template.md A common clearfix hack to prevent parent elements from collapsing when containing floated children. Includes HTML usage example. ```css .cl:after { content: "."; display: block; height: 0; clear: both; visibility: hidden; } .cl { zoom: 1; } ``` ```htmlWelcome, {$_G['member']['username']}
``` -------------------------------- ### Use include_once or include for Cache Files Source: https://github.com/lovespark/disucz_doc/blob/master/dev_coderule.md For cache files, use `include_once` or `include`. Consider using `[@include_once]` or `[@include]` to suppress potential error messages if the cache file might not always be accessible. ```php include_once ``` ```php include ``` -------------------------------- ### Configure Search Engine Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/06_configuration-reference.md Select the search engine by setting `engine` to 'database' or 'elasticsearch'. ```php $"_config['search']['engine'] = 'database'; // 'database' or 'elasticsearch' ``` -------------------------------- ### Cache Configuration Options Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/INDEX.md Specify the cache type ('sql' or 'file') and optionally configure Memcache servers. ```php $_config['cache']['type'] $_config['cache']['server'] ``` -------------------------------- ### Configure Cache Server Details Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/06_configuration-reference.md Advanced cache configuration, specifying server host, port, timeout, and weight. ```php $"_config['cache']['server'] = array( array( 'host' => '127.0.0.1', 'port' => 11211, 'timeout' => 1, 'weight' => 1, ), ); ``` -------------------------------- ### C::t() Range Method Usage Source: https://github.com/lovespark/disucz_doc/blob/master/construct_db_merged.md Illustrates fetching a range of values from a table based on start and limit parameters, with an optional sort order, using the range() method of the C::t() data layer. ```php C::t($tablename')->range($start, $limit, $sort) ``` -------------------------------- ### Table Abstraction Layer Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/INDEX.md Access table data through an abstraction layer. Use `C::t($table_name)` to get table instances and perform CRUD operations, counting, or range queries. This simplifies direct table manipulation. ```php C::t($table_name) ``` ```php table_*::fetch($id) ``` ```php table_*::fetch_all($ids) ``` ```php table_*::insert($data) ``` ```php table_*::update($id, $data) ``` ```php table_*::delete($id) ``` ```php table_*::count() ``` ```php table_*::range($start, $limit) ``` -------------------------------- ### Enable Plugin Developer Mode in Discuz! Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/01_plugin-system-api.md Add this configuration to `config/config_global.php` to enable plugin development mode. Set to 1 for general development mode, or 2 to show hook embedding points. ```php $\_config['plugindeveloper'] = 1; // Enable plugin development mode $\config['plugindeveloper'] = 2; // Show hook embedding points ``` -------------------------------- ### Iterating Over Forums with Key Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/08_template-system.md Shows the `` syntax when both the key (forum ID) and the value (forum data) are needed during iteration. Useful for creating links or accessing specific forum properties. ```html {$forum['name']} ``` -------------------------------- ### Database Operations with DB Class Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/01_plugin-system-api.md Perform common database operations like getting table names, querying, inserting, updating, and deleting records using the DB class. Use format specifiers for safe query construction. ```php // Get table name with prefix $table = DB::table('common_member'); ``` ```php // Query with format support $sql = 'SELECT * FROM %t WHERE uid > %d LIMIT %d'; $result = DB::fetch_all($sql, array('common_member', 100, 10), 'uid'); ``` ```php // Insert DB::insert('tablename', array('field1' => 'value1', 'field2' => 'value2')); ``` ```php // Update DB::update('tablename', array('field' => 'value'), 'WHERE id = 1'); ``` ```php // Delete DB::delete('tablename', 'WHERE id = 1'); ``` -------------------------------- ### Access Module Settings Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/02_core-functions-api.md Access module-specific settings preloaded into the global $_G array. Use this to retrieve configuration values like site name or URL. ```php // Access module-specific setting $_G['setting']['sitename']; // Site name $_G['setting']['siteurl']; // Site URL ``` -------------------------------- ### Global Ad Block Hook Example Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/03_hook-points-reference.md This hook allows for the injection of custom advertisement code into specific locations within the Discuz! X platform. The function name must match the ad position script ID (e.g., `ad_headerbanner`). ```php function ad_adId($value) { // Where adId matches ad position script ID // Example: ad_headerbanner() for header banner ad } ``` ```php $value = array( 'params' => array(...), // Ad position parameters 'content' => $current_html // Current ad block content ) ``` -------------------------------- ### SQL Query Optimization Example Source: https://github.com/lovespark/disucz_doc/blob/master/dev_coderule.md Optimize query performance by ordering conditions to filter out the most results first. The order of conditions in WHERE clauses significantly impacts query speed, especially on large tables. ORDER BY clauses are primarily related to indexes and not affected by condition order. ```sql SELECT * FROM table WHERE a>'0' AND b<'1' ORDER BY c LIMIT 10; ``` -------------------------------- ### Iterating Over Threads with Foreach Loop Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/08_template-system.md Demonstrates how to loop through an array of threads to display individual thread information. The syntax supports iterating with or without an index. ```html{$thread['message']}