/** * Minimize css files * * @return void */ public function minimize($id_theme, $name) { $msg = null; // check permission $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], 'themes', $id_theme, 4); if (is_null($msg)) { $qs = X4Route_core::get_query_string(); // do action $res = 1; // get the templates in the theme $mod = new Theme_model(); // CSS section $path = PATH . 'themes/' . $name . '/css/'; $items = $mod->get_css($id_theme); foreach ($items as $i) { if (file_exists($path . $i->css . '.css')) { $txt = file_get_contents($path . $i->css . '.css'); $txt = $mod->compress_css($txt); $chk = file_put_contents($path . $i->css . '.min.css', $txt); if (!$chk) { $res = 0; } } } // JS section X4Core_core::auto_load('jshrink_library'); $path = PATH . 'themes/' . $name . '/js/'; $items = $mod->get_js($id_theme); foreach ($items as $i) { if (file_exists($path . $i->js . '.js')) { $txt = file_get_contents($path . $i->js . '.js'); $txt = Minifier::minify($txt, array('flaggedComments' => false)); $chk = file_put_contents($path . $i->js . '.min.js', $txt); if (!$chk) { $res = 0; } } } $result = array(0, $res); // 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); }
/** * Delete language * * @access private * @param array $_post _POST array * @return void */ private function deleting($_post) { $msg = null; // check permission $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], 'languages', $_post['id'], 4); if (is_null($msg)) { // action $mod = new Language_model(); $result = $mod->delete_lang($_post['id']); // set message $msg = AdmUtils_helper::set_msg($result); // clear useless permissions if ($result[1]) { $perm = new Permission_model(); $perm->deleting_by_what('languages', $_post['id']); // set what update $msg->update[] = array('element' => 'tdown', 'url' => BASE_URL . 'languages', 'title' => null); } } $this->response($msg); }
/** * Delete article's version * * @access private * @param integer $id article ID * @param string $bid BID code * @return void */ private function deleting_version($id) { $msg = null; // check permissions $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], 'articles', $id, 4); if (is_null($msg)) { // do action $mod = new Article_model(); $obj = $mod->get_by_id($id, 'articles', 'id_area, lang, bid'); $result = $mod->delete($id); // clear useless permissions if ($result[1]) { $perm = new Permission_model(); $perm->deleting_by_what('articles', $id); } // set message $msg = AdmUtils_helper::set_msg($result); // set what update if ($result[1]) { $msg->update[] = array('element' => 'topic', 'url' => BASE_URL . 'articles/history/' . $obj->id_area . '/' . $obj->lang . '/' . $obj->bid, 'title' => null); } } $this->response($msg); }
/** * Register site data * * @access private * @param array $_post _POST array * @return void */ private function editing($_post) { $msg = null; // check permission $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], 'sites', $_post['id'], 4); if (is_null($msg)) { // handle _post $post = array('xcode' => X4Utils_helper::unspace($_post['xcode']), 'domain' => $_post['domain']); // do update $result = $this->site->update($_post['id'], $post); // set message $msg = AdmUtils_helper::set_msg($result); // set what update if ($result[1]) { $msg->update[] = array('element' => 'topic', 'url' => BASE_URL . 'sites/show/1', 'title' => null); } } $this->response($msg); }
/** * Register edited file * * @access private * @param array $_post _POST array * @param string $file File path * @return void */ private function editing($_post, $file) { $msg = null; // check permission $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], 'templates', $_post['id'], 2); if (is_null($msg)) { // get file permission $fileperm = substr(sprintf('%o', fileperms($file)), -3); if ($fileperm != 777) { // set file permission chmod($file, 0777); } // update file content $check = file_put_contents($file, $this->replace(0, stripslashes($_post['code']))); chmod($file, 0755); // set message $msg = AdmUtils_helper::set_msg($result); // set what update if ($result[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); }
/** * Delete page * * @access private * @param integer $id Page ID * @return void */ private function deleting($id) { $msg = null; // check permissions $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], 'pages', $id, 4); if (is_null($msg)) { // action $mod = new Page_model('', '', $id); $page = $mod->get_by_id($id, 'pages', 'id_area, lang, xfrom'); $result = $mod->delete_page($id, $this->site->site->domain); // clear useless permissions if ($result[1]) { $perm = new Permission_model(); $perm->deleting_by_what('pages', $id); } // set message $msg = AdmUtils_helper::set_msg($result); // set what update if ($result[1]) { $msg->update[] = array('element' => 'topic', 'url' => BASE_URL . 'pages/index/' . $page->id_area . '/' . $page->lang . '/' . str_replace('/', '-', $page->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); }
/** * Uninstall the plugin * * @access private * @param object $obj Plugin Objject * @return void */ private function uninstalling($obj) { $msg = null; // check permission $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], 'modules', $obj->id, 4); if (is_null($msg)) { // do action $mod = new X4Plugin_model(); $result = $mod->uninstall($obj->id); // check uninstalling if (is_array($result)) { $this->notice(false, '_plugin_not_uninstalled'); die; } else { // set message $msg = AdmUtils_helper::set_msg(true); // uninstalled if ($result) { // clear useless permissions $perm = new Permission_model(); $perm->deleting_by_what('modules', $obj->id); } $area = $mod->get_by_id($obj->id_area, 'areas', 'name'); $msg->update[] = array('element' => 'topic', 'url' => BASE_URL . 'modules/index/' . $obj->id_area . '/' . $area->name, 'title' => null); } } $this->response($msg); }
/** * Delete category * * @access private * @param integer $id Category ID * @param object $obj Category Obj * @return void */ private function deleting($id, $obj) { $msg = null; // check permissions $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], 'categories', $id, 4); if (is_null($msg)) { // do action $mod = new Category_model(); $result = $mod->delete($id); // set message $msg = AdmUtils_helper::set_msg($result); // clear useless permissions if ($result[1]) { $perm = new Permission_model(); $perm->deleting_by_what('categories', $id); // set what update $msg->update[] = array('element' => 'topic', 'url' => BASE_URL . 'categories/index/' . $obj->id_area . '/' . $obj->lang . '/' . $obj->tag, '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); }
/** * Refresh menu order * Called via Ajax * * @param integer $id Page ID * @param integer $holder Menu ID * @param string $orders Encoded string, for each menu you have a section, each section contains the list of Page ID in menu * @return void */ public function menu($id, $holder, $orders) { $msg = null; if (!is_null($id) && is_numeric($id)) { // check permission $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], 'pages', $id, 3); if (is_null($msg)) { // refresh order $menu = new Menu_model(); $result = $menu->menu($id, substr($holder, 1), $orders); // set message $this->dict->get_words(); $msg = AdmUtils_helper::set_msg($result); } } $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); }
/** * Delete area * * @access private * @param integer $id Area ID * @param string $name Area name * @return void */ private function deleting($id, $name) { $msg = null; // check permissions $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], 'areas', $id, 4); if (is_null($msg)) { // action $area = new Area_model(); $result = $area->delete_area($id, $name); // set message $msg = AdmUtils_helper::set_msg($result); // clear useless permissions if ($result[1]) { $perm = new Permission_model(); $perm->deleting_by_what('areas', $id); // set what update $msg->update[] = array('element' => 'topic', 'url' => BASE_URL . 'areas/index/1', 'title' => null); } } $this->response($msg); }