安装脚本一般格式如下 PHP: <?php // +---------------------------------------------+ // | Copyright © 2003 – 2004 Subdreamer | // | http://www.subdreamer.com | // | This file may not be redistributed. | // +---------------------------------------------+ // This sets the TABLE_PREFIX constant to "" if your Subdreamer database doesn't use a prefix. if(!defined('TABLE_PREFIX')) define('TABLE_PREFIX', ""); // Makes sure that this script is only called from within Subdreamer if(!defined('IN_SUBDREAMER')) die("Hacking attempt!"); // You can remove most of the comment lines we have added here. Most of them are only here to explain // the install file. Check other plugins to see how the comments they contain. // ############################# PLUGIN INFORMATION ############################ // The uniqueid is the plugin number we have chosen for this plugin, and will be used when we // insert data into our Subdreamer database later. $uniqueid = 55; // Plugin name is a unique name for the plugin. This name will automatically be used as the display name // for the plugin when displayed on your site, so use a meaningful name that hasn't been used by other plugins. $pluginname = 'Site Stats'; // This number indicates that this is the first version of the plugin. If you make minor adjustmenst to the // plugin, you will use 1.1, 1.2 etc. A major upgrade should be given the number 2.0. The version number is // used by this installation file to figure out which version the user has installed on his site. Further // down you will see that there is a section for upgrading the plugin. $version = '1.0'; // The pluginpath is the relative path from the plugins/ folder to our plugin script. $pluginpath = 'p55_site_stats/p55_site_stats.php'; // The settingspath is the relative path from the plugins/ folder to our plugin settings. $settingspath = 'p55_site_stats/p55_settings.php'; // The authorname can be whatever you want, but we usually use the usernames we have in the Subdreamer forum. $authorname = 'labrekke'; // The authorlink is the number of your user in the Subdreamer forum. $authorlink = 217; // ############################## INSTALL PLUGIN ############################### if($installtype == 'install') { // Install plugin tables - we are not going to create tables in this plugin, but the next 6 lines shows you // how you can create your own subdreamer tables to be used by your plugin //$DB->query("CREATE TABLE " . TABLE_PREFIX . "p55_site_stats ( // firstfield INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, // secondfield VARCHAR(64) NOT NULL DEFAULT '', // thirdfield TINYINT(1) NOT NULL DEFAULT '0', // KEY firstfield (firstfield) //) " ); // Install plugin settings - the values you insert here will be displayed on the settings page // for your plugin in the admin panel of Subdreamer, values are inserted into the table PLUGINSETTINGS. // The only thing you should change in the inserts are the part after VALUES. // Each query will insert a record into the PLUGINSETTINGS table and will be displayed as one option // in the admin panel for this plugin. // Please note that the groupname is used to group settings together (as described in the // section "3. Create a Settings File"). // The first three records in the PLUGINSETTINGS table will be "Yes/No" radio buttons to decide if // we are going to display statistics for news, links and images. We will also ask the admin of the // website if he/she wants to display how many image sections there are online. $DB->query("INSERT INTO " . TABLE_PREFIX . "pluginsettings (pluginid, groupname, title, description, input, value, displayorder) VALUES ('$uniqueid', 'Options', 'News Articles', 'Do you want to display the number of online news articles?', 'yesno', '1', 1) "); $DB->query("INSERT INTO " . TABLE_PREFIX . "pluginsettings (pluginid, groupname, title, description, input, value, displayorder) VALUES ('$uniqueid', 'Options', 'Image Gallery', 'Do you want to display the number of online images?', 'yesno', '1', 2) "); $DB->query("INSERT INTO " . TABLE_PREFIX . "pluginsettings (pluginid, groupname, title, description, input, value, displayorder) VALUES ('$uniqueid', 'Options', 'Image Sections', 'Do you want to display the number of online image sections?', 'yesno', '1', 3) "); // The next query will insert a dropdown list where the user will be able to decide if and how there // should be a horizontal rule before and/or after the plugin. As you can see, we've made it a bit // easier for us by printing the list values on more than one line. This will not have an effect // on the query, but it makes it easier for us to make the list. If you wonder why the last line // has the value 'both', it is the default value for the list. Note that the whole code of the form // of a dropdown list is inserted into the database! $DB->query("INSERT INTO " . TABLE_PREFIX . "pluginsettings (pluginid, groupname, title, description, input, value, displayorder) VALUES ('$uniqueid', 'Options', 'Horizontal Rule', 'Display a horizontal rule above or below the plugin?', '<select name=\\\\\"settings[\$setting[settingid]]\\\\\">\r\n <option value=\\\\\"above\\\\\" \".iif(\$setting[value]==\"above\", \"selected\", \"\").\">Above only</option>\r\n <option value=\\\\\"below\\\\\" \".iif(\$setting[value]==\"below\", \"selected\", \"\").\">Below only</option>\r\n <option value=\\\\\"both\\\\\" \".iif(\$setting[value]==\"both\", \"selected\", \"\").\">Above and Below</option>\r\n <option value=\\\\\"none\\\\\" \".iif(\$setting[value]==\"none\", \"selected\", \"\").\">No Horizontal Rule</option>\r\n </select>', 'both', 4)"); // The last option we will add is a text box where users can enter a categoryid to exclude news categories from being counted. // Please note that if you use a single quote character in a text, for example the word "don't" , you need to use the escape // character \ in front of the single quote, like this: don\'t $DB->query("INSERT INTO " . TABLE_PREFIX . "pluginsettings (pluginid, groupname, title, description, input, value, displayorder) VALUES ('$uniqueid', 'Options', 'Exclude News Categories', 'If you want to exclude any news categories from being counted enter the categoryid here.<br />Separate values with space. Leave emtpy if you don\'t want to exclude.', 'text', '', 5) "); // Install plugin language // If you want users to change phrases used by your plugin you should insert records into the table PHRASES as displayed below. // If you don't want the plugin to be multilanguage, you can remove these lines, but we highly recommend using them so that your // plugin can easily be used by people having another language. $DB->query("INSERT INTO " . TABLE_PREFIX . "phrases (phraseid, pluginid, varname, defaultphrase, customphrase, font, color, size, bold, italic, underline) VALUES ('', '$uniqueid', 'articles', 'Online Articles:', '', '', '', '', '1', '0', '0') "); $DB->query("INSERT INTO " . TABLE_PREFIX . "phrases (phraseid, pluginid, varname, defaultphrase, customphrase, font, color, size, bold, italic, underline) VALUES ('', '$uniqueid', 'images', 'Online Images:', '', '', '', '', '1', '0', '0') "); $DB->query("INSERT INTO " . TABLE_PREFIX . "phrases (phraseid, pluginid, varname, defaultphrase, customphrase, font, color, size, bold, italic, underline) VALUES ('', '$uniqueid', 'image_sections', 'Online Image sections:', '', '', '', '', '1', '0', '0') "); } // ############################## UPGRADE PLUGIN ############################### if($installtype == 'upgrade') { // upgrade to a new version if($currentversion == '1.0') { // Uncomment the lines below if you have made a new version of your plugin // and use 1.1 or the appropriate number on the next two next lines. // UpdatePluginVersion(55, 1.1); // $currentversion = 1.1; } } // ############################# UNINSTALL PLUGIN ############################## // If you haven't created one or more new tables, the uninstall function of Subdreamer // will take care of deleting all settings for your plugin. Below we display an example // of how you can delete (drop) a table if you created one before. if($installtype == 'uninstall') { //$DB->query("DROP TABLE IF EXISTS " . TABLE_PREFIX . "p55_site_stats"); } ?> $uniqueid就是上文中的XX $pluginname 插件名称 $version 插件版本 $pluginpath 插件的主脚本文件 $settingspath 插件设置脚本文件 $authorname 作者 $authorlink 作者信息链接 是Subdreamer 论坛的ID号 PHP: if($installtype == 'install') { 判断安装类型 如果是install PHP: $DB->query("INSERT INTO " . TABLE_PREFIX . "pluginsettings (pluginid, groupname, title, description, input, value, displayorder) VALUES ('$uniqueid', 'Options', 'News Articles', 'Do you want to display the number of online news articles?', 'yesno', '1', 1) "); $DB->query("INSERT INTO " . TABLE_PREFIX . "pluginsettings (pluginid, groupname, title, description, input, value, displayorder) VALUES ('$uniqueid', 'Options', 'Image Gallery', 'Do you want to display the number of online images?', 'yesno', '1', 2) "); $DB->query("INSERT INTO " . TABLE_PREFIX . "pluginsettings (pluginid, groupname, title, description, input, value, displayorder) VALUES ('$uniqueid', 'Options', 'Image Sections', 'Do you want to display the number of online image sections?', 'yesno', '1', 3) "); 就对数据库插入数据 基本上就是一些sql语句 PHP: if($installtype == 'upgrade') { // upgrade to a new version if($currentversion == '1.0') { // Uncomment the lines below if you have made a new version of your plugin // and use 1.1 or the appropriate number on the next two next lines. // UpdatePluginVersion(55, 1.1); // $currentversion = 1.1; } } 判断版本 并执行升级程序 PHP: f($installtype == 'uninstall') { //$DB->query("DROP TABLE IF EXISTS " . TABLE_PREFIX . "p55_site_stats"); } 卸载脚本 对安装脚本的反操作 明天再写