function createModule($name, $group, $class, $table, $permissions, $icon, $route = false) { // Find an available module route. $route = $route ? $route : BigTreeCMS::urlify($name); if (!ctype_alnum(str_replace("-", "", $route)) || strlen($route) > 127) { return false; } // Go through the hard coded modules $existing = array(); $d = opendir(SERVER_ROOT . "core/admin/modules/"); while ($f = readdir($d)) { if ($f != "." && $f != "..") { $existing[] = $f; } } // Go through the directories (really ajax, css, images, js) $d = opendir(SERVER_ROOT . "core/admin/"); while ($f = readdir($d)) { if ($f != "." && $f != "..") { $existing[] = $f; } } // Go through the hard coded pages $d = opendir(SERVER_ROOT . "core/admin/pages/"); while ($f = readdir($d)) { if ($f != "." && $f != "..") { // Drop the .php $existing[] = substr($f, 0, -4); } } // Go through already created modules $q = sqlquery("SELECT route FROM bigtree_modules"); while ($f = sqlfetch($q)) { $existing[] = $f["route"]; } // Get a unique route $x = 2; $oroute = $route; while (in_array($route, $existing)) { $route = $oroute . "-" . $x; $x++; } $name = sqlescape(BigTree::safeEncode($name)); $route = sqlescape($route); $class = sqlescape($class); $group = $group ? "'" . sqlescape($group) . "'" : "NULL"; $gbp = BigTree::json($permissions, true); $icon = sqlescape($icon); sqlquery("INSERT INTO bigtree_modules (`name`,`route`,`class`,`icon`,`group`,`gbp`) VALUES ('{$name}','{$route}','{$class}','{$icon}',{$group},'{$gbp}')"); $id = sqlid(); if ($class) { // Create class module. $f = fopen(SERVER_ROOT . "custom/inc/modules/{$route}.php", "w"); fwrite($f, "<?\n"); fwrite($f, "\tclass {$class} extends BigTreeModule {\n"); fwrite($f, ' var $Table = "' . $table . '";' . "\n"); fwrite($f, "\t}\n"); fwrite($f, "?>\n"); fclose($f); BigTree::setPermissions(SERVER_ROOT . "custom/inc/modules/{$route}.php"); // Remove cached class list. unlink(SERVER_ROOT . "cache/bigtree-module-class-list.json"); } $this->track("bigtree_modules", $id, "created"); return $id; }