protected function get_input() { // get these from old setting $this->install_model->db_table_prefix = cms_table_prefix(); $this->install_model->is_subsite = TRUE; $this->install_model->subsite = $this->input->post('subsite'); $this->install_model->subsite_aliases = (string) $this->input->post('aliases'); $this->install_model->set_subsite(); $this->install_model->hide_index = TRUE; $this->install_model->gzip_compression = FALSE; }
protected function get_input() { // get these from old setting $this->install_model->db_table_prefix = cms_table_prefix(); $this->install_model->is_subsite = TRUE; $this->install_model->subsite = $this->input->post('subsite'); $this->install_model->subsite_aliases = (string) $this->input->post('aliases'); $this->install_model->set_subsite(); $this->install_model->admin_email = (string) $this->input->post('admin_email'); $this->install_model->admin_real_name = (string) $this->input->post('admin_real_name'); $this->install_model->admin_user_name = (string) $this->input->post('admin_user_name'); $this->install_model->admin_password = (string) $this->input->post('admin_password'); $this->install_model->admin_confirm_password = (string) $this->input->post('admin_confirm_password'); $this->install_model->hide_index = TRUE; $this->install_model->gzip_compression = FALSE; $this->install_model->auth_enable_facebook = $this->input->post('auth_enable_facebook') == 'true'; $this->install_model->auth_facebook_app_id = (string) $this->input->post('auth_facebook_app_id'); $this->install_model->auth_facebook_app_secret = $this->input->post('auth_facebook_app_secret'); $this->install_model->auth_enable_twitter = $this->input->post('auth_enable_twitter') == 'true'; $this->install_model->auth_twitter_app_key = (string) $this->input->post('auth_twitter_app_key'); $this->install_model->auth_twitter_app_secret = (string) $this->input->post('auth_twitter_app_secret'); $this->install_model->auth_enable_google = $this->input->post('auth_enable_google') == 'true'; $this->install_model->auth_google_app_id = (string) $this->input->post('auth_google_app_id'); $this->install_model->auth_google_app_secret = $this->input->post('auth_google_app_secret'); $this->install_model->auth_enable_yahoo = $this->input->post('auth_enable_yahoo') == 'true'; $this->install_model->auth_yahoo_app_id = (string) $this->input->post('auth_yahoo_app_id'); $this->install_model->auth_yahoo_app_secret = (string) $this->input->post('auth_yahoo_app_secret'); $this->install_model->auth_enable_linkedin = $this->input->post('auth_enable_linkedin') == 'true'; $this->install_model->auth_linkedin_app_key = (string) $this->input->post('auth_linkedin_app_key'); $this->install_model->auth_linkedin_app_secret = $this->input->post('auth_linkedin_app_secret'); $this->install_model->auth_enable_myspace = $this->input->post('auth_enable_myspace') == 'true'; $this->install_model->auth_myspace_app_key = (string) $this->input->post('auth_myspace_app_key'); $this->install_model->auth_myspace_app_secret = (string) $this->input->post('auth_myspace_app_secret'); $this->install_model->auth_enable_foursquare = $this->input->post('auth_enable_foursquare') == 'true'; $this->install_model->auth_foursquare_app_id = (string) $this->input->post('auth_foursquare_app_id'); $this->install_model->auth_foursquare_app_secret = (string) $this->input->post('auth_foursquare_app_secret'); $this->install_model->auth_enable_windows_live = $this->input->post('auth_enable_windows_live') == 'true'; $this->install_model->auth_windows_live_app_id = (string) $this->input->post('auth_windows_live_app_id'); $this->install_model->auth_windows_live_app_secret = (string) $this->input->post('auth_windows_live_app_secret'); $this->install_model->auth_enable_open_id = $this->input->post('auth_enable_open_id') == 'true'; $this->install_model->auth_enable_aol = $this->input->post('auth_enable_aol') == 'true'; }
/** * @author goFrendiAsgard * @param string user_name * @param string email * @param string real_name * @param string password * @param string config * @desc register new user */ public function cms_do_register($user_name, $email, $real_name, $password, $subsite_config = array()) { // check if activation needed $activation = $this->cms_get_config('cms_signup_activation'); $data = array("user_name" => $user_name, "email" => $email, "real_name" => $real_name, "password" => md5($password), "active" => $activation == 'automatic'); $this->db->insert(cms_table_name('main_user'), $data); // send activation code if needed if ($activation == 'by_mail') { $this->cms_generate_activation_code($user_name, TRUE, 'SIGNUP'); } if ($this->cms_is_module_active('gofrendi.noCMS.multisite') && $this->cms_get_config('cms_add_subsite_on_register') == 'TRUE') { $current_user_id = $this->db->select('user_id')->from(cms_table_name('main_user'))->where('user_name', $user_name)->get()->row()->user_id; $module_path = $this->cms_module_path('gofrendi.noCMS.multisite'); $this->load->model('installer/install_model'); $this->load->model($module_path . '/subsite_model'); $install_model = new Install_Model(); $subsite_model = new Subsite_Model(); // get these from old setting $this->install_model->db_table_prefix = cms_table_prefix(); $this->install_model->is_subsite = TRUE; $this->install_model->subsite = strtolower(str_replace(' ', '', $user_name)); $this->install_model->subsite_aliases = ''; $this->install_model->set_subsite(); $this->install_model->admin_email = $email; $this->install_model->admin_real_name = $real_name; $this->install_model->admin_user_name = $user_name; $this->install_model->admin_password = $password; $this->install_model->admin_confirm_password = $password; $this->install_model->hide_index = TRUE; $this->install_model->gzip_compression = FALSE; // get these from configuration $configs = $this->cms_get_config('cms_subsite_configs'); $configs = @json_decode($configs, TRUE); if (!$configs) { $configs = array(); } foreach ($subsite_config as $key => $value) { $configs[$key] = $value; } $modules = $this->cms_get_config('cms_subsite_modules'); $modules = explode(',', $modules); $new_modules = array(); foreach ($modules as $module) { $module = trim($module); if (!in_array($module, $new_modules)) { $new_modules[] = $module; } } $modules = $new_modules; $this->install_model->configs = $configs; $this->install_model->modules = $modules; // check installation $check_installation = $this->install_model->check_installation(); $success = $check_installation['success']; $module_installed = FALSE; if ($success) { $config = array('subsite_home_content' => $this->cms_get_config('cms_subsite_home_content', TRUE)); $this->install_model->build_database($config); $this->install_model->build_configuration($config); $module_installed = $this->install_model->install_modules(); } if (!isset($_SESSION)) { session_start(); } // hack module path by changing the session, don't forget to unset !!! $this->cms_override_module_path($module_path); $data = array('name' => $this->install_model->subsite, 'description' => $user_name . ' website', 'use_subdomain' => $this->cms_get_config('cms_subsite_use_subdomain') == 'TRUE' ? 1 : 0, 'user_id' => $current_user_id, 'active' => $activation == 'automatic'); $this->db->insert($this->cms_complete_table_name('subsite'), $data); $this->load->model($this->cms_module_path() . '/subsite_model'); $this->subsite_model->update_configs(); $this->cms_reset_overriden_module_path(); if (!$module_installed) { // hack script, will be added and removed in next view $install_module_script = '<script type="text/javascript"> $(document).ready(function(){ var modules = ["blog", "static_accessories", "contact_us"]; var done = 0; for(var i=0; i<modules.length; i++){ var module = modules[i]; $.ajax({ "url": "{{ SITE_URL }}/"+module+"/install/activate/?__cms_subsite=' . $this->install_model->subsite . '", "type": "POST", "dataType": "json", "async": true, "data":{ "silent" : true, "identity": "' . $user_name . '", "password": "******" }, "success": function(response){ if(!response["success"]){ console.log("error installing "+response["module_path"]); } }, }); } });</script>'; $this->cms_flash_metadata($install_module_script); } } }
function cms_table_name($table_name, $table_prefix = NULL) { if ($table_prefix === NULL) { $table_prefix = cms_table_prefix(); } if ($table_prefix != '') { return $table_prefix . '_' . $table_name; } else { return $table_name; } }
/** * @author goFrendiAsgard * @param string user_name * @param string email * @param string real_name * @param string password * @param string config * @desc register new user */ public function cms_do_register($user_name, $email, $real_name, $password, $subsite_config = array()) { // check if activation needed $activation = $this->cms_get_config('cms_signup_activation'); $data = array("user_name" => $user_name, "email" => $email, "real_name" => $real_name, "password" => cms_md5($password), "active" => $activation == 'automatic'); $this->db->insert(cms_table_name('main_user'), $data); // send activation code if needed if ($activation == 'by_mail') { $this->cms_generate_activation_code($user_name, TRUE, 'SIGNUP'); } if ($this->cms_is_module_active('gofrendi.noCMS.multisite') && $this->cms_get_config('cms_add_subsite_on_register') == 'TRUE') { $current_user_id = $this->db->select('user_id')->from(cms_table_name('main_user'))->where('user_name', $user_name)->get()->row()->user_id; $module_path = $this->cms_module_path('gofrendi.noCMS.multisite'); $this->load->model('installer/install_model'); $this->load->model($module_path . '/subsite_model'); // get these from old setting $this->install_model->db_table_prefix = cms_table_prefix(); $this->install_model->is_subsite = TRUE; $this->install_model->subsite = $user_name; $this->install_model->subsite_aliases = ''; $this->install_model->set_subsite(); $this->install_model->admin_email = $email; $this->install_model->admin_real_name = $real_name; $this->install_model->admin_user_name = $user_name; $this->install_model->admin_password = $password; $this->install_model->admin_confirm_password = $password; $this->install_model->hide_index = TRUE; $this->install_model->gzip_compression = FALSE; // get these from configuration $configs = $this->cms_get_config('cms_subsite_configs'); $configs = @json_decode($configs, TRUE); if (!$configs) { $configs = array(); } foreach ($subsite_config as $key => $value) { $configs[$key] = $value; } $modules = $this->cms_get_config('cms_subsite_modules'); $modules = explode(',', $modules); $new_modules = array(); foreach ($modules as $module) { $module = trim($module); if (!in_array($module, $new_modules)) { $new_modules[] = $module; } } $modules = $new_modules; $this->install_model->configs = $configs; $this->install_model->modules = $modules; // check installation $check_installation = $this->install_model->check_installation(); $success = $check_installation['success']; $module_installed = FALSE; if ($success) { $config = array('subsite_home_content' => $this->cms_get_config('cms_subsite_home_content', TRUE)); $this->install_model->build_configuration($config); $this->install_model->build_database($config); $module_installed = $this->install_model->install_modules(); } // TODO: Find a way to bash this dirty trick // This one is necessary to re-index modules $this->cms_adjust_module(); $data = array('name' => $this->install_model->subsite, 'description' => $user_name . ' website', 'use_subdomain' => $this->cms_get_config('cms_subsite_use_subdomain') == 'TRUE' ? 1 : 0, 'user_id' => $current_user_id, 'active' => $activation == 'automatic'); $this->db->insert($this->cms_complete_table_name('subsite', 'gofrendi.noCMS.multisite'), $data); $this->load->model($this->cms_module_path('gofrendi.noCMS.multisite') . '/subsite_model'); $this->subsite_model->update_configs(); // get the new subsite $t_user = cms_table_name('main_user'); $t_subsite = $this->cms_complete_table_name('subsite', 'gofrendi.noCMS.multisite'); $query = $this->db->select('name,use_subdomain')->from($t_subsite)->join($t_user, $t_user . '.user_id=' . $t_subsite . '.user_id')->where('user_name', $user_name)->order_by($t_subsite . '.id', 'desc')->get(); if ($query->num_rows() > 0) { $row = $query->row(); $subsite = $row->name; // get directory $site_url = site_url(); $site_url = substr($site_url, 0, strlen($site_url) - 1); $site_url_part = explode('/', $site_url); if (count($site_url_part) > 3) { $directory_part = array_slice($site_url_part, 3); log_message('error', print_r(array($directory_part, $site_url_part), TRUE)); $directory = '/' . implode('/', $directory_part); } else { $directory = ''; } $protocol = stripos($_SERVER['SERVER_PROTOCOL'], 'https') === true ? 'https://' : 'http://'; $ssl = $protocol == 'https://'; $port = $_SERVER['SERVER_PORT']; $port = !$ssl && $port == '80' || $ssl && $port == '443' ? '' : ':' . $port; if ($row->use_subdomain) { $url = $protocol . $subsite . '.' . $_SERVER['SERVER_NAME'] . $port . $directory; } else { $url = $protocol . $_SERVER['SERVER_NAME'] . $port . $directory . '/site-' . $subsite; } $this->cms_do_login($user_name, $password); redirect($url, 'refresh'); } } else { if ($activation == 'automatic') { $this->cms_do_login($user_name, $password); } } }
public function register(){ $this->cms_guard_page('main_register'); // the honey_pot, every fake input should be empty $honey_pot_pass = (strlen($this->input->post('user_name', ''))==0) && (strlen($this->input->post('email', ''))==0) && (strlen($this->input->post('real_name', ''))==0) && (strlen($this->input->post('password', ''))==0) && (strlen($this->input->post('confirm_password'))==0); if(!$honey_pot_pass){ show_404(); die(); } $previous_secret_code = $this->session->userdata('__main_registration_secret_code'); if($previous_secret_code === NULL){ $previous_secret_code = $this->cms_random_string(); } $activation = $this->cms_get_config('cms_signup_activation'); $module_path = $this->cms_module_path('gofrendi.noCMS.multisite'); $subsite_table_name = $this->cms_complete_table_name('subsite', 'gofrendi.noCMS.multisite'); $this->load->model($module_path.'/subsite_model'); //get user input $user_name = $this->input->post($previous_secret_code.'user_name'); $email = $this->input->post($previous_secret_code.'email'); $real_name = $this->input->post($previous_secret_code.'real_name'); $password = $this->input->post($previous_secret_code.'password'); $confirm_password = $this->input->post($previous_secret_code.'confirm_password'); //set validation rule $this->form_validation->set_rules($previous_secret_code.'user_name', 'User Name', 'required'); $this->form_validation->set_rules($previous_secret_code.'email', 'E mail', 'required|valid_email'); $this->form_validation->set_rules($previous_secret_code.'real_name', 'Real Name', 'required'); $this->form_validation->set_rules($previous_secret_code.'password', 'Password', 'required|matches['.$previous_secret_code.'confirm_password]'); $this->form_validation->set_rules($previous_secret_code.'confirm_password', 'Password Confirmation', 'required'); // generate new secret code $secret_code = $this->cms_random_string(); $this->session->set_userdata('__main_registration_secret_code', $secret_code); if ($this->form_validation->run() && !$this->cms_is_user_exists($user_name) && !$this->cms_is_user_exists($email) && preg_match('/@.+\./', $email) && $user_name != '' && $email != '') { $configs = array(); if(CMS_SUBSITE == '' && $this->cms_is_module_active('gofrendi.noCMS.multisite') && $this->cms_get_config('cms_add_subsite_on_register') == 'TRUE'){ $configs['site_name'] = $this->input->post('site_title'); $configs['site_slogan'] = $this->input->post('site_slogan'); $this->load->library('image_moo'); if(isset($_FILES['site_logo'])){ $site_logo = $_FILES['site_logo']; if(isset($site_logo['tmp_name']) && $site_logo['tmp_name'] != '' && getimagesize($site_logo['tmp_name']) !== FALSE){ try{ $file_name = FCPATH.'assets/nocms/images/custom_logo/'.$user_name.$site_logo['name']; move_uploaded_file($site_logo['tmp_name'], $file_name); $this->cms_resize_image($file_name, 800, 125); $configs['site_logo'] = '{{ base_url }}assets/nocms/images/custom_logo/'.$user_name.$site_logo['name']; }catch(Exception $e){ // do nothing } } } if(isset($_FILES['site_favicon'])){ $site_favicon = $_FILES['site_favicon']; if(isset($site_favicon['tmp_name']) && $site_favicon['tmp_name'] != '' && getimagesize($site_favicon['tmp_name']) !== FALSE){ try{ $file_name = FCPATH.'assets/nocms/images/custom_favicon/'.$user_name.$site_favicon['name']; move_uploaded_file($site_favicon['tmp_name'], $file_name); $this->cms_resize_image($file_name, 64, 64); $configs['site_favicon'] = '{{ base_url }}assets/nocms/images/custom_favicon/'.$user_name.$site_favicon['name']; }catch(Exception $e){ // do nothing } } } } $this->cms_do_register($user_name, $email, $real_name, $password, $configs); // create subsite $current_user_id = $this->db->select('user_id') ->from($this->cms_user_table_name()) ->where('user_name', $user_name) ->get()->row()->user_id; $this->load->model('installer/install_model'); // get these from old setting $this->install_model->db_table_prefix = cms_table_prefix(); $this->install_model->is_subsite = TRUE; $this->install_model->subsite = $user_name; $this->install_model->subsite_aliases = ''; $this->install_model->set_subsite(); $this->install_model->hide_index = TRUE; $this->install_model->gzip_compression = FALSE; $this->load->model($this->cms_module_path().'/subsite_model'); $template = $this->subsite_model->get_single_template($this->input->post('template')); $homepage_layout = $this->input->post('homepage_layout'); $default_layout = $this->input->post('default_layout'); $theme = $this->input->post('theme'); // get template configs $template_configs = $template != NULL? $template->configuration: $this->cms_get_config('cms_subsite_configs'); $template_configs = @json_decode($configs, TRUE); if(!$template_configs){ $template_configs = array(); } foreach($template_configs as $key=>$val){ $configs[$key] = $val; } // add site theme and layout if($theme != ''){ $configs['site_theme'] = $theme; } if($default_layout != ''){ $configs['site_layout'] = $default_layout; } // get modules $modules = $template != NULL? $template->modules: $this->cms_get_config('cms_subsite_modules'); $modules = explode(',', $modules); $new_modules = array(); foreach($modules as $module){ $module = trim($module); if(!in_array($module, $new_modules)){ $new_modules[] = $module; } } $modules = $new_modules; $this->install_model->configs = $configs; $this->install_model->modules = $modules; // check installation $check_installation = $this->install_model->check_installation(); $success = $check_installation['success']; $module_installed = FALSE; if($success){ $config = array( 'subsite_home_content'=> $template != NULL? $template->homepage: $this->cms_get_config('cms_subsite_home_content', TRUE), 'subsite_homepage_layout' => $homepage_layout, 'subsite_user_id' => $current_user_id, ); $this->install_model->build_configuration($config); $this->install_model->build_database($config); $module_installed = $this->install_model->install_modules(); } // TODO: Find a way to bash this dirty trick // This one is necessary to re-index modules //$this->cms_adjust_module(); $data = array( 'name'=> $this->install_model->subsite, 'description'=>$user_name.' website', 'use_subdomain'=>$this->cms_get_config('cms_subsite_use_subdomain')=='TRUE'?1:0, 'user_id'=>$current_user_id, 'active'=>$activation == 'automatic' ); $this->db->insert($subsite_table_name, $data); $this->subsite_model->update_configs(); // get the new subsite $t_user = $this->cms_user_table_name(); $t_subsite = $subsite_table_name; $query = $this->db->select('name,use_subdomain') ->from($t_subsite) ->join($t_user, $t_user.'.user_id='.$t_subsite.'.user_id') ->where('user_name', $user_name) ->order_by($t_subsite.'.id', 'desc') ->get(); if($query->num_rows()>0){ $row = $query->row(); $subsite = $row->name; // get directory $site_url = site_url(); $site_url = substr($site_url, 0, strlen($site_url)-1); $site_url_part = explode('/', $site_url); if(count($site_url_part)>3){ $directory_part = array_slice($site_url_part, 3); $directory = '/'.implode('/', $directory_part); }else{ $directory = ''; } $protocol = stripos($_SERVER['SERVER_PROTOCOL'],'https') === true ? 'https://' : 'http://'; $ssl = $protocol == 'https://'; $port = $_SERVER['SERVER_PORT']; $port = ((!$ssl && $port=='80') || ($ssl && $port=='443')) ? '' : ':'.$port; if($row->use_subdomain){ $url = $protocol.$subsite.'.'.$_SERVER['SERVER_NAME'].$port.$directory; }else{ $url = $protocol.$_SERVER['SERVER_NAME'].$port.$directory.'/site-'.$subsite; } $this->cms_do_login($user_name, $password); redirect($url,'refresh'); } redirect('','refresh'); } else { $data = array( 'user_name' => $user_name, 'email' => $email, 'real_name' => $real_name, 'register_caption' => $this->cms_lang('Register'), 'secret_code' => $secret_code, 'multisite_active' => $this->cms_is_module_active('gofrendi.noCMS.multisite'), 'add_subsite_on_register' => $this->cms_get_config('cms_add_subsite_on_register') == 'TRUE', 'theme_list' => $this->subsite_model->public_theme_list(), 'layout_list' => $this->subsite_model->layout_list(), 'template_list' => $this->subsite_model->template_list(), ); $this->view('multisite/register', $data, 'main_register'); } }
function cms_table_name($table_name) { $table_prefix = cms_table_prefix(); if ($table_prefix != '') { return $table_prefix . '_' . $table_name; } else { return $table_name; } }