예제 #1
0
 public function redirect($p)
 {
     $path = FabriqModules::new_model('pathmap', 'Paths');
     $path->get_by_path($p);
     if (count($path)) {
         switch ($path->modpage) {
             case 'module':
                 if (FabriqModules::enabled($path->controller)) {
                     $extra = explode('/', $path->extra);
                     if (count($extra) == 1) {
                         if ($extra[0] == '') {
                             unset($extra[0]);
                         }
                     }
                     PathMap::arg(0, $path->controller);
                     PathMap::arg(1, $path->action);
                     for ($i = 0; $i < count($extra); $i++) {
                         PathMap::arg($i + 2, $extra[$i]);
                     }
                     FabriqStack::enqueue($path->controller, $path->action, 'module', $extra);
                     return true;
                 } else {
                     FabriqStack::error(404);
                 }
                 break;
             case 'page':
             default:
                 PathMap::arg(0, $path->controller);
                 PathMap::arg(1, $path->action);
                 FabriqStack::enqueue($path->controller, $path->action);
                 if ($path->extra != '') {
                     $extra = explode('/', $path->extra);
                     if ($path->wildcard) {
                         $p = explode('/', $_GET['q']);
                         array_unshift($extra, $p[$path->wildcard]);
                     }
                     for ($i = 0; $i < count($extra); $i++) {
                         PathMap::arg($i + 2, $extra[$i]);
                     }
                 } else {
                     if ($path->wildcard) {
                         $p = explode('/', $_GET['q']);
                         PathMap::arg(2, $p[$path->wildcard]);
                     }
                 }
                 return true;
                 break;
         }
     }
     return false;
 }
 /**
  * Creates a new instance of a module model
  * @param string $module
  * @param string $model
  * @return object
  */
 public static function new_model($module, $model)
 {
     $class = "{$module}_{$model}";
     if (!class_exists($class)) {
         $model = "modules/{$module}/models/{$model}.model.php";
         if (file_exists('sites/' . FabriqStack::site() . "/{$model}")) {
             require_once 'sites/' . FabriqStack::site() . "/{$model}";
         } else {
             require_once $model;
         }
     }
     eval("\$item = new {$class}();");
     return $item;
 }
<h1>Install complete</h1>
<p>Congrats! You have just set up your Fabriq application!</p>
<p>Be sure to remove the write permissions for the following directories (<code>chmod 775</code> is sufficient for most systems):</p>
<ul>
	<li><code>sites/<?php 
echo FabriqStack::site();
?>
/config</code></li>
	<li><code>sites/<?php 
echo FabriqStack::site();
?>
/app/controllers</code></li>
	<li><code>sites/<?php 
