/** * Duplicate an area for another language (secret method) * If you need to add another language to an area you can call this script * /admin/pages/duplicate_area_lang/ID_AREA/OLD_LANG/NEW_LANG * * @param integer $id_area Area ID * @param string $old_lang Old language to copy * @param string $new_lang New language to set * @return string */ public function duplicate_area_lang($id_area, $old_lang, $new_lang) { // Comment the next row to enable the method die('Operation disabled!'); $mod = new Page_model(); // duplicate $res = $mod->duplicate_area_lang($id_area, $old_lang, $new_lang); if ($res[1]) { // refactory permissions $mod = new Permission_model(); $mod->refactory($_SESSION['xuid']); echo '<h1>CONGRATULATIONS!</h1>'; echo '<p>The changes on the database are applied.</p>'; // print instructions for manual changes echo '<p>Follow this instructions to perform manual changes.</p> <ul> <li>Install the following modules: ' . implode(', ', $res[0]) . ' and configure them if needed</li> </ul> <p>Done!</p> <p>NOTE: this operation acts on the pages and articles of the CMS, if you use plugins you have to check if you need to duplicate contents.</p>'; } else { echo '<h1>WARNING!</h1>'; echo '<p>Something went wrong, changes are not applied.</p>'; } die; }
/** * Perform login * * @access private * @param array $_post _POST array * @return void */ private function do_login($_post) { // check failure counter if ($_SESSION['failed'] < 5) { // fields to set in sessions $fields = array('mail' => 'mail', 'username' => 'username', 'id' => 'xuid', 'lang' => 'lang', 'last_in' => 'last_in', 'level' => 'level'); // conditions $conditions = array('id_area' => 1, 'username' => $_post['username']); // remember me $conditions['password'] = isset($_post['hpwd']) && $_post['password'] == '12345678' ? $_post['hpwd'] : X4Utils_helper::hashing($_post['password']); // log in $login = X4Auth_helper::log_in('users', $conditions, $fields, true, true); if ($login) { // post login operations $_SESSION['site'] = SITE; $_SESSION['id_area'] = 1; // admin AREA ID // set cookie for remember me if (isset($_post['remember_me'])) { setcookie(COOKIE . '_login', $conditions['username'] . '-' . $conditions['password'], time() + 2592000, '/', $_SERVER['HTTP_HOST']); } // refactory permissions $mod = new Permission_model(); $mod->refactory($_SESSION['xuid']); // log if (LOGS) { $mod = new X4Auth_model('users'); $mod->logger($_SESSION['xuid'], 1, 'users', 'log in'); } // redirect header('Location: ' . $this->site->site->domain . '/' . $_SESSION['lang'] . '/admin'); die; } else { // increase failure counter $_SESSION['failed']++; if (LOGS) { $mod = new X4Auth_model('users'); $mod->logger(0, 1, 'users', 'log in failed for ' . $_post['username']); } } } // redirect header('Location: ' . BASE_URL . 'login'); die; }
/** * Duplicate an area for another language (secret method) * If you need to add another language to an area you can call this script * /admin/modules/duplicate_area_lang/ID_AREA/OLD_LANG/NEW_LANG * * @param integer $id_area Area ID * @param string $old_lang Old language to copy * @param string $new_lang New language to set * @return string */ public function duplicate_area_lang($id_area, $old_lang, $new_lang) { // Comment the next row to enable the method die('Operation disabled!'); $mod = new X4Plugin_model(); // duplicate $res = $mod->duplicate_modules_lang($id_area, $old_lang, $new_lang); if ($res) { // refactory permissions $mod = new Permission_model(); $mod->refactory($_SESSION['xuid']); echo '<h1>CONGRATULATIONS!</h1>'; echo '<p>The changes on the database are applied.</p>'; } else { echo '<h1>WARNING!</h1>'; echo '<p>Something went wrong, changes are not applied.</p>'; } die; }
/** * Install a plugin * * @param integer area ID * @param string plugin name (is the same name of the folder) * @return mixed integer if all runs fine, else an array of error strings */ public function install($id_area, $name) { $error = array(); if (!$this->exists($name, $id_area)) { if (file_exists(PATH . 'plugins/' . $name . '/install.php')) { // area name, required with some installer $area = $this->get_by_id($id_area, 'areas', 'name'); // load installer require_once PATH . 'plugins/' . $name . '/install.php'; // check requirements $error = $this->check_required($required, $id_area, 0); // check area requirements if (isset($area_limit) && !in_array($area->name, $area_limit)) { $error[] = array('error' => array('_incompatible_area'), 'label' => implode(', ', $area_limit)); } // check compatibility if (!isset($compatibility) || !$this->compatibility($compatibility)) { $error[] = array('error' => array('_incompatible_plugin'), 'label' => $name); } if (empty($error)) { // global queries if (!$this->exists($name, $id_area, 1)) { foreach ($sql0 as $i) { $result = $this->db->single_exec($i); } } // area dipendent queries foreach ($sql1 as $i) { $result = $this->db->single_exec($i); } if ($result[1]) { // initialize Mongo DB autoincrement index if (isset($sql2)) { $model = $sql2['model']; $mod = new $model(); $res = $mod->insert($sql2['index'], 'indexes'); } $perm = new Permission_model(); $perm->refactory($_SESSION['xuid']); // return an integer if installation run fine return $result[0]; } else { $error[] = array('error' => array('_plugin_not_installed'), 'label' => $name); } } } else { $error[] = array('error' => array('_missing_plugin_installer'), 'label' => $name); } } else { $error[] = array('error' => array('_already_installed'), 'label' => $name); } // return an array if happen an error return $error; }
/** * Refresh User permission with group's settings * User will keep all customizations * * @param integer $id_user User ID * @return void */ public function refactory($id_user) { $msg = null; // check permission $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], 'users', $id_user, 3); if (is_null($msg)) { $qs = X4Route_core::get_query_string(); // do action $mod = new Permission_model(); $result = $mod->refactory($id_user, null); // set message $this->dict->get_words(); $msg = AdmUtils_helper::set_msg($result); // set update if ($result[1]) { $msg->update[] = array('element' => $qs['div'], 'url' => urldecode($qs['url']), 'title' => null); } } $this->response($msg); }