### 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
...
...
``` -------------------------------- ### Template Code for Looping Example Source: https://github.com/lovespark/disucz_doc/blob/master/dev_template.md HTML template code demonstrating looping through an array and applying conditional styling based on the loop key. ```html
这里是value值:{$val}
``` -------------------------------- ### Specify Include Paths Source: https://github.com/lovespark/disucz_doc/blob/master/dev_coderule.md When including or requiring files, always start the path with "./" or `DISCUZ_ROOT.'./'`. Avoid directly specifying filenames to ensure correct path resolution. ```php "./" ``` ```php DISCUZ_ROOT.'./' ``` -------------------------------- ### Defining a Table Class Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/04_database-schema.md This example shows how to define a table class that extends `discuz_table`. Ensure the `$_table` property matches the actual database table name and `$_pk` is the primary key. ```php // File: source/class/table/table_common_member.php class table_common_member extends discuz_table { protected $\_table = 'common_member'; protected $\_pk = 'uid'; } ``` -------------------------------- ### Database Operations (PHP) Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/INDEX.md Demonstrates common database operations like INSERT, UPDATE, DELETE, and SELECT using the DB class. Use format specifiers for safe query construction. The SELECT example shows how to fetch all rows and key the result array by a specific column. ```php // INSERT $id = DB::insert('tablename', array( 'field1' => $value1, // Auto-escaped 'field2' => $value2, ), true); // $return_insertid ``` ```php // UPDATE $affected = DB::update('tablename', array('field' => $value), 'WHERE id = 1' ); ``` ```php // DELETE $deleted = DB::delete('tablename', 'WHERE id = 1'); ``` ```php // SELECT with format specifiers $rows = DB::fetch_all( 'SELECT * FROM %t WHERE uid = %d AND username = %s', array('common_member', 100, 'john'), 'uid' // Return array keyed by uid ); ``` -------------------------------- ### Query Database with Table Class Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/README.md Use the table class for database queries, which is the preferred method. This example fetches a single member record by UID. ```php $user = C::t('common_member')->fetch($uid); ``` -------------------------------- ### Template Code for Dynamic Font Size Example Source: https://github.com/lovespark/disucz_doc/blob/master/dev_template.md Includes header and footer, displays text with dynamic font size, and provides controls to change font size using JavaScript and Discuz! style constants. ```html
这是一个改变字体的实例
改变小号字改变为大号字 ``` -------------------------------- ### Getting Paths in Code Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/07_directory-structure.md Avoid hardcoding paths. Use dynamic methods like `$_G['setting']['sitepath']` for the forum root path or `dirname(__FILE__)` to reference the current file's directory. ```php // DISCOURAGED - hardcoded paths $file = '/home/discuz/data/cache/test.php'; // CORRECT - dynamic paths $_G['setting']['sitepath']; // Forum root path // Or reference from $_SERVER $rootpath = dirname(__FILE__); ``` -------------------------------- ### Configure UCenter Application Registration Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/06_configuration-reference.md Set up application registration details for UCenter, including client ID, application ID, and secure key. Generate a unique key during UCenter client setup. ```php $"_config['uc_clientid'] = 1; // This application's ID in UCenter $"_config['uc_clientip'] = ''; // Application server IP (optional) $"_config['uc_appid'] = 1; // Primary app ID $"_config['uc_key'] = 'base64encodedkey'; // Secure key for API communication ``` -------------------------------- ### Error Reporting Configuration Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/06_configuration-reference.md Configure PHP's error reporting level. This example shows how to display all errors except notices, typically set in entry point files like index.php. ```php error_reporting(E_ALL & ~E_NOTICE); // Show all errors except notices ``` -------------------------------- ### Using String Manipulation Functions in Templates Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/08_template-system.md Shows examples of using common string manipulation functions like `substr`, `strtoupper`, and `strlen` directly within the template syntax for basic text processing. ```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; } ``` ```html
``` -------------------------------- ### Protect Configuration Files Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/10_security-best-practices.md Provides guidance on protecting sensitive configuration files like `config/config_global.php` by setting appropriate file permissions and avoiding public repositories. ```bash // config/config_global.php contains: // - Database credentials // - Authentication keys // - Cache configuration // Set file permissions: // chmod 640 config/config_global.php // Don't commit to public repositories // Keep backup in secure location ``` -------------------------------- ### Plugin Module Pattern (PHP) Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/INDEX.md Shows the basic structure for creating a plugin module, including the file naming convention, the initial security check, module execution logic, and loading the associated template file. ```php // Create module file: source/plugin/id/modulename.inc.php if(!defined('IN_DISCUZ')) exit('Access denied'); // Module execution if ($action == 'view') { // Process view $data = C::t('table')->fetch($id); } // Load template load_template('modulename'); // Template: source/plugin/id/template/modulename.htm ``` -------------------------------- ### C::t() Count Method Usage Source: https://github.com/lovespark/disucz_doc/blob/master/construct_db_merged.md Shows how to get the total number of rows in a table using the count() method provided by the C::t() data layer. ```php C::t($tablename')->count() ``` -------------------------------- ### PHP Template File Header Source: https://github.com/lovespark/disucz_doc/blob/master/dev_template.md Add this line at the beginning of a PHP-extended template file to prevent direct access. The actual template content starts from the second line. ```php ``` ```php ``` -------------------------------- ### Discuz! X 3.5 Configuration Directory Structure Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/07_directory-structure.md Details the configuration files within the /config/ directory, including main forum settings and UCenter integration. ```directory structure config/ ├── config_global.php # Main forum configuration (generated) ├── config_global_default.php # Configuration template ├── config_ucenter.php # UCenter configuration (generated) └── config_ucenter_default.php # UCenter template ``` -------------------------------- ### Access Control in PHP Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/05_coding-standards.md Provides examples of essential access control checks in PHP, including verifying if the script is included properly and checking user permissions before executing sensitive operations. ```php // Security gate in all included files if(!defined('IN_DISCUZ')) { exit('Access denied'); } // Permission checks in modules if(!$_G['uid']) { showmessage('no_permission_login'); } ``` -------------------------------- ### Use Environment Variables for Production Configuration Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/10_security-best-practices.md Shows how to use environment variables in PHP for storing sensitive production configuration values like database credentials and authentication keys, instead of hardcoding them in config files. ```php // Use environment variables instead of config file $_config['db']['1']['dbuser'] = getenv('DB_USER'); $_config['db']['1']['dbpw'] = getenv('DB_PASS'); $_config['authkey'] = getenv('AUTH_KEY'); ``` -------------------------------- ### Extending Templates with Plugin Hooks Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/08_template-system.md Adds custom content to templates via plugin hooks without direct modification. This example shows a PHP class method returning HTML. ```php // In plugin embedding script class plugin_myid { function forum_index_top() { return '
My custom content
'; } } ``` -------------------------------- ### Outputting Site Name and Username Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/08_template-system.md Demonstrates how to display the site name and the currently logged-in username using template variables. HTML escaping is automatically applied by the engine. ```html