echo FabriqStack::site();
?>
/app/views</code></li>
</ul>
<p>Now that your Fabriq app is installed, you can delete the .txt files from the root directory of your project.</p>
<p><a href="<?php 
echo PathMap::build_path();
?>
">Return to the Fabriq app's homepage</a></p>
예제 #4
0
 /**
  * Determine what site is currently being served
  */
 public static function determineSite()
 {
     $availableSites = scandir('sites');
     $sites = array();
     foreach ($availableSites as $site) {
         if ($site != '.' && $site != '..' && $site != 'skeleton' && $site != 'default' && $site != 'README.txt') {
             $sites[] = $site;
         }
     }
     rsort($sites);
     if (count($sites)) {
         //$url = str_replace('/', '_', str_replace('http://', '', str_replace('https://', '', $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'])));
         $url = str_replace('http://', '', str_replace('https://', '', $_SERVER['HTTP_HOST']));
         foreach ($sites as $s) {
             if (strpos($url, $s) !== FALSE) {
                 self::$site = $s;
                 break;
             }
         }
     }
 }
 /**
  * Install step 3
  * Database configuration details
  */
 protected function install_step3($continue = TRUE)
 {
     Fabriq::title('Database configuration');
     // go back to site configuration step if the session isn't set
     if (!isset($_SESSION['FAB_INSTALL_site']) || $_SESSION['FAB_INSTALL_site'] == '') {
         PathMap::arg(2, 2);
         $this->install_step2();
     }
     if (isset($_POST['submit'])) {
         if (strlen(trim($_POST['db'])) == 0) {
             Messaging::message('You must enter a database name');
         }
         if (strlen(trim($_POST['user'])) == 0) {
             Messaging::message('You must enter a database user');
         }
         if (strlen(trim($_POST['pwd'])) == 0) {
             Messaging::message('You must enter a database user password');
         }
         if (strlen(trim($_POST['server'])) == 0) {
             Messaging::message('You must enter a database server');
         }
         // test database connectivity
         $mysqli = @mysqli_connect(trim($_POST['server']), trim($_POST['user']), trim($_POST['pwd']), trim($_POST['db']));
         if (!$mysqli) {
             Messaging::message('Error connecting to the database. Please check your database settings and try again.');
         } else {
             mysqli_close($mysqli);
         }
         if (!Messaging::has_messages()) {
             $dbConfig = array('db' => trim($_POST['db']), 'user' => trim($_POST['user']), 'pwd' => trim($_POST['pwd']), 'server' => trim($_POST['server']));
             $_SESSION['FAB_INSTALL_db'] = serialize($dbConfig);
             // write out configuration file
             $siteConfig = unserialize($_SESSION['FAB_INSTALL_site']);
             $confFile = 'sites/' . FabriqStack::site() . '/config/config.inc.php';
             $fh = fopen($confFile, 'w');
             fwrite($fh, "<?php\n");
             fwrite($fh, "/**\n");
             fwrite($fh, " * @file\n");
             fwrite($fh, " * Base config file for a Fabriq app.\n");
             fwrite($fh, " */\n\n");
             fwrite($fh, "\$_FAPP = array(\n");
             fwrite($fh, "\t'title' => \"{$siteConfig['title']}\",\n");
             fwrite($fh, "\t'title_pos' => '{$siteConfig['title_pos']}',\n");
             fwrite($fh, "\t'title_sep' => \"{$siteConfig['title_sep']}\",\n");
             fwrite($fh, "\t'cleanurls' => {$siteConfig['cleanurls']},\n");
             fwrite($fh, "\t'cdefault' => 'homepage',\n");
             fwrite($fh, "\t'adefault' => 'index',\n");
             fwrite($fh, "\t'url' => '{$siteConfig['url']}',\n");
             fwrite($fh, "\t'apppath' => '{$siteConfig['apppath']}',\n");
             fwrite($fh, "\t'templates' => array(\n");
             fwrite($fh, "\t\t'default' => 'application'\n");
             fwrite($fh, "\t)\n");
             fwrite($fh, ");\n\n");
             fwrite($fh, "\$_FDB['default'] = array(\n");
             fwrite($fh, "\t'user' => '{$_POST['user']}',\n");
             fwrite($fh, "\t'pwd' => '{$_POST['pwd']}',\n");
             fwrite($fh, "\t'db' => '{$_POST['db']}',\n");
             fwrite($fh, "\t'server' => '{$_POST['server']}'\n");
             fwrite($fh, ");\n");
             fclose($fh);
             // write default controller if the file isn't already there
             // file may exist from being created in a dev environment or this is
             // a distributed web app
             $contFile = 'sites/' . FabriqStack::site() . "/app/controllers/homepage.controller.php";
             if (!file_exists($contFile)) {
                 $fh = fopen($contFile, 'w');
                 fwrite($fh, "<?php\n");
                 fwrite($fh, "class homepage_controller extends Controller {\n");
                 fwrite($fh, "\tfunction index() {\n");
                 fwrite($fh, "\t\tFabriq::title('Welcome to {$siteConfig['title']}');\n");
                 fwrite($fh, "\t}\n");
                 fwrite($fh, "}\n");
                 fclose($fh);
             }
             // write default action if it doesn't already exist
             // may already exist from being created in a dev environmentor this is
             // a distributed web app
             if (!is_dir('sites/' . FabriqStack::site() . "/app/views/homepage")) {
                 mkdir('sites/' . FabriqStack::site() . "/app/views/homepage");
             }
             $actionFile = 'sites/' . FabriqStack::site() . "/app/views/homepage/index.view.php";
             if (!file_exists($actionFile)) {
                 $fh = fopen($actionFile, 'w');
                 fwrite($fh, "<h1>homepage#index</h1>\n");
                 fclose($fh);
             }
             // create the framework database tables
             global $db;
             $db_info = array('server' => trim($_POST['server']), 'user' => trim($_POST['user']), 'pwd' => trim($_POST['pwd']), 'db' => trim($_POST['db']));
             $db = new Database($db_info);
             // install config table
             $query = "CREATE TABLE IF NOT EXISTS  `fabriq_config` (\n\t\t\t\t\t\t`version` VARCHAR(10) NOT NULL,\n\t\t\t\t\t\t`installed` DATETIME NOT NULL,\n\t\t\t\t\t\tPRIMARY KEY (`version`)\n\t\t\t\t\t) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
             $db->query($query);
             $query = "INSERT INTO fabriq_config (version, installed) VALUES (?, ?)";
             $db->prepare_cud($query, array($this->installVersion, date('Y-m-d H:i:s')));
             // modules table
             $query = "CREATE TABLE IF NOT EXISTS `fabmods_modules` (\n\t\t\t\t\t\t`id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t\t`module` varchar(100) NOT NULL,\n\t\t\t\t\t\t`enabled` tinyint(4) NOT NULL,\n\t\t\t\t\t\t`hasconfigs` tinyint(1) NOT NULL,\n\t\t\t\t\t\t`installed` tinyint(1) NOT NULL,\n\t\t\t\t\t\t`versioninstalled` varchar(20) NOT NULL,\n\t\t\t\t\t\t`description` text NOT NULL,\n\t\t\t\t\t\t`dependson` text,\n\t\t\t\t\t\t`created` datetime NOT NULL,\n\t\t\t\t\t\t`updated` datetime NOT NULL,\n\t\t\t\t\t\tPRIMARY KEY (`id`)\n\t\t\t\t\t) ENGINE=InnoDB  DEFAULT CHARSET=utf8;";
             $db->query($query);
             // module configs table
             $query = "CREATE TABLE IF NOT EXISTS `fabmods_module_configs` (\n\t\t\t\t\t\t`id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t\t`module` int(11) NOT NULL,\n\t\t\t\t\t\t`var` varchar(100) NOT NULL,\n\t\t\t\t\t\t`val` text NOT NULL,\n\t\t\t\t\t\t`created` datetime NOT NULL,\n\t\t\t\t\t\t`updated` datetime NOT NULL,\n\t\t\t\t\t\tPRIMARY KEY (`id`)\n\t\t\t\t\t) ENGINE=InnoDB  DEFAULT CHARSET=utf8;";
             $db->query($query);
             // module perms table
             $query = "CREATE TABLE IF NOT EXISTS `fabmods_perms` (\n\t\t\t\t\t\t`id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t\t`permission` varchar(100) NOT NULL,\n\t\t\t\t\t\t`module` int(11) NOT NULL,\n\t\t\t\t\t\t`created` datetime NOT NULL,\n\t\t\t\t\t\t`updated` datetime NOT NULL,\n\t\t\t\t\t\tPRIMARY KEY (`id`)\n\t\t\t\t\t) ENGINE=InnoDB  DEFAULT CHARSET=utf8;";
             $db->query($query);
             // install the module events table
             $query = "CREATE TABLE IF NOT EXISTS `fabmods_module_events` (\n\t\t\t\t\t`id` INT(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t`eventModule` VARCHAR(50) NOT NULL,\n\t\t\t\t\t`eventAction` VARCHAR(50) NOT NULL,\n\t\t\t\t\t`eventName` VARCHAR(100) NOT NULL,\n\t\t\t\t\t`handlerModule` VARCHAR(50) NOT NULL,\n\t\t\t\t\t`handlerAction` VARCHAR(50) NOT NULL,\n\t\t\t\t\tPRIMARY KEY (`id`)\n\t\t\t\t) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
             $db->query($query);
             if (!isset($_SESSION['FAB_INSTALL_mods_installed'])) {
                 Messaging::message('Configuration file has been written', 'success');
                 Messaging::message('Core database tables have been created', 'success');
                 FabriqModules::register_module('pathmap');
                 FabriqModules::register_module('roles');
                 FabriqModules::register_module('users');
                 FabriqModules::register_module('sitemenus');
                 FabriqModules::register_module('fabriqmodules');
                 FabriqModules::register_module('fabriqinstall');
                 FabriqModules::install('pathmap');
                 $module = new Modules();
                 $module->getModuleByName('pathmap');
                 $module->enabled = 1;
                 $module->update();
                 Messaging::message('Installed pathmap module', 'success');
                 FabriqModules::install('roles');
                 $module = new Modules();
                 $module->getModuleByName('roles');
                 $module->enabled = 1;
                 $module->update();
                 Messaging::message('Installed roles module', 'success');
                 FabriqModules::install('users');
                 $module = new Modules();
                 $module->getModuleByName('users');
                 $module->enabled = 1;
                 $module->update();
                 Messaging::message('Installed users module', 'success');
                 FabriqModules::register_module('sitemenus');
                 FabriqModules::install('sitemenus');
                 $module = new Modules();
                 $module->getModuleByName('sitemenus');
                 $module->enabled = 1;
                 $module->update();
                 Messaging::message('Installed sitemenus module', 'success');
                 FabriqModules::register_module('fabriqmodules');
                 FabriqModules::install('fabriqmodules');
                 $module = new Modules();
                 $module->getModuleByName('fabriqmodules');
                 $module->enabled = 1;
                 $module->update();
                 Messaging::message('Installed fabriqmodules module', 'success');
                 FabriqModules::register_module('fabriqinstall');
                 FabriqModules::install('fabriqinstall');
                 $module = new Modules();
                 $module->getModuleByName('fabriqinstall');
                 $module->enabled = 1;
                 $module->update();
                 Messaging::message('Installed fabriqinstall module', 'success');
                 // get admin role and give it all perms so that the admin can actually set
                 // things up
                 $role = FabriqModules::new_model('roles', 'Roles');
                 $role->getRole('administrator');
                 $perms = new Perms();
                 $perms->getAll();
                 foreach ($perms as $perm) {
                     $modPerm = FabriqModules::new_model('roles', 'ModulePerms');
                     $modPerm->permission = $perm->id;
                     $modPerm->role = $role->id;
                     $modPerm->create();
                 }
                 $_SESSION['FAB_INSTALL_mods_installed'] = true;
             }
             if ($continue) {
                 // go to next step
                 header("Location: " . PathMap::build_path('fabriqinstall', 'install', 4));
                 exit;
             }
         }
         FabriqModules::set_var('fabriqinstall', 'submitted', true);
     }
 }
