function execute(&$form, $action_id) { $config = $form->actions_config[$action_id]; $config = new \GCore\Libs\Parameter($config); $mainframe = \JFactory::getApplication(); //set data $user = \GCore\Libs\Base::getUser(); $article_data['created_by'] = $user['id']; $article_data['access'] = $config->get('access', 1); $article_data['created'] = date("Y-m-d H:i:s"); $article_data['catid'] = $config->get('catid', ''); $article_data['sectionid'] = $config->get('sectionid', 0); $article_data['state'] = $config->get('state', 0); $article_data['title'] = $form->data($config->get('title', '')); $article_data['fulltext'] = $form->data($config->get('fulltext', '')); $article_data['introtext'] = strlen($form->data($config->get('introtext', ''))) ? $form->data($config->get('introtext', '')) : ''; //$article_data['created_by_alias'] = $form->data[$config->get('created_by_alias', '')]; $article_data['language'] = '*'; //alias $article_data['alias'] = \JFilterOutput::stringURLSafe($article_data['title']); //$article_data['id'] = null; \GCore\Libs\GModel::generateModel('CFJArticle', array('tablename' => '#__content')); \GCore\Models\CFJArticle::getInstance()->save($article_data); }
function _initialize() { //$this->area = 'front'; $session = \GCore\Libs\Base::getSession(); if ($this->get('ccname', null)) { $this->data['ccname'] = $this->get('ccname'); } if (!empty($this->data['ccname'])) { $this->connection = $connection = $this->Connection->find('first', array('conditions' => array('title' => $this->data['ccname'], 'published' => 1))); if (!empty($connection['Connection']['extras']['models']['name'][1]) and !empty($connection['Connection']['extras']['models']['tablename'][1])) { $dbo_config = array(); if (!empty($connection['Connection']['extras']['ndb']['enabled'])) { $dbo_config = array('type' => $connection['Connection']['extras']['ndb']['driver'], 'host' => $connection['Connection']['extras']['ndb']['host'], 'name' => $connection['Connection']['extras']['ndb']['database'], 'user' => $connection['Connection']['extras']['ndb']['user'], 'pass' => $connection['Connection']['extras']['ndb']['password'], 'prefix' => $connection['Connection']['extras']['ndb']['prefix']); } //primary model available \GCore\Libs\GModel::generateModel(trim($connection['Connection']['extras']['models']['name'][1]), array('tablename' => trim($connection['Connection']['extras']['models']['tablename'][1]), 'dbo_config' => $dbo_config)); $pmodel = '\\GCore\\Models\\' . $connection['Connection']['extras']['models']['name'][1]; $this->pmodel = $pmodel::getInstance(); $this->connection_models[$this->pmodel->alias] = $this->pmodel; //find secondary models if available foreach ($this->connection['Connection']['extras']['models']['name'] as $k => $name) { if ($k != 1) { $name = trim($this->connection['Connection']['extras']['models']['name'][$k]); $tablename = trim($this->connection['Connection']['extras']['models']['tablename'][$k]); $pkey = !empty($this->connection['Connection']['extras']['models']['pkey'][$k]) ? trim($this->connection['Connection']['extras']['models']['pkey'][$k]) : NULL; if (!empty($name) and !empty($tablename)) { \GCore\Libs\GModel::generateModel($name, array('tablename' => $tablename, 'pkey' => $pkey, 'dbo_config' => $dbo_config)); //setup relation to primary if exists $relation = $this->connection['Connection']['extras']['models']['relation'][$k]; if (!empty($relation)) { $relation_settings = array('className' => '\\GCore\\Models\\' . $name); if (!empty($this->connection['Connection']['extras']['models']['foreignKey'][$k])) { $relation_settings['foreignKey'] = trim($this->connection['Connection']['extras']['models']['foreignKey'][$k]); } if (!empty($this->connection['Connection']['extras']['models']['assoc_save'][$k])) { $relation_settings['save_on_save'] = true; } if (!empty($this->connection['Connection']['extras']['models']['assoc_delete'][$k])) { $relation_settings['delete_on_delete'] = true; } if (!empty($this->connection['Connection']['extras']['models']['conditions'][$k])) { $conditions = eval('?>' . $this->connection['Connection']['extras']['models']['conditions'][$k]); $relation_settings['conditions'] = is_array($conditions) ? $conditions : array(); } if (!empty($this->connection['Connection']['extras']['models']['join_conditions'][$k])) { $join_conditions = eval('?>' . $this->connection['Connection']['extras']['models']['join_conditions'][$k]); $relation_settings['join_conditions'] = is_array($join_conditions) ? $join_conditions : array(); } if (!empty($this->connection['Connection']['extras']['models']['join_type'][$k])) { $relation_settings['type'] = $this->connection['Connection']['extras']['models']['join_type'][$k]; } if (!empty($this->connection['Connection']['extras']['models']['fields'][$k])) { $relation_settings['fields'] = $this->_process_fields_list($this->connection['Connection']['extras']['models']['fields'][$k]); } if (!empty($this->connection['Connection']['extras']['models']['order'][$k])) { $relation_settings['order'] = $this->_process_fields_list($this->connection['Connection']['extras']['models']['order'][$k]); } if (!empty($this->connection['Connection']['extras']['models']['group'][$k])) { $relation_settings['group'] = $this->_process_fields_list($this->connection['Connection']['extras']['models']['group'][$k]); } if (empty($this->connection['Connection']['extras']['models']['associated_model'][$k])) { $this->pmodel->bindModels($relation, array($name => $relation_settings)); $this->connection_models[$name] = $this->pmodel->{$name}; } else { $associated_model = $this->connection['Connection']['extras']['models']['associated_model'][$k]; $associated_model_class = '\\GCore\\Models\\' . $this->connection['Connection']['extras']['models']['associated_model'][$k]; if ($associated_model == $this->pmodel->alias) { $this->pmodel->bindModels($relation, array($name => $relation_settings)); $this->connection_models[$name] = $this->pmodel->{$name}; } else { $check_model = $this->pmodel; check_again: if (in_array($associated_model, array_keys($check_model->associated_models))) { $check_model->{$associated_model}->bindModels($relation, array($name => $relation_settings)); $this->connection_models[$name] = $check_model->{$associated_model}->{$name}; } else { $sub_models = array_keys($check_model->associated_models); foreach ($sub_models as $sub_model) { $check_model = $sub_model; goto check_again; } } } } } } } } } else { $session->setFlash('error', l_('CONN_CONNECTION_NOT_FOUND')); return false; } } else { $session->setFlash('error', l_('CONN_NO_CONNECTION_NAME')); return false; } //check permissions if (!empty($this->connection['Connection']['extras'][$this->area]['permissions'][$this->action])) { $gcb = $this->Request->data('gcb', null); $owner_id = null; if ($this->connection['Connection']['extras'][$this->area]['permissions'][$this->action]['owner'] == 1) { if (!empty($gcb) and !empty($this->connection['Connection']['extras'][$this->area]['permissions_conf']['owner_id_column'])) { $user_id_column = $this->connection['Connection']['extras'][$this->area]['permissions_conf']['owner_id_column']; $records = $this->pmodel->find('all', array('recursive' => -1, 'fields' => array($this->pmodel->pkey, $user_id_column), 'conditions' => array($this->pmodel->pkey => $gcb))); if (strpos($user_id_column, '.') === false) { $user_id_column = $this->pmodel->alias . '.' . $user_id_column; } $owners = \GCore\Libs\Arr::getVal($records, explode('.', '[n].' . $user_id_column)); $owners = array_values(array_unique($owners)); if (count($owners) > 1) { goto check_all; } else { $owner_id = $owners[0]; } } } check_all: if (!\GCore\Libs\Authorize::check_rules($this->connection['Connection']['extras'][$this->area]['permissions'][$this->action], \GCore\Libs\Authenticate::get_user_groups(), $owner_id)) { $session->setFlash('error', l_('CONNECTIVITY_ACCESS_DENIED')); return false; } } //load plugins if (!empty($this->pmodel)) { if (!empty($this->connection['Connection']['extras'][$this->area]['display']['page_limit']) and is_numeric($this->connection['Connection']['extras'][$this->area]['display']['page_limit'])) { $this->pmodel->page_limit = (int) $this->connection['Connection']['extras'][$this->area]['display']['page_limit']; } //run plugins if (!empty($this->connection['Connection']['extras']['plugins'])) { //sort plugins execution $plugins_priority = array(); foreach ($this->connection['Connection']['extras']['plugins'] as $plg => $plg_data) { $plugins_priority[$plg] = \GCore\Libs\Arr::getVal($plg_data, array('priority'), 0); } array_multisort($plugins_priority, SORT_DESC, $this->connection['Connection']['extras']['plugins']); foreach ($this->connection['Connection']['extras']['plugins'] as $plugin => $plugin_data) { if (!empty($plugin_data['enabled'])) { $this->plugins[] = $plugin; if (class_exists('\\GCore\\Admin\\Extensions\\Chronoconnectivity\\Plugins\\' . \GCore\Libs\Str::camilize($plugin) . '\\' . \GCore\Libs\Str::camilize($plugin . '_helper'))) { $plugin_helper = '\\GCore\\Admin\\Extensions\\Chronoconnectivity\\Plugins\\' . \GCore\Libs\Str::camilize($plugin) . '\\' . \GCore\Libs\Str::camilize($plugin . '_helper'); $this->helpers[$plugin_helper]['connection'] = $this->connection; $this->helpers[$plugin_helper]['model'] = $this->pmodel; } } } } $this->helpers['\\GCore\\Admin\\Extensions\\Chronoconnectivity\\Helpers\\Plugin']['plugins'] = $this->plugins; $this->_process_plugins('on_initialize', $this); } }
function execute(&$form, $action_id) { $config = $form->actions_config[$action_id]; $config = new \GCore\Libs\Parameter($config); $this->config = $config; //set activation link if (trim($this->config->get('activation_link', '')) == '') { $this->config->set('activation_link', 'index.php?option=com_users&task=registration.activate'); } // Get required system objects $user = clone JFactory::getUser(); $mainframe = JFactory::getApplication(); //$config = JFactory::getConfig(); $authorize = JFactory::getACL(); $document = JFactory::getDocument(); $language = JFactory::getLanguage(); $language->load('com_users'); // If user registration is not allowed, show 403 not authorized. $usersConfig = JComponentHelper::getParams('com_users'); if ($usersConfig->get('allowUserRegistration') == '0' && !$config->get('override_allow_user_registration', 0)) { JError::raiseError(403, JText::_('Access Forbidden')); return; } // Initialize new usertype setting $userConfig = JComponentHelper::getParams('com_users'); // Default to Registered. $defaultUserGroup = $config->get('new_usertype', ''); if (empty($defaultUserGroup)) { $defaultUserGroup = $userConfig->get('new_usertype', array(2)); } else { $_groups = $defaultUserGroup; //explode(",", trim($defaultUserGroup)); $defaultUserGroup = array(); foreach ($_groups as $_group) { $defaultUserGroup[] = (int) $_group; } } //set the post fields values $form->data['name'] = $form->data($config->get('name', ''), ''); $form->data['username'] = $form->data($config->get('username', ''), ''); $form->data['email'] = $form->data($config->get('email', ''), ''); $form->data['password'] = $form->data($config->get('password', ''), ''); $form->data['password2'] = $form->data($config->get('password2', ''), ''); //generate the random pass if enabled if ((int) $config->get('random_password', 0) == 1) { jimport('joomla.user.helper'); $random_pass = JUserHelper::genRandomPassword(); $form->data['password'] = $random_pass; $form->data['password2'] = $random_pass; } //check empty fields $checks = array('name', 'username', 'email', 'password'); foreach ($checks as $check) { if (!trim($form->data[$check])) { $this->events['fail'] = 1; $form->errors[$config->get($check)] = 'You must provide your ' . $check . '.'; //return false; } } if ($this->events['fail'] == 1) { return false; } //check the 2 passwords if ($form->data['password'] != $form->data['password2']) { $this->events['fail'] = 1; $form->errors[$config->get('password2')] = 'Passwords do NOT match.'; $form->debug[] = "Couldn't create new user, Passwords do NOT match."; return false; } // Bind the post array to the user object $post_data = $form->data; if (!$user->bind($post_data, 'usertype')) { //JError::raiseError( 500, $user->getError()); $this->events['fail'] = 1; $form->errors[] = $user->getError(); $form->debug[] = "Couldn't bind new user, Joomla returned this error : " . $user->getError(); return false; } // Set some initial user values $user->set('id', 0); $user->set('usertype', 'deprecated'); $user->set('groups', $defaultUserGroup); $date = JFactory::getDate(); $user->set('registerDate', date('Y-m-d H:i:s', time())); // If user activation is turned on, we need to set the activation information $useractivation = $config->get('useractivation', $usersConfig->get('useractivation')); if ($useractivation == 1 || $useractivation == 2) { jimport('joomla.user.helper'); $user->set('activation', md5(JUserHelper::genRandomPassword())); $user->set('block', '1'); } // If there was an error with registration, set the message and display form if (!$user->save()) { /*JError::raiseWarning('', JText::_( $user->getError())); $this->register();*/ $this->events['fail'] = 1; $form->errors[] = $user->getError(); $form->debug[] = "Couldn't save new user, Joomla returned this error : " . $user->getError(); return false; } else { $this->events['success'] = 1; } //store user data $user_data = (array) $user; $removes = array('params', '_params', 'guest', '_errorMsg', '_errors'); foreach ($removes as $remove) { unset($user_data[$remove]); } $form->data['_PLUGINS_']['joomla_registration'] = $user_data; //inject user data under the correct data path if (strlen(trim($config->get('user_data_path', ''))) > 0) { $form->data = $form->set_array_value($form->data, explode('.', trim($config->get('user_data_path', ''))), $user_data); } //CB support if ((bool) $config->get('enable_cb_support', 0) === true) { /********************CB part*************************/ $database = JFactory::getDBO(); $database->setQuery("SELECT * FROM #__comprofiler_fields WHERE `table`='#__comprofiler' AND name <>'NA' AND registration = '1'"); $fields = $database->loadObjectList(); $default_fields_names = array('id', 'user_id'); $default_fields_values = array('id' => $user_data['id'], 'user_id' => $user_data['id']); foreach ($fields as $field) { $default_fields_names[] = $field->name; $fieldname = $field->name; $default_fields_values[$fieldname] = $form->data($fieldname, ''); } /*$database->setQuery( "INSERT INTO #__comprofiler (".implode(",", $default_fields_names).") VALUES ('".implode("','", $form->escapeVar($default_fields_values))."');" ); if (!$database->query()) { JError::raiseWarning(100, $database->getErrorMsg()); }*/ \GCore\Libs\GModel::generateModel('Profiler', array('tablename' => '#__comprofiler')); \GCore\Models\Profiler::getInstance()->save($default_fields_values); /**********************************************/ } // Send registration confirmation mail $password = $form->data['password']; //JRequest::getString('password', '', 'post', JREQUEST_ALLOWRAW); $password = preg_replace('/[\\x00-\\x1F\\x7F]/', '', $password); //Disallow control chars in the email if ((int) $config->get('send_joo_activation', 0) == 1) { $this->_sendMail($user, $password, $config); } // Everything went fine, set relevant message depending upon user activation state and display message if ((int) $useractivation == 2) { $message = JText::_('COM_USERS_REGISTRATION_COMPLETE_VERIFY'); } else { if ((int) $useractivation == 1) { $message = JText::_('COM_USERS_REGISTRATION_COMPLETE_ACTIVATE'); } else { $message = JText::_('COM_USERS_REGISTRATION_SAVE_SUCCESS'); } } if ($config->get('display_reg_complete', 0) == 1) { echo $message; } if ((int) $config->get('auto_login', 0) == 1) { $credentials = array(); $credentials['username'] = $form->data['username']; $credentials['password'] = $form->data['password']; $mainframe->login($credentials); } }