function install($basepath = '') { global $db, $db_type, $pun_config; //include PUN_ROOT.'include/attach/attach_incl.php'; //first check so that the path seems reasonable if (!((substr($basepath, 0, 1) == '/' || substr($basepath, 1, 1) == ':') && substr($basepath, -1) == '/')) { error('The pathname specified doesn\'t comply with the rules set. Go back and make sure that it\'s the complete path, and that it ends with a slash and that it either start with a slash (example: "/home/username/attachments/", on *nix servers (unix, linux, bsd, solaris etc.)) or a driveletter (example: "C:/webpages/attachments/" on windows servers)'); } // create the neccessary tables // create the files table $db->query("CREATE TABLE IF NOT EXISTS `" . $db->prefix . "attach_2_files` (\r\n\t\t`id` int(10) unsigned NOT NULL auto_increment,\r\n\t\t`owner` int(10) unsigned NOT NULL default '0',\r\n \t\t`post_id` int(10) unsigned NOT NULL default '0',\r\n \t\t`filename` varchar(255) NOT NULL default 'error.file',\r\n \t\t`extension` varchar(64) NOT NULL default 'error.file',\r\n \t\t`mime` varchar(64) NOT NULL default '',\r\n \t\t`location` text NOT NULL,\r\n \t\t`size` int(10) unsigned NOT NULL default '0',\r\n \t\t`downloads` int(10) unsigned NOT NULL default '0',\r\n \t\tUNIQUE KEY `id` (`id`)) ENGINE=MyISAM;") or error('Unable to add table "attach_2_files" to database', __FILE__, __LINE__, $db->error()); // create the rules table $db->query("CREATE TABLE IF NOT EXISTS `" . $db->prefix . "attach_2_rules` (\r\n \t\t`id` int(10) unsigned NOT NULL auto_increment,\r\n \t\t`forum_id` int(10) unsigned NOT NULL default '0',\r\n \t\t`group_id` int(10) unsigned NOT NULL default '0',\r\n \t\t`rules` int(10) unsigned NOT NULL default '0',\r\n \t\t`size` int(10) unsigned NOT NULL default '0',\r\n \t\t`per_post` tinyint(4) NOT NULL default '1',\r\n \t\t`file_ext` text NOT NULL,\r\n \t\tUNIQUE KEY `id` (`id`)) ENGINE=MyISAM;") or error('Unable to add table "attach_2_rules" to database', __FILE__, __LINE__, $db->error()); //ok path could be correct, try to make a subfolder :D $newname = attach_generate_pathname($basepath); if (!attach_create_subfolder($newname, $basepath)) { error('Unable to create new subfolder with name "' . $newname . '", make sure php has write access to that folder!', __FILE__, __LINE__); } // ok, add the stuff needed in the config cache $attach_config = array('attach_always_deny' => 'html"htm"php"php3"php4"exe"com"bat', 'attach_basefolder' => $basepath, 'attach_create_orphans' => '1', 'attach_cur_version' => '2.0.1', 'attach_icon_folder' => 'img/attach/', 'attach_icon_extension' => 'txt"doc"pdf"wav"mp3"ogg"avi"mpg"mpeg"png"jpg"jpeg"gif', 'attach_icon_name' => 'text.png"doc.png"doc.png"audio.png"audio.png"audio.png"video.png"video.png"video.png"image.png"image.png"image.png"image.png', 'attach_max_size' => '2000', 'attach_subfolder' => $newname, 'attach_use_icon' => '1'); foreach ($attach_config as $key => $value) { $db->query("INSERT INTO " . $db->prefix . "config (conf_name, conf_value) VALUES ('{$key}', '" . $db->escape($value) . "')") or error('Unable to add column "' . $key . '" to config table', __FILE__, __LINE__, $db->error()); } // and now, update the cache... require_once PUN_ROOT . 'include/cache.php'; generate_config_cache(); /* DO MOD INSTALLATION HERE Here's an example showing how to run different queries depending on $db_type. NOTE: This is just an example! Replace it with whatever queries your mod needs to run. switch ($db_type) { case 'mysql': case 'mysqli': $db->query("ALTER TABLE ".$db->prefix."some_table ADD some_column TINYINT(1) NOT NULL DEFAULT 1") or error('Unable to add column "some_column" to table "some_table"', __FILE__, __LINE__, $db->error()); break; default: $db->query('ALTER TABLE ".$db->prefix."some_table ADD some_column INT(10) NOT NULL DEFAULT 1') or error('Unable to add column "some_column" to table "some_table"', __FILE__, __LINE__, $db->error()); break; } */ }
} // Regenerate the config cache require_once PUN_ROOT . 'include/cache.php'; generate_config_cache(); // end of stuff taken from admin_options redirect($_SERVER['REQUEST_URI'], 'Attachment Mod ' . $pun_config['attach_cur_version'] . ' settings updated. Redirecting …'); } elseif (isset($_POST['generate_subfolder']) || isset($_POST['change_subfolder'])) { // if the latter, we should use that instead for new folder if (isset($_POST['change_subfolder'])) { // we want to use the entered subfolder $newname = $_POST['subfolder']; } else { $newname = attach_generate_pathname($pun_config['attach_basefolder']); } // ok, we doesn't need to use a folder that has been created beforehand ... if (!attach_create_subfolder($newname)) { error('Unable to create new subfolder with name ' . $newname, __FILE__, __LINE__); } else { redirect($_SERVER['REQUEST_URI'], 'Attachment Mod ' . $pun_config['attach_cur_version'] . ' new subfolder created. Redirecting …'); } } elseif (isset($_POST['alter_settings']) || isset($_GET['alter_settings'])) { // Display the admin navigation menu generate_admin_menu($plugin); ?> <div id="exampleplugin" class="blockform"> <h2><span>Attachment Mod <?php echo $pun_config['attach_cur_version']; ?> - Alter Settings</span></h2> <div class="box"> <div class="inbox">