Esempio n. 1
0
 /**
  * Process everything the queue
  */
 public static function processQueue()
 {
     if (!count(self::$queue)) {
         return false;
     }
     $next = FabriqStack::dequeue();
     while ($next->controller == '') {
         if (!count(self::$queue)) {
             return false;
         }
         FabriqStack::processQueue();
     }
     self::$processing = $next;
     switch ($next->type) {
         case 'module':
             $module =& FabriqModules::module($next->controller);
             call_user_func_array(array($module, $next->action), $next->extra);
             if (Fabriq::render() != 'none' && FabriqModules::has_permission() && !FabriqModules::stopMappedRender()) {
                 FabriqTemplates::renderToBody($next);
             }
             break;
         case 'controller':
         default:
             PathMap::controller($next->controller);
             PathMap::action($next->action);
             $file = "app/controllers/{$next->controller}.controller.php";
             if (file_exists('sites/' . FabriqStack::site() . "/{$file}")) {
                 require_once 'sites/' . FabriqStack::site() . "/{$file}";
             } else {
                 require_once $file;
             }
             $c = "{$next->controller}_controller";
             $controller = new $c();
             $a = str_replace('.', '_', $next->action);
             if (!$controller->hasMethod($a)) {
                 FabriqStack::error(404);
             }
             call_user_func(array($controller, $a));
             FabriqTemplates::renderToBody($next);
             break;
     }
     if (count(self::$queue)) {
         FabriqStack::processQueue();
     }
 }
 function __construct()
 {
     parent::__construct();
     global $installed;
     global $_FAPP;
     $processing = FabriqStack::processing();
     if ($processing->action == 'fetchUpdates') {
         return;
     }
     // make sure that we're good to run the requested action
     if ($processing->action == 'install' && $installed && PathMap::arg(2) < 4) {
         header("Location: " . PathMap::build_path($_FAPP['cdefault'], $_FAPP['adefault']));
         exit;
     } else {
         if ($processing->action == 'install' && $installed && PathMap::arg(2) == 4) {
             // determine which version is installed
             if (!isset($_POST['submit'])) {
                 global $db;
                 $query = "SHOW TABLES;";
                 $db->query($query);
                 $tables = array();
                 while ($row = $db->result->fetch_array()) {
                     $tables[] = $row[0];
                 }
                 if (in_array('fabmod_users_users', $tables)) {
                     $query = "SELECT COUNT(*) AS num FROM fabmod_users_users";
                     $db->query($query);
                     $row = $db->result->fetch_array();
                     if ($row['num'] > 0) {
                         header("Location: " . PathMap::build_path($_FAPP['cdefault'], $_FAPP['adefault']));
                         exit;
                     }
                 }
             }
         } else {
             if ($processing->action == 'update') {
                 // figure out what updates are available
                 global $db;
                 $query = "SELECT version FROM fabriq_config ORDER BY installed DESC, version DESC LIMIT 1";
                 $db->query($query);
                 $data = mysqli_fetch_array($db->result);
                 $this->version = $data['version'];
                 if (!FabriqModules::module('roles')->hasRole('administrator')) {
                     if ($this->version != null) {
                         header('Location: ' . PathMap::build_path('users', 'login', 'fabriqinstall', 'update'));
                         exit;
                     }
                 }
             }
         }
     }
     // set the install version
     $this->installVersion = '0.0';
     $updates = get_class_methods('fabriqinstall_module');
     foreach ($updates as $method) {
         if (substr($method, 0, 7) == 'update_' && substr($method, 0, 11) != 'update_step') {
             $version = str_replace('_', '.', str_replace('update_', '', $method));
             if ($version > $this->installVersion) {
                 $this->installVersion = $version;
             }
         }
     }
     // set up display elements
     Fabriq::empty_css_queue();
     FabriqModules::add_css('fabriqinstall', 'fabriqinstall');
     FabriqTemplates::template('fabriqinstall');
 }