From 9de81661c1e9e6b1156395ccdee1f3a1b47b0252 Mon Sep 17 00:00:00 2001 From: Felipe Date: Fri, 23 Apr 2010 11:01:01 -0600 Subject: [PATCH] Changed the modules settings page, now it is 'automatic', plus a few bug fixes. --- README | 20 ++++++++++++++ core/menu/menu.admin | 29 ++++++++++++++++---- core/system/system.admin | 71 +++++++++++++++++++++++++++++++++++++++++++----- core/user/user.admin | 20 ++------------ core/user/user.boot | 3 +- includes/bootstrap.inc | 5 +++- includes/core.inc | 17 +++++------- includes/path.inc | 2 ++ install/README | 19 +++++++++++++ 9 files changed, 143 insertions(+), 43 deletions(-) create mode 100644 README create mode 100644 install/README diff --git a/README b/README new file mode 100644 index 0000000..aa315c7 --- /dev/null +++ b/README @@ -0,0 +1,20 @@ +esTigi +======= +Felipe + +esTigi CMS will be focused on efficiency and usability. +We are currently on the first development stages of it, +but so far things are going great! + +About esTigi +------------- +This project started as a learning experience and because I +was not satisfied with the current CMS implementation in the +market, either they are to difficult to develop for or they are +to resource consuming and overloaded. +esTigi aims at been very powerful but always keeping in mind the +fact that if you will run a CMS in a shared hosting service, each +executing instance must be as light weighed as possible. + + +More to come soon... diff --git a/core/menu/menu.admin b/core/menu/menu.admin index 4eb02c8..d053911 100644 --- a/core/menu/menu.admin +++ b/core/menu/menu.admin @@ -63,7 +63,14 @@ function menu_admin(){ return $content; } - +/** + * Menu administration page + * + * @param $mid + * The menu id to administer + * @todo + * Use $db['num_rows'] when it works in order to see if a menu was found + */ function menu_admin_menu($mid){ global $skin; @@ -77,10 +84,15 @@ function menu_admin_menu($mid){ $menus = db_query("SELECT * FROM {PRE_}menu WHERE parent = ".$mid." OR mid = ".$mid." ORDER BY POS ASC", TRUE); + //Go away if the menu does not exist + if($menus == ""){ + path_redirect("menu/admin"); + } + core_load('form', 'api'); - $content = 'Click on any menu to modify it.'; - $content = 'Or click here to edit the ' . path_link('menu/admin/item/'.$mid, 'Parent Menu'); + $content = 'Click on any menu to modify it.
'; + $content .= 'Or click here to edit the ' . path_link('menu/admin/item/'.$mid, 'Parent Menu'); $content .= form_set_head('menu_admin_menu'). ' @@ -145,7 +157,7 @@ function menu_admin_item($mid = NULL){ $content = form_form($form); - if($form_status == 'delete_confirmed'){ //isset($_POST['submit'])){ + if($form_status == 'delete_confirmed'){ $q = _menu_delete_item($mid); if($q > 0){ @@ -260,6 +272,13 @@ function _menu_update_item($info, $type = 'update'){ } } +/** + * Deletes a menu item + * + * @param $mid + * The menu id to be deleted + * + */ function _menu_delete_item($mid){ global $db; @@ -267,7 +286,7 @@ function _menu_delete_item($mid){ //Lets see if this will cause bad parenting $childs = db_query("SELECT * FROM {PRE_}menu WHERE parent = ".$mid.""); - if($db['num_rows'] > 0){ + if($db['num_rows'] > 0){ print_r($childs); exit; system_warnings("Sorry, deleting this item would be bad parenting. You must first delete or reasign its child menus.", "error"); return -1; } diff --git a/core/system/system.admin b/core/system/system.admin index 6dbb351..14e15fe 100644 --- a/core/system/system.admin +++ b/core/system/system.admin @@ -124,26 +124,61 @@ function system_settings_form(){ return $form; } -// FORMS +/** + * Set values for admin form + * + * @param &$form + * The form with the values + * @param $module + * Working module + */ function system_convert_form_admin(&$form, $module){ //modify default values if they have been set already foreach($form[$module.'_admin'] as $item => $value){ - $form[$module.'_admin'][$item]['value'] = core_variable_get($item, $value['value'], $module); + //Fieldsets + if($value['type'] == 'fieldset'){ + foreach($value as $field => $field_value){ + if(is_array($field_value)){ + $form[$module.'_admin'][$item][$field]['value'] = core_variable_get($field, $field_value['value'], $module); + } + } + } } } +/** + * Registers modules variables for the modules settings + * + * @param &$form + * The form with the information + * @param $module + * The working module + * @todo + * Not very convinced in the fieldset handling method + */ function system_process_form_admin(&$form, $module){ global $x; + //Remove all variables + core_variable_rm(FALSE, $module, TRUE); + foreach($form[$module.'_admin'] as $item => $value){ - if($value['type'] != 'submit') + if($value['type'] == 'fieldset'){ + foreach($value as $field => $field_value){ + if(is_array($field_value)){ + core_variable_set($field, $field_value['value'], $module); + } + } + } + if($value['type'] != 'submit' && $value['type'] != 'fieldset'){ core_variable_set($item, $value['value'], $module); + } } system_warnings("Changes succesfully made"); @@ -158,11 +193,34 @@ function system_process_form_admin(&$form, $module){ * Function to call in order to get the appropriate form * @param $module * The module that wants to get/set settings + * @param $perms + * An array with a list of access permissions in order to access this form + * @param $title + * The page title, will use 'Foo Settings Page' by default + * @param $file + * The file extension in which your function is located, default = admin (will load foo.admin) * */ -function system_settings_get($func, $module){ +function system_settings_page($func, $module, $perms, $title = NULL, $file = 'admin'){ + + global $form_status, $skin; + + //No access by default + $access = FALSE; + + foreach($perms as $perm){ + if(user_access($perm)){ + $access = TRUE; + } + } + + if(!$access){ + return PATH_NO_ACCESS; + } - global $form_status; + $skin['page_title'] = (!$title ? $module.' Settings Page' : $title); + + core_load($module, $file); $form = call_user_func($func); @@ -181,7 +239,6 @@ function system_settings_get($func, $module){ if($form_status == 'verified'){ //Process the form - system_process_form_admin($content, $module); } @@ -197,7 +254,7 @@ function system_settings(){ $skin['page_title'] = 'System main settings'; - return system_settings_get('system_settings_form', 'system'); + return system_settings_page('system_settings_form', 'system'); } diff --git a/core/user/user.admin b/core/user/user.admin index 10aeb6b..e46d637 100644 --- a/core/user/user.admin +++ b/core/user/user.admin @@ -24,7 +24,8 @@ function user_settings_form(){ 'type' => 'radio', 'text' =>'', 'options' => array('an' => 'Anyone without administration approval', 'admin' => 'Only administrators can register new users', 'aa' => 'Anyone, but administrative approval is requried'), - 'value' => 'an' + 'value' => 'an', + 'use_keys' => TRUE ); /* @@ -39,23 +40,6 @@ function user_settings_form(){ } /** - * General user management settings page - */ -function user_settings(){ - - global $skin; - - $skin['page_title'] = 'User\'s Settings'; - - if(!user_access('users admin')){ - return PATH_NO_ACCESS; - } - - return system_settings_get('user_settings_form', 'user'); - -} - -/** * User filter form * * @todo diff --git a/core/user/user.boot b/core/user/user.boot index d4bac5c..9833fc9 100644 --- a/core/user/user.boot +++ b/core/user/user.boot @@ -44,8 +44,7 @@ function user_isityou(){ user_logout(); break; case 'user/admin/settings': - core_load('user', 'admin'); - return user_settings(); + return system_settings_page('user_settings_form', 'user', array('users admin'), 'User\'s Settings Page'); break; case 'user/admin/list': core_load('user', 'admin'); diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc index 10ad8e8..aae0f4f 100644 --- a/includes/bootstrap.inc +++ b/includes/bootstrap.inc @@ -5,6 +5,9 @@ * Booting system * * @ingroup System + * + * @todo + * Set definitions for the booting system in the form of runlevels */ @@ -21,7 +24,7 @@ function boot_variable_init($owner = 'system') { global $settings; - $result = db_query("SELECT * FROM {PRE_}variable WHERE owner = '".$owner."'", TRUE, TRUE); + $result = db_query("SELECT * FROM {PRE_}variable WHERE owner = '".$owner."'", TRUE); if($result){ foreach($result as $variable){ diff --git a/includes/core.inc b/includes/core.inc index 90ca294..800f53f 100644 --- a/includes/core.inc +++ b/includes/core.inc @@ -243,22 +243,18 @@ function core_variable_get($name, $default, $owner = 'system'){ * @param $value * The value to set. This can be any PHP data type; these functions take care * of serialization as necessary. + * @param $owner + * The owner of the variable + * */ function core_variable_set($name, $value, $owner) { - global $db, $settings; - + $serialized_value = serialize($value); - //db_query("UPDATE {PRE_}variable SET value = '".$serialized_value."' WHERE name ='".$name."' AND owner ='".$owner."'"); db_query("DELETE FROM {PRE_}variable WHERE name ='".$name."' AND owner ='".$owner."'"); -//echo "UPDATE {PRE_}variable SET value = '".$serialized_value."' WHERE name = '".$name."' AND owner = '".$owner."'"; -//print_r($db); exit; - //if ($db['affected_rows'] == 0) { - db_query("INSERT INTO {PRE_}variable (name, value, owner) VALUES ('".$name."', '".$serialized_value."', '".$owner."')"); -//print_r($db); exit; - //} + db_query("INSERT INTO {PRE_}variable (name, value, owner) VALUES ('".$name."', '".$serialized_value."', '".$owner."')"); $setings['variables'][$owner][$name] = $value; } @@ -281,7 +277,8 @@ function core_variable_rm($name, $owner, $all = FALSE){ db_query("DELETE FROM {PRE_}variable WHERE name = '".$name."' AND owner = '".$owner."'"); unset($setings['variables'][$owner][$name]); } - else{ + //Just for security you must specify the $all parameter + elseif(!$name && $all){ db_query("DELETE FROM {PRE_}variable WHERE owner = '".$owner."'"); unset($setings['variables'][$owner]); } diff --git a/includes/path.inc b/includes/path.inc index 9f8e646..c7773d9 100644 --- a/includes/path.inc +++ b/includes/path.inc @@ -87,6 +87,8 @@ function path_trim($path = NULL){ * If this path is an alias, in which case we look for its internal path * @todo * Use the wildcard feature when you want to get an alias for a path + * @bug + * It does not work if the path is one word vg: 'user' * */ diff --git a/install/README b/install/README new file mode 100644 index 0000000..fe4e4fb --- /dev/null +++ b/install/README @@ -0,0 +1,19 @@ +As you can imagine, it is a manual install, but it is very simple, not very different from other manual installs. + +Step by step: +============= + +1. Create database using your prefered method. +2. Load the sql script located in this same folder. +3. Modify settings.php with the database information. But only this variables + $db['user'] = ''; + $db['pwd'] = ''; + $db['host'] = 'localhost'; + $db['db'] = ''; + +User: root +Password: 123 + +Ready to run!!!! + +This is more than a basic install and there is not much you can do with esTigi yet, but there will soon be a lot of improvements. -- 2.11.4.GIT