Example #1
0
 private function register_modules()
 {
     if (is_array($this->module_folders) and count($this->module_folders) >= 1) {
         $registered_module_array = BaseModule_Access::list_folder_entries();
         $found_module_array = array();
         $module_requirements_array = array();
         foreach ($this->module_folders as $key => $value) {
             $config_folder = $value . "/config";
             if (is_dir($config_folder)) {
                 $config_file = $config_folder . "/module_info.php";
                 if (is_file($config_file)) {
                     require $config_file;
                     $module_dialog_file = $config_folder . "/module_dialog.php";
                     if (!is_file($module_dialog_file)) {
                         unset($module_dialog_file);
                     }
                     $module_link_file = $config_folder . "/module_link.php";
                     if (!is_file($module_link_file)) {
                         unset($module_link_file);
                     }
                     if (($register_key = array_search(str_replace(constant("MODULES_DIR") . "/", "", $value), $registered_module_array)) !== false) {
                         $config_info_changed = false;
                         $found_module_array[$register_key] = str_replace(constant("MODULES_DIR") . "/", "", $value);
                         $config_file_checksum = BaseModuleFile_Access::get_checksum_by_module_id_and_name($register_key, "module_info.php");
                         if ($config_file_checksum != md5_file($config_file)) {
                             $config_info_changed = true;
                             $base_module = new BaseModule_Access($register_key);
                             if ($base_module->set_name($name) == false) {
                                 throw new BaseModuleProcessFailedException();
                             }
                             if ($base_module->set_class($main_class) == false) {
                                 throw new BaseModuleProcessFailedException();
                             }
                             $module_info_id = BaseModuleFile_Access::get_id_by_module_id_and_name($register_key, "module_info.php");
                             if ($module_info_id != null) {
                                 $base_module_file = new BaseModuleFile_Access($module_info_id);
                                 $base_module_file->set_checksum(md5_file($config_file));
                             } else {
                                 $base_module_file = new BaseModuleFile_Access(null);
                                 if ($base_module_file->create($register_key, "module_info.php", md5_file($config_file)) == null) {
                                     throw new BaseModuleProcessFailedException();
                                 }
                             }
                             if (is_array($tab) and count($tab) >= 1) {
                                 $tab_array = array();
                                 $tab_list = BaseModuleNavigation_Access::list_entries_by_module_id($register_key);
                                 foreach ($tab as $tab_key => $tab_value) {
                                     array_push($tab_array, $tab_value['language_address']);
                                     if (is_array($tab_list[$tab_value['language_address']])) {
                                         if (trim($tab_list[$tab_value['language_address']]['colour']) != $tab_value['colour']) {
                                             $base_module_navigation = new BaseModuleNavigation_Access($tab_list[$tab_value['language_address']]['id']);
                                             $base_module_navigation->set_colour($tab_value['colour']);
                                         }
                                         if (trim($tab_list[$tab_value['language_address']]['controller_class']) != $tab_value['controller_class']) {
                                             $base_module_navigation = new BaseModuleNavigation_Access($tab_list[$tab_value['language_address']]['id']);
                                             $base_module_navigation->set_controller_class($tab_value['controller_class']);
                                         }
                                         if (trim($tab_list[$tab_value['language_address']]['controller_file']) != $tab_value['controller_class']) {
                                             $base_module_navigation = new BaseModuleNavigation_Access($tab_list[$tab_value['language_address']]['id']);
                                             $base_module_navigation->set_controller_file($tab_value['controller_file']);
                                         }
                                         if (trim($tab_list[$tab_value['language_address']]['alias']) != $tab_value['controller_class']) {
                                             $base_module_navigation = new BaseModuleNavigation_Access($tab_list[$tab_value['language_address']]['id']);
                                             $base_module_navigation->set_alias($tab_value['alias']);
                                         }
                                     } else {
                                         $position = BaseModuleNavigation_Access::get_highest_position();
                                         $base_module_navigation = new BaseModuleNavigation_Access(null);
                                         if ($base_module_navigation->create($tab_value['language_address'], $tab_value['colour'], $position + 1, $register_key, $tab_value['controller_class'], $tab_value['controller_file'], $tab_value['alias']) == null) {
                                             throw new BaseModuleProcessFailedException();
                                         }
                                     }
                                 }
                                 if (is_array($tab_list) and count($tab_list) >= 1) {
                                     foreach ($tab_list as $tab_list_key => $tab_list_value) {
                                         if (!in_array($tab_list_key, $tab_array)) {
                                             $base_module_navigation = new BaseModuleNavigation_Access($tab_list_value['id']);
                                             if ($base_module_navigation->delete() == false) {
                                                 throw new BaseModuleProcessFailedException();
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                         if (isset($module_dialog_file)) {
                             $module_dialog_checksum = BaseModuleFile_Access::get_checksum_by_module_id_and_name($register_key, "module_dialog.php");
                             if ($module_dialog_checksum != md5_file($module_dialog_file)) {
                                 require $module_dialog_file;
                                 if (BaseModuleDialog_Access::delete_by_module_id($register_key) == false) {
                                     throw new BaseModuleProcessFailedException();
                                 }
                                 // Register Dialog
                                 if (is_array($dialog) and count($dialog) >= 1) {
                                     foreach ($dialog as $dialog_key => $dialog_value) {
                                         $base_module_dialog = new BaseModuleDialog_Access(null);
                                         if ($base_module_dialog->create($register_key, $dialog_value['type'], $dialog_value['class_path'], $dialog_value['class'], $dialog_value['method'], $dialog_value['internal_name'], $dialog_value['language_address'], $dialog_value['weight']) == null) {
                                             throw new BaseModuleDialogCreationFailedException();
                                         }
                                     }
                                 }
                                 $module_dialog_id = BaseModuleFile_Access::get_id_by_module_id_and_name($register_key, "module_dialog.php");
                                 if ($module_dialog_id != null) {
                                     $base_module_file = new BaseModuleFile_Access($module_dialog_id);
                                     $base_module_file->set_checksum(md5_file($module_dialog_file));
                                 } else {
                                     $base_module_file = new BaseModuleFile_Access(null);
                                     if ($base_module_file->create($register_key, "module_dialog.php", md5_file($module_dialog_file)) == null) {
                                         throw new BaseModuleProcessFailedException();
                                     }
                                 }
                                 unset($dialog);
                             }
                         }
                         if (isset($module_link_file)) {
                             $module_link_checksum = BaseModuleFile_Access::get_checksum_by_module_id_and_name($register_key, "module_link.php");
                             if ($module_link_checksum != md5_file($module_link_file)) {
                                 require $module_link_file;
                                 if (BaseModuleLink_Access::delete_by_module_id($register_key) == false) {
                                     throw new BaseModuleProcessFailedException();
                                 }
                                 // Register Dialog
                                 if (is_array($link) and count($link) >= 1) {
                                     foreach ($link as $link_key => $link_value) {
                                         $base_module_link = new BaseModuleLink_Access(null);
                                         if ($base_module_link->create($register_key, $link_value['type'], serialize($link_value['array']), $link_value['file'], $link_value['weight']) == null) {
                                             throw new ModuleLinkCreationFailedException();
                                         }
                                     }
                                 }
                                 $module_link_id = BaseModuleFile_Access::get_id_by_module_id_and_name($register_key, "module_link.php");
                                 if ($module_link_id != null) {
                                     $base_module_file = new BaseModuleFile_Access($module_link_id);
                                     $base_module_file->set_checksum(md5_file($module_link_file));
                                 } else {
                                     $base_module_file = new BaseModuleFile_Access(null);
                                     if ($base_module_file->create($register_key, "module_link.php", md5_file($module_link_file)) == null) {
                                         throw new BaseModuleProcessFailedException();
                                     }
                                 }
                                 unset($link);
                             }
                         }
                     } else {
                         // Register new includes
                         if (is_array($requires) and count($requires) >= 1) {
                             $module_requirements_array[str_replace(constant("MODULES_DIR") . "/", "", $value)] = $required_include;
                         }
                         // Register includes
                         $base_module = new BaseModule_Access(null);
                         if (($base_module_id = $base_module->create($name, str_replace(constant("MODULES_DIR") . "/", "", $value), $main_class)) == null) {
                             throw new BaseModuleProcessFailedException();
                         } else {
                             $base_module_file = new BaseModuleFile_Access(null);
                             if ($base_module_file->create($base_module_id, "module_info.php", md5_file($config_file)) == null) {
                                 throw new BaseModuleProcessFailedException();
                             }
                         }
                         if (is_array($tab) and count($tab) >= 1) {
                             foreach ($tab as $tab_key => $tab_value) {
                                 $position = BaseModuleNavigation_Access::get_highest_position();
                                 $base_module_navigation = new BaseModuleNavigation_Access(null);
                                 if ($base_module_navigation->create($tab_value['language_address'], $tab_value['colour'], $position + 1, $base_module_id, $tab_value['controller_class'], $tab_value['controller_file'], $tab_value['alias']) == null) {
                                     throw new BaseModuleProcessFailedException();
                                 }
                             }
                         }
                         if (isset($module_dialog_file)) {
                             require $module_dialog_file;
                             $base_module_file = new BaseModuleFile_Access(null);
                             if ($base_module_file->create($base_module_id, "module_dialogs.php", md5_file($module_dialog_file)) == null) {
                                 throw new BaseModuleProcessFailedException();
                             }
                             // Register Dialog
                             if (is_array($dialog) and count($dialog) >= 1) {
                                 foreach ($dialog as $dialog_key => $dialog_value) {
                                     $base_module_dialog = new BaseModuleDialog_Access(null);
                                     if ($base_module_dialog->create($base_module_id, $dialog_value['type'], $dialog_value['class_path'], $dialog_value['class'], $dialog_value['method'], $dialog_value['internal_name'], $dialog_value['language_address'], $dialog_value['weight']) == null) {
                                         throw new BaseModuleDialogCreationFailedException();
                                     }
                                 }
                             }
                             unset($dialog);
                         }
                         if (isset($module_link_file)) {
                             require $module_link_file;
                             $base_module_file = new BaseModuleFile_Access(null);
                             if ($base_module_file->create($base_module_id, "module_link.php", md5_file($module_link_file)) == null) {
                                 throw new BaseModuleProcessFailedException();
                             }
                             // Register Dialog
                             if (is_array($link) and count($link) >= 1) {
                                 foreach ($link as $link_key => $link_value) {
                                     $base_module_link = new BaseModuleLink_Access(null);
                                     if ($base_module_link->create($base_module_id, $link_value['type'], serialize($link_value['array']), $link_value['file'], $link_value['weight']) == null) {
                                         throw new ModuleLinkCreationFailedException();
                                     }
                                 }
                             }
                             unset($link);
                         }
                         $found_module_array[$base_module_id] = str_replace(constant("MODULES_DIR") . "/", "", $value);
                     }
                 }
             }
             unset($name);
             unset($class);
             unset($tab);
             unset($required_include);
         }
         // Past Requirements Check
         $registered_module_array = BaseModule_Access::list_folder_entries();
         if (is_array($registered_module_array) and count($registered_module_array) >= 1) {
             foreach ($registered_module_array as $key => $value) {
                 if (isset($module_requirements_array[$value]) and is_array($module_requirements_array[$value]) and count($module_requirements_array[$value]) >= 1) {
                     foreach ($module_requirements_array[$value] as $sub_key => $sub_value) {
                         if (!in_array($sub_value, $module_requirements_array)) {
                             throw new ModuleRequirementFailedException();
                         }
                     }
                 }
             }
         }
         // Delete legacy modules
         $legacy_module_array = array_diff($registered_module_array, $found_module_array);
         if (is_array($legacy_module_array) and count($legacy_module_array) >= 1) {
             foreach ($legacy_module_array as $legacy_key => $legacy_value) {
                 if (BaseModuleFile_Access::delete_by_module_id($legacy_key) == false) {
                     throw new BaseModuleProcessFailedException();
                 }
                 $base_module_navigation_id = BaseModuleNavigation_Access::get_id_by_module_id($legacy_key);
                 $base_module_navigation = new BaseModuleNavigation_Access($base_module_navigation_id);
                 // Position
                 if ($base_module_navigation->get_next_position() != $base_module_navigation_id) {
                     $tmp_base_module_navigation = clone $base_module_navigation;
                     $tmp_base_module_navigation_id = $base_module_navigation_id;
                     $tmp_position = $base_module_navigation->get_position();
                     if ($base_module_navigation->set_position(null) === false) {
                         throw new BaseModuleProcessFailedException();
                     }
                     while (($next_base_module_navigation_id = $tmp_base_module_navigation->get_next_position()) != $tmp_base_module_navigation_id) {
                         $next_base_module_navigation = new BaseModuleNavigation_Access($next_base_module_navigation_id);
                         $next_position = $next_base_module_navigation->get_position();
                         if ($next_base_module_navigation->set_position($tmp_position) == false) {
                             throw new BaseModuleProcessFailedException();
                         } else {
                             $tmp_base_module_navigation = $next_base_module_navigation;
                             $tmp_base_module_navigation_id = $next_base_module_navigation_id;
                             $tmp_position = $next_position;
                         }
                     }
                 }
                 if (BaseModuleNavigation_Access::delete_by_module_id($legacy_key) == false) {
                     throw new BaseModuleProcessFailedException();
                 }
                 if (BaseModuleDialog_Access::delete_by_module_id($legacy_key) == false) {
                     throw new BaseModuleProcessFailedException();
                 }
                 $base_module = new BaseModule_Access($legacy_key);
                 if ($base_module->delete() == false) {
                     throw new BaseModuleProcessFailedException();
                 }
             }
         }
     }
 }
Example #2
0
 /**
  * @see EventListenerInterface::listen_events()
  * @param object $event_object
  * @return bool
  */
 public static function listen_events($event_object)
 {
     if ($event_object instanceof ModuleDisableEvent) {
         $id_array = BaseModuleDialog_Access::list_id_by_module_id($event_object->get_module_id());
         if (is_array($id_array) and count($id_array) >= 1) {
             foreach ($id_array as $key => $value) {
                 $module_dialog = new BaseModuleDialog_Access($value);
                 if ($module_dialog->get_disabled() == false) {
                     if ($module_dialog->set_disabled(true) == false) {
                         return false;
                     }
                 }
             }
         }
     }
     if ($event_object instanceof ModuleEnableEvent) {
         $id_array = BaseModuleDialog_Access::list_id_by_module_id($event_object->get_module_id());
         if (is_array($id_array) and count($id_array) >= 1) {
             foreach ($id_array as $key => $value) {
                 $module_dialog = new BaseModuleDialog_Access($value);
                 if ($module_dialog->get_disabled() == true) {
                     if ($module_dialog->set_disabled(false) == false) {
                         return false;
                     }
                 }
             }
         }
     }
     return true;
 }