/** * Register New / Edit article data * * @access private * @param object $item Article * @param array $_post _POST array * @return void */ private function editing($item, $_post) { $msg = null; // check permission if ($item->id) { $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], 'articles', $item->id, 2); } if (is_null($msg)) { // handle _post $post = array('bid' => $_post['bid'], 'id_area' => $_post['id_area'], 'lang' => $_post['lang'], 'code_context' => $_post['code_context'], 'category' => $_post['category'], 'id_page' => isset($_post['id_page']) ? $_post['id_page'] : 0, 'date_out' => empty($_post['date_out']) ? 0 : intval(strtotime($_post['date_out'])), 'xkeys' => strtolower($_post['xkeys']), 'name' => $_post['name'], 'content' => $_post['content'], 'js' => html_entity_decode($_post['js']), 'excerpt' => strstr($_post['content'], '<!--pagebreak-->') !== false ? 1 : 0, 'tags' => str_replace(', ', ',', $_post['tags']), 'author' => $_post['author'], 'module' => $_post['module'], 'param' => $_post['param'], 'id_editor' => $_SESSION['xuid'], 'show_author' => intval(isset($_post['show_author'])), 'show_date' => intval(isset($_post['show_date'])), 'show_tags' => intval(isset($_post['show_tags'])), 'show_actions' => intval(isset($_post['show_actions'])), 'xon' => AUTOREFRESH); // adjust date_in value in case of set or update if ($item->id == 0 || $_post['date_in'] != date('Y-m-d', $_post['old_date_in'])) { $post['date_in'] = strtotime($_post['date_in']) + (date('G') * 60 + date('i')) * 60 + date('s'); } else { $post['date_in'] = $_post['old_date_in']; } // insert article $mod = new Article_model(); // check for context // if the code_context is changed we assign a new bid to the article // if the id page is changed we assign a new bid if ($_post['old_context'] > -1 && $_post['old_context'] != $_post['code_context'] || isset($_post['id_page']) && $item->id_page != $_post['id_page']) { $post['bid'] = $mod->get_new_bid(); } $result = $mod->insert($post); if (APC) { apc_delete(SITE . 'abid' . $post['id_area'] . $_post['lang'] . $_post['bid']); if (!empty($post['old_module'])) { apc_delete(SITE . 'pageto' . $post['id_area'] . $_post['lang'] . $_post['old_module'] . $_post['old_param']); } if (!empty($post['module'])) { apc_delete(SITE . 'pageto' . $post['id_area'] . $_post['lang'] . $post['module'] . $post['param']); } } // set message $msg = AdmUtils_helper::set_msg($result); // add permission if ($result[1]) { $perm = new Permission_model(); $array[] = array('action' => 'insert', 'id_what' => $result[0], 'id_user' => $_SESSION['xuid'], 'level' => 4); $res = $perm->pexec('articles', $array, $_post['id_area']); if (!empty($_post['from'])) { $msg->update[] = array('element' => 'topic', 'url' => urldecode($_post['from']), 'title' => null); } } } $this->response($msg); }
/** * Save article * * @param string $bid * @return void */ public function update($bid) { // load dictionaries $this->dict->get_words(); // get article id $mod = new Article_model(); $item = $mod->get_by_bid($bid); // check permission AdmUtils_helper::chklevel($_SESSION['xuid'], 'articles', $item->id, 2); // only if there are differences if ($item->content != $_POST['content']) { // tinymce $post = array('bid' => $bid, 'id_area' => $item->id_area, 'lang' => $item->lang, 'code_context' => $item->code_context, 'id_page' => $item->id_page, 'date_in' => time(), 'xkeys' => $item->xkeys, 'name' => $item->name, 'content' => $_POST['content'], 'excerpt' => 0, 'author' => $_SESSION['mail'], 'module' => $item->module, 'param' => $item->param, 'id_editor' => $_SESSION['xuid'], 'xon' => AUTOREFRESH); // insert new article's version $result = $mod->insert($post); if ($result[1]) { // add permission $perm = new Permission_model(); // privs permissions $array[] = array('action' => 'insert', 'id_what' => $result[0], 'id_user' => $_SESSION['xuid'], 'level' => 4); $res = $perm->pexec('articles', $array, $item->id_area); } // set message X4Utils_helper::set_msg($result); echo $_SESSION['msg']; unset($_SESSION['msg']); } else { echo ''; } }
/** * Perform template install * * @access private * @param array $_post _POST array * @return void */ private function installing($_post) { $msg = null; // check permission $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], '_template_install', 0, 4); if (is_null($msg)) { // handle _post $post = array('name' => $_post['name'], 'css' => $_post['css'], 'id_theme' => $_post['id_theme'], 'description' => $_post['description'], 'sections' => $_post['sections']); $mod = new Template_model(); $result = $mod->insert($post); // set message $msg = AdmUtils_helper::set_msg($result); // add permission on new template if ($result[1]) { $perm = new Permission_model(); $array[] = array('action' => 'insert', 'id_what' => $result[0], 'id_user' => $_SESSION['xuid'], 'level' => 4); $res = $perm->pexec('templates', $array, 1); $theme = $mod->get_var($post['id_theme'], 'themes', 'name'); $msg->update[] = array('element' => 'tdown', 'url' => BASE_URL . 'templates/index/' . $post['id_theme'] . '/' . $theme, 'title' => null); } } $this->response($msg); }
/** * Register new page * * @access private * @param array $_post _POST array * @return void */ private function adding($_post) { $msg = null; // check permissions $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], '_page_creation', 0, 4); if (is_null($msg)) { // remove slash from url if ($_post['id_area'] > 1) { $_post['name'] = str_replace('/', '-', $_post['name']); } // handle _post $post = array('lang' => $_post['lang'], 'id_area' => $_post['id_area'], 'url' => X4Utils_helper::unspace($_post['name'], true), 'name' => $_post['name'], 'title' => $_post['name'], 'description' => $_post['description'], 'xfrom' => $_post['xfrom'], 'tpl' => $_post['tpl']); // load model $mod = new Page_model($_post['id_area'], $_post['lang']); // check if a page with the same URL already exists $check = (bool) $mod->exists($post['url']); if ($check) { $msg = AdmUtils_helper::set_msg(false, '', $this->dict->get_word('_PAGE_ALREADY_EXISTS', 'msg')); } else { // set css for the template of the new page $tmod = new Template_model(); $css = $tmod->get_css($_post['id_area'], $_post['tpl']); $post['css'] = $css; // set xrif for admin pages if ($_post['id_area'] == 1) { $post['xid'] = 'pages'; } // insert the new page $result = $mod->insert_page($post, $this->site->site->domain); // add permission if ($result[1]) { $perm = new Permission_model(); $array[] = array('action' => 'insert', 'id_what' => $result[0], 'id_user' => $_SESSION['xuid'], 'level' => 4); $result = $perm->pexec('pages', $array, $post['id_area']); // refresh article permissions $perm->refactory_table($_SESSION['xuid'], array($post['id_area']), 'articles'); } // set message $msg = AdmUtils_helper::set_msg($result); // set what update if ($result[1]) { $msg->update[] = array('element' => 'topic', 'url' => BASE_URL . 'pages/index/' . $post['id_area'] . '/' . $post['lang'] . '/' . str_replace('/', '-', $post['xfrom']), 'title' => null); } } } $this->response($msg); }
/** * Register Edited image * * @access private * @param integer $id File ID (if 0 then is a new item) * @param array $_post _POST array * @return void */ private function saving($id_file, $_post) { $msg = null; // check permissions $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], 'files', $id_file, 2); if (is_null($msg)) { $ko = _MSG_ERROR; // check if set asnew $asnew = intval(isset($_post['asnew'])); $mod = new File_model(); $file = $mod->get_by_id($id_file); if ($file) { switch ($file->xtype) { case 0: // images $path = APATH . 'files/filemanager/img/'; $rotation = intval($_post['rotate']); $rotation = $rotation ? 360 - $rotation : 0; if ($asnew) { // save a new file // set the new name $final_name = X4Files_helper::get_final_name($path, $file->name); $chk = X4Files_helper::create_cropped($path . $file->name, $path . $final_name, array($_post['width'], $_post['height']), array($_post['xcoord'], $_post['ycoord']), true); if ($chk) { $post = array(); $post[] = array('id_area' => $file->id_area, 'xtype' => $file->xtype, 'category' => $file->category, 'subcategory' => $file->subcategory, 'name' => $final_name, 'alt' => $file->alt, 'xon' => 1); // insert $result = $mod->insert_file($post); // create permissions if ($result[1]) { $id = $result[0]; $perm = new Permission_model(); // privs permissions $array[] = array('action' => 'insert', 'id_what' => $id, 'id_user' => $_SESSION['xuid'], 'level' => 4); $res = $perm->pexec('files', $array, $file->id_area); if ($rotation) { sleep(1); $res = X4Files_helper::rotate($path . $final_name, $path . $final_name, $rotation); } } } else { $result = array($_post['id'], intval($chk)); } } else { // replace old $chk = X4Files_helper::create_cropped($path . $file->name, $path . $file->name, array($_post['width'], $_post['height']), array($_post['xcoord'], $_post['ycoord']), true); if ($chk && $rotation) { sleep(1); $res = X4Files_helper::rotate($path . $file->name, $path . $file->name, $rotation); } $result = array($_post['id'], intval($chk)); $id = $file->id; } break; case 1: // generic text file $path = APATH . 'files/filemanager/files/'; $txt = $_post['content']; $res = file_put_contents($path . $file->name, $txt); $id = $id_file; $result = array($id, intval($res)); break; case 2: // video file // get the command, if exists $ffmpeg = str_replace(NL, '', $this->command_exist('ffmpeg')); if (!empty($ffmpeg)) { $file_name = $file->name; $mimes = array('video/quicktime' => 'mov', 'video/mp4' => 'mp4', 'video/webm' => 'webm', 'video/ogg' => 'ogv', 'application/ogg' => 'ogv', 'video/x-flv' => 'flv', 'video/avi' => 'avi', 'application/vnd.adobe.flash.movie' => 'swf', 'application/x-shockwave-flash' => 'swf'); if (isset($_post['capture'])) { // we have to extract a frame $vpath = APATH . 'files/filemanager/media/'; $ipath = APATH . 'files/filemanager/img/'; $file_name = str_replace($mimes[$_post['old_format']], 'jpg', $file_name); // set the new name $final_name = X4Files_helper::get_final_name($ipath, $file_name); //ffmpeg -i video_file -an -ss 27.888237 -vframes 1 -s 320x240 -f image2 image_file $chk = shell_exec($ffmpeg . ' -i ' . $vpath . $file->name . ' -an -ss ' . $_post['sec'] . ' -vframes 1 -s ' . $_post['iwidth'] . 'x' . $_post['iheight'] . ' -f image2 ' . $ipath . $final_name . ' 2>&1'); if ($chk && file_exists($ipath . $final_name)) { chmod($ipath . $final_name, 0777); $post = array(); $post[] = array('id_area' => $file->id_area, 'xtype' => 0, 'category' => $file->category, 'subcategory' => $file->subcategory, 'name' => $final_name, 'alt' => $file->alt, 'xon' => 1); // insert $result = $mod->insert_file($post); // create permissions if ($result[1]) { $id = $result[0]; $perm = new Permission_model(); // privs permissions $array[] = array('action' => 'insert', 'id_what' => $id, 'id_user' => $_SESSION['xuid'], 'level' => 4); $res = $perm->pexec('files', $array, $file->id_area); } } } else { // is a video conversion $path = APATH . 'files/filemanager/media/'; $new_format = $new_size = 0; if ($_post['old_width'] != $_post['width'] || $_post['old_height'] != $_post['height']) { $new_size = 1; } // if new format is a new file if ($_post['old_format'] != $_post['format']) { $new_format = 1; $file_name = str_replace($mimes[$_post['old_format']], $mimes[$_post['format']], $file_name); } if ($asnew || $new_format) { // save a new file // set the new name $final_name = X4Files_helper::get_final_name($path, $file_name); if ($new_size) { $chk = shell_exec($ffmpeg . ' -i ' . $path . $file->name . ' -vf scale=' . $_post['width'] . ':' . $_post['height'] . ' ' . $path . $final_name . ' 2>&1'); } else { // -c:a copy $chk = shell_exec($ffmpeg . ' -i ' . $path . $file->name . ' ' . $path . $final_name . ' 2>&1'); } if ($chk) { chmod($path . $final_name, 0777); $post = array(); $post[] = array('id_area' => $file->id_area, 'xtype' => $file->xtype, 'category' => $file->category, 'subcategory' => $file->subcategory, 'name' => $final_name, 'alt' => $file->alt, 'xon' => 1); // insert $result = $mod->insert_file($post); // create permissions if ($result[1]) { $id = $result[0]; $perm = new Permission_model(); // privs permissions $array[] = array('action' => 'insert', 'id_what' => $id, 'id_user' => $_SESSION['xuid'], 'level' => 4); $res = $perm->pexec('files', $array, $file->id_area); } } } else { // replace old if ($new_size) { $chk = shell_exec($ffmpeg . ' -i ' . $path . $file->name . ' -vf scale=' . $_post['width'] . ':' . $_post['height'] . ' ' . $path . $file->name . ' 2>&1'); } else { $chk = 1; } $result = array($_post['id'], intval($chk)); $id = $result[0]; } } } else { // ffmpeg not available $result = array(0, 0); $ko = _FFMPEG_NOT_FOUND; } break; case 3: // template $path = APATH . 'files/filemanager/template/'; if (extension_loaded('php5-tidy')) { // clean the code $tidy = tidy_parse_string($_post['content']); $tidy->cleanRepair(); $html = $tidy->html(); } else { $html = $_post['content']; } $res = file_put_contents($path . $file->name, $html); $id = $id_file; $result = array($id, intval($res)); break; } // set message $msg = AdmUtils_helper::set_msg($result, _MSG_OK, $ko); // set what update if ($result[1]) { $msg->update[] = array('element' => 'topic', 'url' => BASE_URL . 'files/editor/' . $id, 'title' => null); } } else { // file not found // set message $msg = AdmUtils_helper::set_msg(array(0, 0)); } } $this->response($msg); }
/** * Install a plugin * * @param integer $id_area Area ID * @param string $plugin_name Plugin name * @return void */ public function install($id_area, $plugin_name) { $msg = null; // check permission $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], '_module_install', 0, 4); if (is_null($msg)) { $qs = X4Route_core::get_query_string(); // load global dictionary $this->dict->get_words(); // install the plugin $mod = new X4Plugin_model(); $result = $mod->install($id_area, $plugin_name); // the result is an array only if an error occurred if (is_array($result) && !empty($result)) { // build msg $str = array(); foreach ($result as $i) { $str[] = $i['label'] . _TRAIT_ . $this->dict->get_word(strtoupper($i['error'][0]), 'msg'); } $msg = AdmUtils_helper::set_msg(false, '', implode('<br />', $str)); } else { // set message $msg = AdmUtils_helper::set_msg(true); // installed if ($result) { $area = $mod->get_by_id($id_area, 'areas', 'name'); // add permission $mod = new Permission_model(); $array[] = array('action' => 'insert', 'id_what' => $result, 'id_user' => $_SESSION['xuid'], 'level' => 4); $result = $mod->pexec('modules', $array, $id_area); // refresh deep, xpos and ordinal $mod = new Menu_model(); $mod->ordinal(1, X4Route_core::$lang, 'modules', 'A0021005'); $msg->update[] = array('element' => 'topic', 'url' => BASE_URL . 'modules/index/' . $id_area . '/' . $area->name, 'title' => null); } } } $this->response($msg); }
/** * Edit widget * * @access private * @param array $_post _POST array * @return void */ private function editing($_post) { $msg = null; // check permissions $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], 'modules', $_post['id'], 1); if (is_null($msg)) { // get obj $mod = new Widget_model(); $obj = $mod->get_by_id($_post['id'], 'modules', 'id_area, name, description'); // handle post $post = array('id_area' => $obj->id_area, 'id_user' => $_SESSION['xuid'], 'id_module' => $_post['id'], 'name' => $obj->name, 'description' => $obj->description); // xpos $xpos = $mod->get_max_pos($_SESSION['xuid']); $post['xpos'] = $xpos; $result = $mod->insert($post); // set message $msg = AdmUtils_helper::set_msg($result); // set what update if ($result[1]) { $perm = new Permission_model(); $array[] = array('action' => 'insert', 'id_what' => $result[0], 'id_user' => $_SESSION['xuid'], 'level' => 4); $res = $perm->pexec('widgets', $array, $post['id_area']); $msg->update[] = array('element' => 'topic', 'url' => BASE_URL . 'widgets', 'title' => null); } } $this->response($msg); }
/** * Register Edit / New User form data * (if 0 then is a new item) * @param integer $id item ID (if 0 then is a new item) * @param array $_post _POST array * @return void */ private function editing($id, $_post) { $msg = null; // check permission $msg = $id ? AdmUtils_helper::chk_priv_level($_SESSION['xuid'], 'users', $id, 2) : AdmUtils_helper::chk_priv_level($_SESSION['xuid'], '_user_creation', 0, 4); if (is_null($msg)) { // handle _post $post = array('lang' => $_post['lang'], 'id_group' => $_post['id_group'], 'username' => $_post['username'], 'description' => $_post['description'], 'mail' => $_post['mail'], 'phone' => $_post['phone'], 'level' => $_post['level']); // update password if (!empty($_post['password'])) { $post['password'] = X4Utils_helper::hashing($_post['password']); } // check if an user with the same username or password already exists $user = new User_model(); $check = (bool) $user->exists($post['username'], $post['mail'], $id); if ($check) { $msg = AdmUtils_helper::set_msg(false, '', $this->dict->get_word('_USER_ALREADY_EXISTS', 'msg')); } else { $perm = new Permission_model(); if ($id) { // update $result = $user->update($id, $post); // update user privileges on areas $perm->set_aprivs($id, $_post['domain']); // redirect $where = '/detail/' . $id; } else { // insert $result = $user->insert($post); // redirect $where = ''; if ($result[1]) { $id = $result[0]; // set privileges on areas $perm->set_aprivs($id, $_post['domain']); // add privs on new user $array[] = array('action' => 'insert', 'id_what' => $result[0], 'id_user' => $_SESSION['xuid'], 'level' => 4); $res = $perm->pexec('users', $array, $_post['id_area']); // refactory permissions for the user $perm->refactory($id); } } // set message $msg = AdmUtils_helper::set_msg($result); // set what update if ($result[1]) { $msg->update[] = array('element' => 'tdown', 'url' => BASE_URL . 'users' . $where, 'title' => null); } } } $this->response($msg); }
/** * Register Edit / New group form data * * @access private * @param array $_post _POST array * @return void */ private function editing($_post) { $msg = null; // check permission $msg = $_post['id'] ? AdmUtils_helper::chk_priv_level($_SESSION['xuid'], 'menus', $_post['id'], 2) : AdmUtils_helper::chk_priv_level($_SESSION['xuid'], '_group_creation', 0, 4); if (is_null($msg)) { // handle _post $post = array('name' => $_post['name'], 'id_area' => $_post['id_area'], 'description' => $_post['description']); // update or insert $group = new Group_model(); if ($_post['id']) { $result = $group->update($_post['id'], $post); } else { $result = $group->insert($post); // add permission if ($result[1]) { $perm = new Permission_model(); $array[] = array('action' => 'insert', 'id_what' => $result[0], 'id_user' => $_SESSION['xuid'], 'level' => 4); $res = $perm->pexec('groups', $array, $_post['id_area']); } } // set message $msg = AdmUtils_helper::set_msg($result); // set what update if ($result[1]) { $msg->update[] = array('element' => 'tdown', 'url' => BASE_URL . 'users', 'title' => null); } } $this->response($msg); }
/** * Register page's composition * Use _POST data * * @param integer item id (if 0 then is a new item) * @param array _POST array * @return void */ public function compositing() { $msg = null; // check permission $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], 'pages', $_POST['id_page'], 3); if (is_null($msg)) { // handle _POST $sections = array(); $post = array('id_area' => $_POST['id_area'], 'id_page' => $_POST['id_page'], 'xon' => 1); // handle _POST for each section for ($i = 1; $i <= $_POST['snum']; $i++) { $post['progressive'] = $i; // delete first comma $articles = substr($_POST['sort' . $i], 0, 1) == ',' ? substr($_POST['sort' . $i], 1) : $_POST['sort' . $i]; $post['articles'] = str_replace(',', '|', $articles); $sections[] = $post; } // register composition $mod = new Section_model(); $result = $mod->compose($sections); APC && apc_delete(SITE . 'sections' . $post['id_page']); // set message $this->dict->get_words(); $msg = AdmUtils_helper::set_msg($result); // add permissions on new sections if ($result[1]) { $msg->update[] = array('element' => 'topic', 'url' => BASE_URL . 'sections/compose/' . $post['id_page'], 'title' => null); if (is_array($result[0]) && !empty($result[0])) { $perm = new Permission_model(); $array = array(); foreach ($result[0] as $i) { $array[] = array('action' => 'insert', 'id_what' => $i, 'id_user' => $_SESSION['xuid'], 'level' => 4); } $result = $perm->pexec('sections', $array, $_POST['id_area']); } } } $this->response($msg); }
/** * Register Edit / New Menu form data * * @access private * @param array $_post _POST array * @return void */ private function editing($id, $_post) { $msg = null; // check permission if ($_post['id']) { $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], 'menus', $_post['id'], 2); } else { $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], '_menu_creation', 0, 4); } if (is_null($msg)) { // handle _post $post = array('id_theme' => $_post['id_theme'], 'name' => $_post['name'], 'description' => $_post['description']); $mod = new Menu_model(); // update or insert if ($_post['id']) { $result = $mod->update($_post['id'], $post); } else { $result = $mod->insert($post); // add pemission if ($result[1]) { $perm = new Permission_model(); $array[] = array('action' => 'insert', 'id_what' => $result[0], 'id_user' => $_SESSION['xuid'], 'level' => 4); $result = $perm->pexec('menus', $array, 1); } } // set message $msg = AdmUtils_helper::set_msg($result); if ($result[1]) { $theme = $mod->get_var($post['id_theme'], 'themes', 'name'); $msg->update[] = array('element' => 'tdown', 'url' => BASE_URL . 'menus/index/' . $post['id_theme'] . '/' . $theme, 'title' => null); } } $this->response($msg); }
/** * Perform the importing of words * * @access private * @param array $_post _POST array * @return void */ private function importing($_post) { $msg = null; // check permission $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], '_key_import', 0, 4); if (is_null($msg)) { // get key list($lang, $area, $what) = explode('-', $_post['what']); // handle _post $post = array('lang' => $_post['lang'], 'area' => $_post['area'], 'what' => $what, 'xon' => 1); // set the translator X4Core_core::auto_load('google_translate_library'); $translator = new GoogleTranslate($lang, $post['lang']); // get words to import $dict = new Dictionary_model(); if ($what == 'ALL') { // import all sections in an area $sections = $dict->get_sections($lang, $area); $result = true; foreach ($sections as $s) { // get words in section $words = $dict->get_words_to_import($lang, $area, $s->what, $post['lang'], $post['area']); if (!empty($words)) { $post['what'] = $s->what; // import foreach ($words as $i) { $post['xkey'] = $i->xkey; // try to translate if ($lang != $post['lang']) { $value = $translator->translate($i->xval); } else { $value = $i->xval; } // set the word $post['xval'] = $value; // insert $result = $dict->insert($post); // add permission if ($result[1]) { $amod = new Area_model(); $id_area = $amod->get_area_id($_post['area']); $perm = new Permission_model(); $array[] = array('action' => 'insert', 'id_what' => $result[0], 'id_user' => $_SESSION['xuid'], 'level' => 4); $res = $perm->pexec('dictionary', $array, $id_area); } } } } // set what for redirect $what = 'global'; } else { // import only one section $words = $dict->get_words_to_import($lang, $area, $what, $post['lang'], $post['area']); $result = true; // import foreach ($words as $i) { $post['xkey'] = $i->xkey; // try to translate if ($lang != $post['lang']) { $value = $translator->translate($i->xval); } else { $value = $i->xval; } // set the word $post['xval'] = $value; // insert $result = $dict->insert($post); // add permission if ($result[1]) { $amod = new Area_model(); $id_area = $amod->get_area_id($_post['area']); $perm = new Permission_model(); $array[] = array('action' => 'insert', 'id_what' => $result[0], 'id_user' => $_SESSION['xuid'], 'level' => 4); $res = $perm->pexec('dictionary', $array, $id_area); } } } $msg = AdmUtils_helper::set_msg($result); // set what update if ($result[1]) { $msg->update[] = array('element' => 'tdown', 'url' => BASE_URL . 'dictionary/keys/' . $post['lang'] . '/' . $post['area'] . '/' . $what, 'title' => null); } } $this->response($msg); }
/** * Register Edit / New Context form data * * @access private * @param integer $id item ID (if 0 then is a new item) * @param array $_post _POST array * @return void */ private function editing($id, $_post) { $msg = null; // check permission $msg = $id ? AdmUtils_helper::chk_priv_level($_SESSION['xuid'], 'contexts', $id, 3) : AdmUtils_helper::chk_priv_level($_SESSION['xuid'], '_context_creation', 0, 4); if (is_null($msg)) { // handle _post $post = array('id_area' => $_post['id_area'], 'lang' => $_post['lang'], 'name' => strtolower($_post['name']), 'xkey' => X4Utils_helper::unspace($_post['name'])); $mod = new Context_model(); // check if context already exists $check = $mod->exists($post, $id); if ($check) { $msg = AdmUtils_helper::set_msg(false, '', $this->dict->get_word('_CONTEXT_ALREADY_EXISTS', 'msg')); } else { // update or insert if ($id) { $result = $mod->update($id, $post); // check if dictionary name for the context already exists if ($result[1]) { $mod->check_dictionary($post); } } else { // get the code of the new context $code = $mod->get_max_code($post['id_area'], $post['lang']); // this implies that the site can't have more than 33 languages // you have 3 default contexts (draft, page, multipages) for each language and for each area $post['code'] = $code > 100 ? $code + 1 : 101; $result = $mod->insert($post); if ($result[1]) { // add item into dictionary $mod->check_dictionary($post, 1); // create permission $perm = new Permission_model(); $array[] = array('action' => 'insert', 'id_what' => $result[0], 'id_user' => $_SESSION['xuid'], 'level' => 4); $res = $perm->pexec('contexts', $array, $post['id_area']); } } // set message $msg = AdmUtils_helper::set_msg($result); // set what update if ($result[1]) { $msg->update[] = array('element' => 'topic', 'url' => BASE_URL . 'contexts/index/' . $post['id_area'] . '/' . $post['lang'], 'title' => null); } } } $this->response($msg); }
/** * Install a theme * * @param string $theme_name Theme name * @return void */ public function install($theme_name) { $msg = null; // check permission $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], '_theme_install', 0, 4); if (is_null($msg)) { $qs = X4Route_core::get_query_string(); // perform the install $theme = new Theme_model(); $result = $theme->install($theme_name); // if result is an array an error occurred if (is_array($result)) { $this->notice(false, '_theme_not_installed'); die; } else { // installed // set message $this->dict->get_words(); $msg = AdmUtils_helper::set_msg(true); // add permission on new theme if ($result) { $perm = new Permission_model(); $array[] = array('action' => 'insert', 'id_what' => $result, 'id_user' => $_SESSION['xuid'], 'level' => 4); $result = $perm->pexec('themes', $array, 1); // refactory permissions $perm->refactory_table($_SESSION['xuid'], array(1), 'themes'); $perm->refactory_table($_SESSION['xuid'], array(1), 'templates'); $perm->refactory_table($_SESSION['xuid'], array(1), 'menus'); } $msg->update[] = array('element' => 'tdown', 'url' => BASE_URL . 'themes', 'title' => null); } } $this->response($msg); }
/** * Register Edit / New Category form data * * @access private * @param integer $id item ID (if 0 then is a new item) * @param array $_post _POST array * @return void */ private function editing($id, $_post) { $msg = null; // check permission $msg = $id ? AdmUtils_helper::chk_priv_level($_SESSION['xuid'], 'categories', $_post['id'], 3) : AdmUtils_helper::chk_priv_level($_SESSION['xuid'], '_category_creation', 0, 4); if (is_null($msg)) { // handle _post $post = array('id_area' => $_post['id_area'], 'lang' => $_post['lang'], 'title' => $_post['title'], 'name' => X4Utils_helper::unspace($_post['title']), 'tag' => X4Utils_helper::unspace($_post['tag'])); $mod = new Category_model(); // check if category already exists $check = $mod->exists($post, $id); if ($check) { $msg = AdmUtils_helper::set_msg(false, '', $this->dict->get_word('_CATEGORY_ALREADY_EXISTS', 'msg')); } else { // update or insert if ($id) { $result = $mod->update($_post['id'], $post); } else { $result = $mod->insert($post); // create permissions if ($result[1]) { $perm = new Permission_model(); $array[] = array('action' => 'insert', 'id_what' => $result[0], 'id_user' => $_SESSION['xuid'], 'level' => 4); $res = $perm->pexec('categories', $array, $_post['id_area']); } } // set message $msg = AdmUtils_helper::set_msg($result); // set what update if ($result[1]) { $msg->update[] = array('element' => 'topic', 'url' => BASE_URL . 'categories/index/' . $post['id_area'] . '/' . $post['lang'] . '/' . $post['tag'], 'title' => null); } } } $this->response($msg); }
/** * Register Edit / New language data * * @access private * @param integer $id item ID (if 0 then is a new item) * @param array $_post _POST array * @return void */ private function editing($id, $_post) { $msg = null; // check permission if ($id) { $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], 'languages', $_post['id'], 3); } else { $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], '_language_creation', 0, 4); } if (is_null($msg)) { // handle _post $post = array('code' => X4Utils_helper::unspace($_post['code']), 'language' => $_post['language'], 'rtl' => intval(isset($_post['rtl']))); $lang = new Language_model(); // check if language already exists $check = $lang->exists($post, $id); if ($check) { $msg = AdmUtils_helper::set_msg(false, '', $this->dict->get_word('_LANGUAGE_ALREADY_EXISTS', 'msg')); } else { // update or insert if ($id) { $result = $lang->update($_post['id'], $post); } else { $result = $lang->insert($post); // create permissions if ($result[1]) { $perm = new Permission_model(); $array[] = array('action' => 'insert', 'id_what' => $result[0], 'id_user' => $_SESSION['xuid'], 'level' => 4); $res = $perm->pexec('languages', $array, 1); } } // set message $msg = AdmUtils_helper::set_msg($result); // set what update if ($result[1]) { $msg->update[] = array('element' => 'tdown', 'url' => BASE_URL . 'languages', 'title' => null); } } } $this->response($msg); }
/** * Register Edit / New Area form data * * @access private * @param integer $id item ID (if 0 then is a new item) * @param array $_post _POST array * @return void */ private function editing($id, $_post) { $msg = null; // check permissions $msg = $id ? AdmUtils_helper::chk_priv_level($_SESSION['xuid'], 'areas', $id, 2) : AdmUtils_helper::chk_priv_level($_SESSION['xuid'], '_area_creation', 0, 4); if (is_null($msg)) { // handle _post $post = array('lang' => $_post['lang'], 'name' => X4Utils_helper::unspace($_post['name']), 'title' => $_post['title'], 'description' => $_post['description'], 'id_theme' => $_post['id_theme'], 'private' => intval(isset($_post['private'])) && $_post['private'], 'folder' => $_post['folder']); $mod = new Area_model(); // check if area name already exists $check = (bool) $mod->exists($post['name'], $id); if ($check) { $msg = AdmUtils_helper::set_msg(false, '', $this->dict->get_word('_AREA_ALREADY_EXISTS', 'msg')); } else { // Redirect checker $redirect = false; // enable logs if (LOGS && DEVEL) { $mod->set_log(true); } // update or insert if ($id) { $result = $mod->update($id, $post); if ($id == 1 && X4Route_core::$lang != $post['lang']) { $redirect = true; } } else { $result = $mod->insert($post); // create permissions if ($result[1]) { $id = $result[0]; $perm = new Permission_model(); // aprivs permissions $domain = X4Utils_helper::obj2array($perm->get_aprivs($_SESSION['xuid']), null, 'id_area'); $domain[] = $result[0]; $res = $perm->set_aprivs($_SESSION['xuid'], $domain); // privs permissions $array[] = array('action' => 'insert', 'id_what' => $id, 'id_user' => $_SESSION['xuid'], 'level' => 4); $res = $perm->pexec('areas', $array, $id); } } if ($result[1]) { // refresh languages related to area $lang = new Language_model(); $lang->set_alang($id, $_post['languages'], $_post['lang']); // update theme settings if ($_post['id'] && $_post['id_theme'] != $_post['old_id_theme']) { $menu = new Menu_model(); // reset tpl, css, id_menu, ordinal $result = $menu->reset($_post['id']); $langs = $lang->get_languages(); // restore ordinal foreach ($langs as $i) { $menu->ordinal($_post['id'], $i->code, 'home', 'A'); } } if (APC) { apc_clear_cache(); apc_clear_cache('user'); apc_clear_cache('opcode'); } } // set message $msg = AdmUtils_helper::set_msg($result); // set what update if ($result[1]) { if ($redirect) { X4Route_core::redirect($this->site->site->domain . '/admin'); } else { $msg->update[] = array('element' => 'topic', 'url' => BASE_URL . 'areas', 'title' => null); } } } } $this->response($msg); }