static function XMLEntities($string) { // copied from php manual comments $string = preg_replace('/[^\\x09\\x0A\\x0D\\x20-\\x7F]/e', Bolts_Common::_privateXMLEntities("\$0"), $string); return $string; }
} else { $index_template_replacements = array("OBJECT_NICENAME" => $name, "THEME_GLOBAL_PATH_VAR_NAME" => "theme_global_path", "CREATE_NEW_URL" => "/" . $module_name . "/" . strtolower($name) . "/edit", "ROWSET_VAR" => strtolower($name), "THE_ID" => $identity_col, "INDEX_URL" => $index_url); } $index_template = Bolts_Common::replaceWithArray($index_template, $index_template_replacements); file_put_contents($theme_dir . "/index.tpl", $index_template); // add delete method $delete_method = new Zend_CodeGenerator_Php_Method(); $delete_method_body = file_get_contents($basepath . "/modules/bolts/extras/crudify_templates/deleteAction.txt"); $delete_action_replacements = array("TABLE_OBJECT_VAR" => $table_object_var, "TABLE_CLASSNAME" => $object_name, "ROW_OBJECT_VAR" => $row_object_var, "THE_ID" => $identity_col, "OBJECT_NICENAME" => $name, "ROWSET_VAR" => strtolower($name), "DELETE_URL" => $delete_url, "INDEX_URL" => $index_url); $delete_method_body = Bolts_Common::replaceWithArray($delete_method_body, $delete_action_replacements); $delete_method->setName('deleteAction')->setBody($delete_method_body); $controller_class->setMethod($delete_method); // load delete template $delete_template = file_get_contents($basepath . "/modules/bolts/extras/crudify_templates/delete.tpl"); if ($is_admin) { $delete_template_replacements = array("OBJECT_NICENAME" => $name, "THEME_GLOBAL_PATH_VAR_NAME" => "admin_theme_global_path", "CREATE_NEW_URL" => "/" . $module_name . "/" . strtolower($name) . "admin/edit", "ROWSET_VAR" => strtolower($name), "THE_ID" => $identity_col, "DELETE_URL" => $delete_url, "INDEX_URL" => $index_url); } else { $delete_template_replacements = array("OBJECT_NICENAME" => $name, "THEME_GLOBAL_PATH_VAR_NAME" => "theme_global_path", "CREATE_NEW_URL" => "/" . $module_name . "/" . strtolower($name) . "/edit", "ROWSET_VAR" => strtolower($name), "THE_ID" => $identity_col, "DELETE_URL" => $delete_url, "INDEX_URL" => $index_url); } $delete_template = Bolts_Common::replaceWithArray($delete_template, $delete_template_replacements); file_put_contents($theme_dir . "/delete.tpl", $delete_template); $controller_file = new Zend_CodeGenerator_Php_File(); $controller_file->setClass($controller_class); } // Render the generated files file_put_contents($basepath . "/modules/" . $module_name . "/models/" . $object_name . ".php", $model_file->generate()); if ($is_admin) { file_put_contents($basepath . "/modules/" . $module_name . "/controllers/" . $name . "adminController.php", $controller_file->generate()); } else { file_put_contents($basepath . "/modules/" . $module_name . "/controllers/" . $name . "Controller.php", $controller_file->generate()); }
function indexAction() { $request = new Bolts_Request($this->getRequest()); $basepath = Zend_Registry::get('basepath'); $this->view->timezones = Bolts_Common::getTimeZonesArray(); if ($this->getRequest()->isPost()) { $errors = array(); /* * TODO: Check that smarty dirs are writeable, etc. dir is writable, etc. dir is NOT writeable after install, libraries exist, * log level is set to something */ if (!file_exists($basepath . "/.htaccess")) { $errors[] = $this->_T("Missing .htaccess file in %s. Maybe use %s/template.htaccess ?", array($basepath, $basepath)); } $etc_dir = $basepath . "/etc"; $config_filename = $etc_dir . "/config.ini"; $tmp_path = $basepath . "/tmp"; $smarty_compile_dir = $tmp_path . "/view_compiles"; $smarty_cache_dir = $tmp_path . "/cache"; $image_cache_dir = $tmp_path . "/image_cache"; $upload_path = $basepath . "/uploads"; $log_path = $basepath . "/logs"; $module_cfg = parse_ini_file($basepath . "/modules/bolts/module.ini", true); $dir_array = array($etc_dir, $tmp_path, $upload_path, $log_path); foreach ($dir_array as $dir) { if (!is_writable($dir)) { $errors[] = $this->_T("Web server can't write to %s.", $dir); } } if ($request->admin_username == null) { $errors[] = $this->_T("Admin username cannot be blank."); } if ($request->admin_email == null) { $errors[] = $this->_T("Admin email cannot be blank."); } if ($request->app_name == null) { $errors[] = $this->_T("Application name cannot be blank."); } $cfg_array = array("database" => array("adapter" => "PDO_MYSQL", "params" => array("host" => $request->db_host, "dbname" => $request->db_name, "username" => $request->db_user, "password" => $request->db_pass, "port" => $request->db_port))); if (!is_null($request->db_sock)) { $cfg_array['database']['params']['unix_socket'] = $request->db_sock; // this is often something like /var/run/mysqld/mysqld.sock } $dbconfig = new Zend_Config($cfg_array); $db = Zend_Db::factory($dbconfig->database); try { if (count($errors) == 0) { $tables = $db->listTables(); if (count($tables) > 0) { $errors[] = $this->_T("The specified database is not empty."); } // get the table creation script $ddl_file = $basepath . "/core/bolts/sql/" . $dbconfig->database->adapter . "/install.sql"; if (file_exists($ddl_file)) { $queries = explode(";", file_get_contents($ddl_file)); $db->beginTransaction(); try { foreach ($queries as $query) { if (trim($query) != "") { $query = str_replace("@@@@ADMIN_USERNAME@@@@", $request->admin_username, $query); $query = str_replace("@@@@ADMIN_EMAIL@@@@", $request->admin_email, $query); $query = str_replace("@@@@CREATED_ON@@@@@", date("Y-m-d H:i:s"), $query); $db->query($query); } } $db->commit(); } catch (Exception $e) { $db->rollBack(); $errors[] = $e->getMessage(); } } else { $errors[] = $this->_T("Database creation script not found."); } } } catch (Exception $e) { $errors[] = $e->getMessage(); } if (count($errors) == 0) { // everything worked out okay, attempt to write the config file $config = array("db.communitas.adapter" => "PDO_MYSQL", "db.communitas.config.host" => $request->db_host, "db.communitas.config.dbname" => $request->db_name, "db.communitas.config.username" => $request->db_user, "db.communitas.config.password" => $request->db_pass, "db.communitas.config.port" => $request->db_port, "db.communitas.config.default" => "true"); if (!is_null($request->db_sock)) { $config['db.communitas.config.unix_socket'] = $request->db_sock; } $config_file .= Bolts_ConfigFile::makeSection("databases", "Database Settings", "This is the default database.", $config); $Bolts_config = array("timezone" => $request->Bolts_timezone, "launched" => "1", "prelaunch_url" => "http://google.com", "allowed_ips" => "127.0.0.1", "zf_path" => $basepath . "/lib/ZendFramework/library", "smarty_path" => $basepath . "/lib/Smarty/libs", "asido_path" => $basepath . "/lib/Asido", "image_cache_dir" => $image_cache_dir, "log_filename" => $log_path . "/bolts.log", "log_level" => "6", "addtl_includes" => ""); $config_file .= Bolts_ConfigFile::makeSection("application", "Application Settings", "These are the application specific settings.", $Bolts_config); // create directories if needed if (!file_exists($smarty_compile_dir)) { mkdir($smarty_compile_dir, 0777, true); } if (!file_exists($smarty_cache_dir)) { mkdir($smarty_cache_dir, 0777, true); } if (!file_exists($image_cache_dir)) { mkdir($image_cache_dir, 0777, true); } $smarty_config = array("config.compile_dir" => $smarty_compile_dir, "config.cache_dir" => $smarty_cache_dir); $config_file .= Bolts_ConfigFile::makeSection("smarty", "Smarty Settings", "These are the settings for the Smarty template engine.", $smarty_config); if (file_put_contents($config_filename, $config_file) === false) { $this->view->config_file = $config_file; $this->view->config_filename = $config_filename; $this->view->success = "Database installed, but could not write config file. Please create the file \"" . $config_filename . "\" and paste this following into it:"; } else { $this->_redirect("/bolts/install/secondstage/username/" . $request->admin_username . "/appname/" . $request->app_name); } } else { $this->view->errors = $errors; $this->view->db_host = $request->db_host; $this->view->db_name = $request->db_name; $this->view->db_user = $request->db_user; $this->view->db_pass = $request->db_pass; $this->view->db_port = $request->db_port; $this->view->db_sock = $request->db_sock; $this->view->app_name = $request->app_name; $this->view->admin_username = $request->admin_username; $this->view->admin_email = $request->admin_email; $this->view->Bolts_timezone = $request->Bolts_timezone; } } else { $this->view->db_host = "localhost"; $this->view->db_name = "bolts"; $this->view->db_user = "******"; $this->view->db_pass = ""; $this->view->db_port = "3306"; $this->view->db_sock = ""; $this->view->app_name = "My Application"; $this->view->admin_username = "******"; $this->view->Bolts_timezone = "America/Los_Angeles"; } }
function editAction() { $errors = array(); $users_table = new Users(); $users_roles_table = new UsersRoles(); $request = new Bolts_Request($this->getRequest()); $countries_table = new Countries(); $this->view->countries = $countries_table->getCountriesArray('Choose a country...'); $roles_table = new Roles(); $roles = $roles_table->fetchAll(NULL, "shortname ASC"); $arRoles = array(); foreach ($roles as $role) { if (!strpos($role->shortname, "-base")) { $arRoles[$role->id] = $role->description; } } $this->view->roles = $arRoles; $is_new = true; $user = array(); if ($request->has('username')) { $obUser = $users_table->fetchByUsername($request->username); if (!is_null($obUser)) { $is_new = false; $user_roles = $users_roles_table->fetchAll($users_roles_table->select()->where("username = ?", $obUser->username)); if (count($user_roles) > 0) { $tmp_selected = array(); foreach ($user_roles as $user_role) { $tmp_selected[] = $user_role->role_id; } $this->view->selected_roles = $tmp_selected; } $user = $obUser->toArray(); } } $this->view->is_new = $is_new; if ($is_new) { // defaults for form fields $user['username'] = ""; $user['full_name'] = ""; $user['aboutme'] = ""; } $pre_render = $this->_Bolts_plugin->doFilter($this->_mca . "_pre_render", array('user' => $user, 'request' => $this->_request)); // FILTER HOOK $user = $pre_render['user']; foreach ($pre_render as $key => $value) { if ($key != "user") { $this->view->{$key} = $value; } } // $tags = unserialize($user['tags']); if ($this->getRequest()->isPost()) { $errors = array(); $request->stripTags(array('full_name', 'email', 'newpassword', 'confirm')); // $request->stripTags(array('full_name', 'email', 'newpassword', 'confirm', 'aboutme')); $user['username'] = $request->username; $user['email'] = $request->email; $user['password'] = $request->newpassword; $user['confirm'] = $request->confirm; $user['full_name'] = $request->full_name; $user['birthday'] = $birthday = strtotime($request->Birthday_Day . $request->Birthday_Month . $request->Birthday_Year); $user['gender'] = $request->gender; $user['country_code'] = $request->country_code; $user['aboutme'] = $request->aboutme; // validate username $username_validator = new Zend_Validate(); $username_validator->addValidator(new Zend_Validate_StringLength(1, Bolts_Registry::get('username_length'))); $username_validator->addValidator(new Zend_Validate_Alnum()); if (!$username_validator->isValid($user['username'])) { $show_username = "******" . $user['username'] . "'"; if (trim($user['username']) == "") { $show_username = "******" . $this->_T("empty") . "]"; } $errors[] = $this->_T("%s isn't a valid username. (Between %d and %d characters, only letters and numbers)", array($show_username, 1, Bolts_Registry::get('username_length'))); } if ($is_new) { $user_where = $users_table->getAdapter()->quoteInto('username = ?', $user['username']); if ($users_table->getCountByWhereClause($user_where) > 0) { $errors[] = $this->_T("The username '%s' is already in use", $user['username']); } } // validate email if (!Bolts_Validate::checkEmail($user['email'])) { $errors[] = $this->_T("Email is not valid"); } // check to see if email is in use already by someone else if ($users_table->isEmailInUse($user['email'], $user['username'])) { $errors[] = $this->_T("Email already in use"); } // if password isn't blank, validate it if ($user['password'] != "") { if (!Bolts_Validate::checkLength($user['password'], 6, Bolts_Registry::get('password_length'))) { $errors[] = $this->_T("Password must be between 6 and 32 characters"); } // if password is set, make sure it matches confirm if ($user['password'] != $user['confirm']) { $errors[] = $this->_T("Passwords don't match"); } } // convert birthday_ts to mysql date $birthday = date("Y-m-d H:i:s", $user['birthday']); $params = array('request' => $request, 'user' => $user, 'errors' => $errors); // upload new avatar image if present if (array_key_exists('filedata', $_FILES)) { if ($_FILES['filedata']['tmp_name'] != '') { $destination_path = Bolts_Registry::get('upload_path') . "/" . $user['username'] . "/original"; if (!is_dir($destination_path)) { mkdir($destination_path, 0777, true); Bolts_Log::report("Creating user folder at " . $destination_path, null, Zend_Log::DEBUG); } if (file_exists($destination_path . "/avatar")) { unlink($destination_path . "/avatar"); Bolts_Log::report("Deleted existing user avatar from " . $destination_path, null, Zend_Log::DEBUG); } else { Bolts_Log::report("User avatar did not exist in " . $destination_path, null, Zend_Log::DEBUG); } move_uploaded_file($_FILES['filedata']['tmp_name'], $destination_path . "/avatar"); Users::clearUserCache($user['username']); Bolts_Log::report("User avatar uploaded to " . $destination_path, null, Zend_Log::DEBUG); $params['user']['hasnewfile'] = true; } else { $params['user']['hasnewfile'] = false; } } $additional = $this->_Bolts_plugin->doFilter($this->_mca . "_pre_save", $params); // FILTER HOOK $errors = $additional['errors']; $user = $additional['user']; $users_roles_table->delete($users_roles_table->getAdapter()->quoteInto("username = ?", $user['username'])); foreach ($request->role_ids as $role_id) { $role_data = array("username" => $user['username'], "role_id" => $role_id); $users_roles_table->insert($role_data); } if (count($errors) == 0) { /********** Commented out due to Plug-in compatibility issues. $data = array( 'email' => $user['email'], 'birthday' => $birthday, 'aboutme' => nl2br($user['aboutme']), 'gender' => $user['gender'], 'full_name' => $user['full_name'], 'country_code' => $user['country_code'], 'last_modified_on' => date(DB_DATETIME_FORMAT), ); **********/ $user['birthday'] = $birthday; $user['aboutme'] = nl2br($user['aboutme']); $user['last_modified_on'] = date(DB_DATETIME_FORMAT); // This is a hold-over value from the form. unset($user['confirm']); if ($user['password'] != "") { #$data['password'] = $user['password']; } else { unset($user['password']); } if ($is_new) { // TODO - stuff? really? $stuff = array('request' => $request, 'user' => $user, 'errors' => $errors); $additional1 = $this->_Bolts_plugin->doFilter($this->_mca, $stuff); // FILTER HOOK $errors = $additional1['errors']; $user = $additional1['user']; $data['username'] = $user['username']; #$data['created_on'] = date(DB_DATETIME_FORMAT); $user['created_on'] = date(DB_DATETIME_FORMAT); $users_table->insert($user); $this->view->success = "Profile created."; } else { $where = $users_table->getAdapter()->quoteInto('username = ?', $user['username']); #$users_table->update($data, $where); $users_table->update($user, $where); $this->view->success = "Profile updated."; } } else { $this->view->errors = $errors; } } $this->view->end_year = -Bolts_Registry::get('minimum_registration_age'); $this->view->genders = Bolts_Common::getGenderArray(); $user['aboutme'] = Bolts_Common::br2nl($user['aboutme']); $this->view->user = $user; }
function editAction() { if ($this->_user->username != $this->_identity->username) { $this->_forward('default', 'auth', 'missing'); return; } else { $countries_table = new Countries(); $this->view->countries = $countries_table->getCountriesArray('Choose a country...'); $user = $this->_user->toArray(); $params = array('user' => $user, 'request' => $this->_request, 'session' => $this->session); $pre_render = $this->_Bolts_plugin->doFilter($this->_mca . "_pre_render", $params); // FILTER HOOK $user = $pre_render['user']; foreach ($pre_render as $key => $value) { if ($key != "user") { $this->view->{$key} = $value; } } //$tags = unserialize($user->tags); if ($this->getRequest()->isPost()) { $errors = array(); $request = new Bolts_Request($this->getRequest()); $request->stripTags(array('email', 'newpassword', 'confirm', 'aboutme')); $user['username'] = $this->_identity->username; $user['email'] = $request->email; $user['full_name'] = $request->full_name; $user['password'] = $request->newpassword; $user['confirm'] = $request->confirm; $user['birthday'] = $birthday = strtotime($request->Birthday_Day . $request->Birthday_Month . $request->Birthday_Year); //$user['tags'] = $tag_array = Bolts_Common::makeTagArray($request->tags); $user['gender'] = $request->gender; $user['country_code'] = $request->country_code; $user['aboutme'] = $request->aboutme; // validate email if (!Bolts_Validate::checkEmail($user['email'])) { $errors[] = $this->_T("Email is not valid"); } // check to see if email is in use already by someone else if ($this->_users_table->isEmailInUse($user['email'], $user['username'])) { $errors[] = $this->_T("Email already in use"); } // if password isn't blank, validate it if ($user['password'] != "") { if (!Bolts_Validate::checkLength($user['password'], 6, Bolts_Registry::get('password_length'))) { $errors[] = $this->_T("Password must be between %d and %d characters", array(6, Bolts_Registry::get('password_length'))); } // if password is set, make sure it matches confirm if ($user['password'] != $user['confirm']) { $errors[] = $this->_T("Passwords don't match"); } } if (!Bolts_Validate::checkLength($user['aboutme'], 0, Bolts_Registry::get('user_about_me_length'))) { $errors[] = $this->_T("About me must be less than %d characters.", Bolts_Registry::get('user_about_me_length')); } // convert birthday_ts to mysql date $birthday = date("Y-m-d H:i:s", $user['birthday']); $params = array('request' => $this->getRequest(), 'user' => $user, 'errors' => $errors); // upload new avatar image if present if (array_key_exists('filedata', $_FILES)) { if ($_FILES['filedata']['tmp_name'] != '') { $users_table = new Users(); $destination_path = $users_table->getAvatarPath($user['username']); $destination_filename = $users_table->getAvatarPath($user['username'], true); if (!is_dir($destination_path)) { mkdir($destination_path, 0777, true); Bolts_Log::report("Creating user folder at " . $destination_path, null, Zend_Log::DEBUG); } if (file_exists($destination_filename)) { unlink($destination_filename); Bolts_Log::report("Deleted existing user avatar from " . $destination_path, null, Zend_Log::DEBUG); } else { Bolts_Log::report("User avatar did not exist in " . $destination_path, null, Zend_Log::DEBUG); } move_uploaded_file($_FILES['filedata']['tmp_name'], $destination_filename); Users::clearUserCache($user['username']); Bolts_Log::report("User avatar uploaded to " . $destination_path, null, Zend_Log::DEBUG); $params['user']['hasnewfile'] = true; } else { $params['user']['hasnewfile'] = false; } } $additional = $this->_Bolts_plugin->doFilter($this->_mca . "_pre_save", $params); // FILTER HOOK $errors = $additional['errors']; $user = $additional['user']; if (strlen($user['full_name']) < 1) { $user['full_name'] = $this->_T("Unidentified User"); } if (count($errors) == 0) { $data = array('email' => $user['email'], 'full_name' => $user['full_name'], 'birthday' => $birthday, 'aboutme' => nl2br($user['aboutme']), 'gender' => $user['gender'], 'country_code' => $user['country_code'], 'last_modified_on' => date(DB_DATETIME_FORMAT)); if ($user['password'] != "") { $data['password'] = $user['password']; } $where = $this->_users_table->getAdapter()->quoteInto('username = ?', $this->_username); $this->_users_table->update($data, $where); $this->_Bolts_plugin->doAction('default_user_edit_post_save', array('username' => $this->_username)); // ACTION HOOK $this->view->success = $this->_T("Profile Updated."); } else { $this->view->errors = $errors; } } //$this->view->tags = Bolts_Common::makeTagString($tags); $this->view->end_year = -Bolts_Registry::get('minimum_registration_age'); // multiply min age by number of seconds in a year $this->view->genders = Bolts_Common::getGenderArray(); $user['aboutme'] = Bolts_Common::br2nl(stripslashes($user['aboutme'])); $this->view->user = $user; } }