예제 #6
0
    $aPath = str_replace('index.php?q=', '', $aPath);
    $aPath = explode('/', $aPath);
    $i = 0;
    while ($aPath[$i] != 'fabriqinstall' && $i < count($aPath)) {
        $appPath .= $aPath[$i] . '/';
        $i++;
    }
    $_FAPP['url'] = "http://{$_SERVER['HTTP_HOST']}";
    $_FAPP['apppath'] = str_replace('//', '/', $appPath);
}
// require the core files
FabriqStack::requireCore();
// check if user is logged in and if not give viewer
// unathenticated role
FabriqStack::checkUserStatus();
// determine the controller and action to render
PathMap::map_path();
// determine which template to set initially
FabriqTemplates::init();
// include the controller and action files
if (file_exists('sites/' . FabriqStack::site() . '/app/controllers/application.controller.php')) {
    require_once 'sites/' . FabriqStack::site() . '/app/controllers/application.controller.php';
} else {
    require_once 'app/controllers/application.controller.php';
}
FabriqStack::processQueue();
FabriqTemplates::render();
// close the database connection
if ($installed) {
    $db->close();
}
 private function scan_modules()
 {
     $modules = array();
     // scan the site's modules directory
     if ($handle = opendir('sites/' . FabriqStack::site() . '/modules')) {
         while (false !== ($file = readdir($handle))) {
             if (strpos($file, '.') === FALSE && is_dir('sites/' . FabriqStack::site() . '/modules/' . $file)) {
                 $modules[] = $file;
             }
         }
         closedir($handle);
     }
     // scan the common modules directory
     if ($handle = opendir('modules')) {
         while (false !== ($file = readdir($handle))) {
             if (strpos($file, '.') === FALSE && is_dir('modules/' . $file)) {
                 if (!in_array($file, $modules)) {
                     $modules[] = $file;
                 }
             }
         }
         closedir($handle);
     }
     return $modules;
 }