/** * Add the admin to the users table * * @author Schmalls / Joshua Thompson <*****@*****.**> * @version 0.0.0 * @since 0.0.0 * @access public * @static * @param array $post_array posted variables */ public static function addAdmin($post_array) { global $_whomp_storage_path; // create the database options array $database_options = array('type' => $post_array['database_type'], 'host' => $post_array['database_host'], 'username' => $post_array['database_user'], 'password' => $post_array['database_password'], 'database' => $post_array['database_name'], 'table_prefix' => $post_array['database_prefix']); // try to connect to the database try { $database = new Whomp_Database($database_options); $record = array('username' => $post_array['admin_user'], 'name' => $post_array['admin_name'], 'email' => $post_array['admin_email'], 'password' => md5($post_array['admin_password']), 'usertype' => 'admin', 'last_visit_date' => date('Y-m-d H:i:s'), 'register_date' => date('Y-m-d H:i:s')); $database->insert('#__users', $record); } catch (Exception $e) { whomp_output_exception($e, true); } // end try return true; }
/** * Gets the requested node array * * Retrieves the node information from the database as an array. * * @author Schmalls / Joshua Thompson <*****@*****.**> * @version 0.0.0 * @since 0.0.0 * @param array $options the requested node options * @global class access to the database * @global array the accept headers * @global class access to the configuration options * @return object the node object */ function whomp_get_node_array($options) { global $_whomp_database, $_whomp_accept_headers, $_whomp_configuration; // get the node information from the database $node_language = ''; try { // check if any languages are available if (!empty($_whomp_accept_headers['languages'])) { // if so, go until we find a node in an acceptable language foreach ($_whomp_accept_headers['languages'] as $language => $qvalue) { $queryValues = array($options['node']); $query = 'SELECT * FROM `#__' . $language . '_nodes` WHERE `name` = %s;'; $_whomp_database->setQuery($query, $queryValues); $_whomp_database->query(); $node_array = $_whomp_database->loadRow(); // check if the node was available if (!empty($node_array)) { // if so, set language and break $node_language = $language; break; } // end if } // end foreach } else { // if not, throw exception throw new Exception('No languages are available.'); } // end if } catch (Exception $e) { whomp_output_exception($e, true); } // end try // check if the node was found if (!empty($node_array)) { // if so, set status to ok header('Status: 200 OK'); } else { // if not, set status to 404 and get error node header('Status: 404 Not Found'); try { // go until we find an error node in an acceptable language foreach ($_whomp_accept_headers['languages'] as $language => $qvalue) { $queryValues = array($_whomp_configuration->node_error_node); $query = 'SELECT * FROM `#__' . $language . '_nodes` WHERE `name` = %s;'; $_whomp_database->setQuery($query, $queryValues); $_whomp_database->query(); $node_array = $_whomp_database->loadRow(); // check if the node was available if (!empty($node_array)) { // if so, set language and break $node_language = $language; break; } // end if } // end foreach } catch (Exception $e) { whomp_output_exception($e, true); } // end try } // end if // add page and format information to the node array $node_array['page'] = $options['page']; $node_array['language'] = $node_language; // create layout array if ($node_array['layouts'] != '') { $layouts = explode("\n", $node_array['layouts']); $node_array['layouts'] = array(); foreach ($layouts as $layout) { $layout = explode(',', $layout . ',,,'); $node_array['layouts'][trim($layout[0])] = array('layout' => trim($layout[1]), 'template' => trim($layout[2]), 'format' => trim($layout[3])); } // end foreach } else { $node_array['layouts'] = array(); } // end if // create parents array $node_array['parents'] = explode(',', $node_array['parents']); // create children array $node_array['children'] = explode(',', $node_array['children']); // create relatives array $node_array['relatives'] = explode(',', $node_array['relatives']); // create the group permissions array if ($node_array['_group'] != '') { $group_permissions = explode("\n", $node_array['_group']); $node_array['_group'] = array(); foreach ($group_permissions as $group_permission) { $group_permission = explode(',', $group_permission); $node_array['_group'][trim($group_permission[0])] = trim($group_permission[1]); } // end foreach } else { $node_array['_group'] = array(); } // end if // create the user permissions array if ($node_array['_user'] != '') { $user_permissions = explode("\n", $node_array['_user']); $node_array['_user'] = array(); foreach ($user_permissions as $user_permission) { $user_permission = explode(',', $user_permission); $node_array['_user'][trim($user_permission[0])] = trim($user_permission[1]); } // end foreach } else { $node_array['_user'] = array(); } // end if // get the most acceptable content type $node_array['content_type'] = whomp_get_content_type($options['content_type'], $node_array['layouts']); $node_array['layout'] = $node_array['layouts'][$node_array['content_type']]['layout']; $node_array['template'] = $node_array['layouts'][$node_array['content_type']]['template']; $node_array['format'] = $node_array['layouts'][$node_array['content_type']]['format']; return $node_array; }
// end try // check if an operation is requested $whomp_operation = whomp_get_param('whomp_operation', null); if ($whomp_operation !== null) { // if so, check if the whomp editor class exists try { /** * The whomp editor class * * @global class $_whomp_editor_class */ $_whomp_editor_class = whomp_get_editor_class(); // load the node information into the editor class $_whomp_editor_class->loadEditor($_whomp_node_array); } catch (Exception $e) { whomp_output_exception($e); } // end try // switch by operation switch ($whomp_operation) { case 'xml': // check if we are supposed to save if ($_SERVER['REQUEST_METHOD'] == 'POST') { // if so, save $_whomp_node_class->save(); } else { // if not, print the node xml $_whomp_node_class->printXml(); } // end if break;
/** * Creates a new user * * The options array should be in the following format: * <pre> * Array ( * 'username' => the username * 'password' => the supplied password * 'confirm_password' => the confirm password * 'name' => the user's name * 'usertype' => the user's type * 'email' => the user's email address * ) * </pre> * * @author Schmalls / Joshua Thompson <*****@*****.**> * @version 0.0.0 * @since 0.0.0 * @access public * @throws Exception if the passwords do not match * @param array $options the user options * @global class access to the database * @todo add confirmation functionality */ public function create($options) { global $_whomp_database; // check if the passwords match if ($options['password'] == $options['confimr_password']) { // if so, insert the user try { $insert = array('username' => $options['username'], 'password' => md5($options['password']), 'name' => $options['name'], 'usertype' => $options['usertype'], 'email' => $options['email'], 'last_visit_date' => date('Y-m-d H:i:s'), 'register_date' => date('Y-m-d H:i:s')); $_whomp_database->insert('#__users', $insert); // set the user id cookie setcookie('whomp_id', $_whomp_database->insertId()); } catch (Exception $e) { whomp_output_exception($e, true); } // end try } else { // if not, throw an exception throw new Exception('The supplied passwords do not match.'); } // end if }