{$_G['setting']['sitename']}

Welcome, {$_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['subject']}

{$thread['message']}

``` -------------------------------- ### Standard File Header Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/05_coding-standards.md All PHP files must begin with this standard header, including version control information. ```php array( 'title' => 'blank_content', 'type' => 'mtextarea' ) ); } // 模块字段 // name: 字段名称 // formtype: 类型,text, textarea, date, title, summary, pic // datatype 数据格式,string, int, date, title, summary, pic function fields() { return array( 'field' => array('name' => '示例字段', 'formtype' => 'text', 'datatype' => 'string') ); } // 模块参数 // 第一个值: 类所在的模块分类,通常为类名,_real 结尾时表示为实时模块,不缓存 // 第二个值: 模块分类显示的名称 function blockclass() { return array('sample_test_real', 'test'); } // 模块数据的返回脚本 // html 为返回的 HTML 内容,data 为返回的数组 function getdata($style, $parameter) { return array('html' => $parameter['content'].time(), 'data' => null); } } ?> ``` -------------------------------- ### DB::fetch_first Method Usage Source: https://github.com/lovespark/disucz_doc/blob/master/construct_db_merged.md Demonstrates fetching the first row of a query result using DB::fetch_first. ```php DB::fetch_first($sql) ``` -------------------------------- ### Define Custom Style CSS File Source: https://github.com/lovespark/disucz_doc/blob/master/dev_template.md When creating a new style, establish a CSS file within the style's directory (e.g., './template/mytest/style/'). This file, like 't1/style.css', enables user-selectable color schemes. ```bash ./template/mytest/style/t1/style.css ``` -------------------------------- ### Memory Limit Configuration Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/06_configuration-reference.md Set the minimum recommended PHP memory limit. Ensure this is at least 128MB for optimal performance. ```php memory_limit = 128M // Minimum 128MB ``` -------------------------------- ### Plugin Class Structure with Private Methods Source: https://github.com/lovespark/disucz_doc/blob/master/dev_plugin.md Shows a recommended structure for plugin classes, where helper methods like `_updatecache` are prefixed with an underscore to indicate they are internal, while public hook methods like `viewthread_posttop` are clearly defined. ```php ``` -------------------------------- ### Security Configuration Options Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/INDEX.md Set the security authentication key and session expiration time in seconds. ```php $_config['authkey'] $_config['sessionexpire'] ``` -------------------------------- ### Cache Settings Configuration Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/09_admin-control-panel.md Configure the caching backend type, supporting SQL, file, Memcache, and Redis. ```php $_config['cache']['type'] // sql, file, memcache, redis ``` -------------------------------- ### DB::limit Method Usage Source: https://github.com/lovespark/disucz_doc/blob/master/construct_db_merged.md Shows how to generate a LIMIT clause string for SQL queries using DB::limit. ```php DB::limit(n, n) ``` -------------------------------- ### DB::fetch_all Method Usage Source: https://github.com/lovespark/disucz_doc/blob/master/construct_db_merged.md Illustrates fetching all rows from a query result using DB::fetch_all. ```php DB::fetch_all($sql) ``` -------------------------------- ### If/Else/Elseif Structure Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/05_coding-standards.md Follow standard brace placement with the opening brace on the same line as the keyword. Ensure consistent spacing for `elseif`. ```php // Brace opening same line as keyword if($condition) { // Statement } else { // Statement } ``` ```php // elseif spacing if($condition) { // Statement } elseif($condition2) { // Space before and after elseif // Statement } else { // Statement } ``` ```php // Always use braces, even for single statements if($condition) { doSomething(); // Braces required } ``` -------------------------------- ### Load and Access Plugin Configuration Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/01_plugin-system-api.md Load the plugin cache and access general, forum-specific, or user group-specific plugin configurations. Ensure the plugin cache is loaded before accessing variables. ```php // Load plugin cache (not needed for hook embeddings) loadcache('plugin'); // Access plugin variables $pluginconf = $_G['cache']['plugin']['plugin_identifier']; // Access forum-specific config $forumconf = $_G['cache']['forums'][$fid]['plugin']['plugin_identifier']; // Access user group config $groupconf = $_G['group']['plugin']['plugin_identifier']; ``` -------------------------------- ### C::t() Optimize Method Usage Source: https://github.com/lovespark/disucz_doc/blob/master/construct_db_merged.md Demonstrates how to optimize a table using the optimize() method of the C::t() data layer. ```php C::t($tablename')->optimize() ``` -------------------------------- ### Enable PWA Support Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/06_configuration-reference.md Set `enable` to 1 to activate Progressive Web App features. ```php $"_config['pwa']['enable'] = 0; // Progressive Web App support ``` -------------------------------- ### Define a Security Question Plugin (PHP) Source: https://github.com/lovespark/disucz_doc/blob/master/dev_plugin.md Implement a security question verification method for Discuz! plugins. The `make` function should return the answer to the question. ```php ``` -------------------------------- ### Set Cache Backend Type Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/06_configuration-reference.md Configure the cache backend type. Defaults to 'sql' (database-backed). ```php $"_config['cache']['type'] = 'sql'; // Database-backed cache (default) $"_config['cache']['type'] = 'file'; // File-based cache ``` -------------------------------- ### Initialize Numeric, String, and Array Variables Source: https://github.com/lovespark/disucz_doc/blob/master/dev_coderule.md Always initialize variables before using them in calculations, display, or storage. This prevents unexpected behavior and potential security issues. ```php $number = 0; //数值型初始化 $string = ''; //字符串初始化 $array = array(); //数组初始化 ``` -------------------------------- ### Core Globals - Settings (PHP) Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/INDEX.md Access global variables for core system settings, including the site name, site URL, cached forum data, and plugin configurations. ```php // Settings $_G['setting']['sitename'] // Forum name $_G['setting']['siteurl'] // Forum URL $_G['cache']['forums'][$fid] // Forum data $_G['cache']['plugin'] // Plugin config ``` -------------------------------- ### Plugin Module Pattern Source: https://github.com/lovespark/disucz_doc/blob/master/_autodocs/INDEX.md Illustrates the standard structure and execution flow for creating plugin modules within the Disucz framework. ```APIDOC ## Plugin Module Pattern ### Module Creation Create module files in `source/plugin/id/modulename.inc.php`. ```php if(!defined('IN_DISCUZ')) exit('Access denied'); ``` ### Module Execution Example of processing module actions like 'view'. ```php if ($action == 'view') { // Process view $data = C::t('table')->fetch($id); } ``` ### Template Loading Loads the associated template file for the module. ```php load_template('modulename'); // Template: source/plugin/id/template/modulename.htm ``` ```