function clean($name) { if (is_array($name)) { foreach ($name as $n) { $this->clean($n); } return; } $name = preg_replace('![^a-z0-9_]!i', '_', $name); kleeja_unlink(PATH . 'cache/' . $name . '.php'); }
$lang['STYLE_DIR_NOT_WR'] = sprintf($lang['STYLE_DIR_NOT_WR'], $d_style_path); if (!is_writable($d_style_path)) { @chmod($d_style_path, 0777); if (is_writable($d_style_path)) { $not_style_writeable = false; } } else { $not_style_writeable = false; } $template_content = file_get_contents($tpl_path); $template_content = htmlspecialchars(stripslashes($template_content)); break; //delete tpl //delete tpl case 2: kleeja_unlink($tpl_path); //show msg $link = basename(ADMIN_PATH) . '?cp=' . basename(__FILE__, '.php') . '&style_choose=' . $style_id . '&method=1'; $text = $lang['TPL_DELETED'] . '<br /> <a href="' . $link . '">' . $lang['GO_BACK_BROWSER'] . '</a><meta HTTP-EQUIV="REFRESH" content="1; url=' . $link . '">' . "\n"; $stylee = "admin_info"; break; } } // submit edit of tpl if (isset($_POST['template_content'])) { $style_id = str_replace('..', '', $SQL->escape($_POST['style_id'])); //tpl name $tpl_name = htmlspecialchars_decode($_POST['tpl_choose']); $tpl_path = PATH . 'styles/' . $style_id . '/' . $tpl_name; $tpl_content = stripslashes($_POST['template_content']); $link = basename(ADMIN_PATH) . '?cp=' . basename(__FILE__, '.php') . '&sty_t=st&style_choose=' . $style_id . '&method=1';
// may.. will protect if (empty($cd)) { kleeja_err($lang['WRONG_URL']); } else { //to check if (isset($_GET['sure']) && $_GET['sure'] == 'ok') { $query = array('SELECT' => 'f.id, f.name, f.folder, f.size', 'FROM' => "{$dbprefix}files f", 'WHERE' => "f.code_del='" . $cd . "'", 'LIMIT' => '1'); ($hook = kleeja_run_hook('qr_select_file_with_code_del')) ? eval($hook) : null; //run hook $result = $SQL->build($query); if ($SQL->num_rows($result) != 0) { while ($row = $SQL->fetch_array($result)) { @kleeja_unlink($row['folder'] . '/' . $row['name']); //delete thumb if (file_exists($row['folder'] . '/thumbs/' . $row['name'])) { @kleeja_unlink($row['folder'] . '/thumbs/' . $row['name']); } $query_del = array('DELETE' => "{$dbprefix}files", 'WHERE' => 'id=' . $row['id']); ($hook = kleeja_run_hook('qr_del_file_with_code_del')) ? eval($hook) : null; //run hook $SQL->build($query_del); if ($SQL->affected()) { //update number of stats $update_query = array('UPDATE' => "{$dbprefix}stats", 'SET' => 'files=files-1,sizes=sizes-' . $row['size']); $SQL->build($update_query); kleeja_info($lang['DELETE_SUCCESFUL']); } else { kleeja_info($lang['ERROR_TRY_AGAIN']); } break; //to prevent divel actions
/** * Delete cached data * * @param mixed $name The unique name of the cached data, or many names as array * @return bool True if exists, false if not */ public function clean($name) { if (is_array($name)) { foreach ($name as $n) { $this->clean($n); } return true; } $name = preg_replace('![^a-z0-9_]!i', '_', $name); #if apc if ($this->cache_type == 'apc') { return apc_delete($name); } #else, file based kleeja_unlink(PATH . 'cache/' . $name . '.php'); return true; }
if (!kleeja_check_form_key_get('adm_users')) { kleeja_admin_err($lang['INVALID_GET_KEY'], true, $lang['ERROR'], true, $action_all, 2); } //is exists ? if (!$SQL->num($SQL->query("SELECT * FROM {$dbprefix}users WHERE id=" . intval($_GET['deleteuserfile'])))) { redirect($action_all); } $query = array('SELECT' => 'size, name, folder', 'FROM' => "{$dbprefix}files", 'WHERE' => 'user='******'deleteuserfile'])); $result = $SQL->build($query); $sizes = $num = 0; while ($row = $SQL->fetch($result)) { //delete from folder .. @kleeja_unlink(PATH . $row['folder'] . "/" . $row['name']); //delete thumb if (file_exists(PATH . $row['folder'] . "/thumbs/" . $row['name'])) { @kleeja_unlink(PATH . $row['folder'] . "/thumbs/" . $row['name']); } $num++; $sizes += $row['size']; } $SQL->free($result); if ($num == 0) { kleeja_admin_err($lang['ADMIN_DELETE_NO_FILE'], true, '', true, $action_all, 2); } else { //update number of stats $update_query = array('UPDATE' => "{$dbprefix}stats", 'SET' => "sizes=sizes-{$sizes}, files=files-{$num}"); $SQL->build($update_query); if ($SQL->affected()) { delete_cache('data_stats'); } //delete all files in just one query
/** * * We need to develop this .. add ftp - etc * * Simple script to extract files from a .tar archive * * @param string $file The .tar archive filepath * @param string $dest [optional] The extraction destination filepath, defaults to "./" * @return boolean Success or failure */ function untar($file, $dest = "./") { if (!is_readable($file)) { return false; } $filesize = @filesize($file); // Minimum 4 blocks if ($filesize <= 512 * 4) { return false; } if (!preg_match("/\\/\$/", $dest)) { // Force trailing slash $dest .= "/"; } //Ensure write to destination /*if (!file_exists($dest)) { if (!mkdir($dest, 0777, true)) { return false; } }*/ $total = 0; if ($fh = @fopen($file, 'rb')) { $files = array(); while (($block = fread($fh, 512)) !== false) { $total += 512; $meta = array(); // Extract meta data // http://www.mkssoftware.com/docs/man4/tar.4.asp $meta['filename'] = trim(substr($block, 0, 99)); $meta['mode'] = octdec((int) trim(substr($block, 100, 8))); $meta['userid'] = octdec(substr($block, 108, 8)); $meta['groupid'] = octdec(substr($block, 116, 8)); $meta['filesize'] = octdec(substr($block, 124, 12)); $meta['mtime'] = octdec(substr($block, 136, 12)); $meta['header_checksum'] = octdec(substr($block, 148, 8)); $meta['link_flag'] = octdec(substr($block, 156, 1)); $meta['linkname'] = trim(substr($block, 157, 99)); $meta['databytes'] = $meta['filesize'] + 511 & ~511; if ($meta['link_flag'] == 5) { // Create folder $this->f->_mkdir($dest . $meta['filename'], 0777); $this->f->_chmod($dest . $meta['filename'], $meta['mode']); } if ($meta['databytes'] >= 0 && $meta['header_checksum'] != 0) { $block = @fread($fh, $meta['databytes']); // Extract data $data = substr($block, 0, $meta['filesize']); $this->f->_write($dest . $meta['filename'], $data); //write if ($meta['mode'] == 0744) { $meta['mode'] = 0644; } $this->f->_chmod($dest . $meta['filename'], $meta['mode']); //privileges stuff /* // Write data and set permissions if (false !== ($ftmp = @fopen($dest . $meta['filename'], 'wb'))) { @flock($ftmp, LOCK_EX); // exlusive look @fwrite($ftmp, $data); @fclose($ftmp); //@touch($dest . $meta['filename'], $meta['mtime'], $meta['mtime']); if ($meta['mode'] == 0744) { $meta['mode'] = 0644; } @chmod($dest . $meta['filename'], $meta['mode']); } */ $total += $meta['databytes']; $files[] = $meta; } if ($total >= $filesize - 1024) { //Yayy !! .. extracted everything , now delete the archive kleeja_unlink($file); return $files; } } } return false; }
//else submit //new plugin from xml if (isset($_POST['submit_new_plg'])) { $text = ''; // oh , some errors if ($_FILES['imp_file']['error']) { $text = $lang['ERR_IN_UPLOAD_XML_FILE']; } else { if (!is_uploaded_file($_FILES['imp_file']['tmp_name'])) { $text = $lang['ERR_UPLOAD_XML_FILE_NO_TMP']; } } //get content $contents = @file_get_contents($_FILES['imp_file']['tmp_name']); // Delete the temporary file if possible kleeja_unlink($_FILES['imp_file']['tmp_name']); // Are there contents? if (!trim($contents)) { kleeja_admin_err($lang['ERR_UPLOAD_XML_NO_CONTENT'], true, '', true, basename(ADMIN_PATH) . '?cp=' . basename(__FILE__, '.php')); } if (empty($text)) { if (isset($_POST['_fmethod']) && $_POST['_fmethod'] == 'kftp') { $plg->f_method = 'kftp'; if (empty($_POST['ftp_host']) || empty($_POST['ftp_port']) || empty($_POST['ftp_user']) || empty($_POST['ftp_pass'])) { kleeja_admin_err($lang['EMPTY_FIELDS'], true, '', true, basename(ADMIN_PATH) . '?cp=' . basename(__FILE__, '.php')); } else { $plg->info = $ftpinfo = array('host' => $_POST['ftp_host'], 'port' => $_POST['ftp_port'], 'user' => $_POST['ftp_user'], 'pass' => $_POST['ftp_pass'], 'path' => $_POST['ftp_path']); $ftpinfo['pass'] = ''; update_config('ftp_info', serialize($ftpinfo), false); if (!$plg->check_connect()) { kleeja_admin_err($lang['LOGIN_ERROR'], true, '', true, basename(ADMIN_PATH) . '?cp=' . basename(__FILE__, '.php') . '?#!cp=' . basename(__FILE__, '.php'));
function _write($filepath, $content) { $fnames = explode('/', $filepath); $filename = array_pop($fnames); $extension = strtolower(array_pop(explode('.', $filename))); $path = dirname($fnames); $cached_file = PATH . 'cache/plg_system_' . $filename; //make it as a cached one $h = @fopen($cached_file, 'wb'); fwrite($h, $content); @fclose($h); if (in_array($extension, array('gif', 'jpg', 'png'))) { $mode = FTP_BINARY; } else { $mode = FTP_ASCII; } $this->_chdir($this->_fixpath($path)); $r = @ftp_put($this->handler, $filename, $this->_fixpath($cached_file), $mode); $this->_chdir($this->root); kleeja_unlink($cached_file); return $r; }
function klj_clean_old_files($from = 0) { global $config, $SQL, $stat_last_f_del, $dbprefix; $return = false; ($hook = kleeja_run_hook('klj_clean_old_files_func')) ? eval($hook) : null; //run hook if ((int) $config['del_f_day'] <= 0 || $return) { return; } if (!$stat_last_f_del || empty($stat_last_f_del)) { $stat_last_f_del = time(); } if (time() - $stat_last_f_del >= 86400) { $totaldays = time() - $config['del_f_day'] * 86400; $not_today = time() - 86400; #This feature will work only if id_form is not empty or direct ! $query = array('SELECT' => 'f.id, f.last_down, f.name, f.type, f.folder, f.time, f.size, f.id_form', 'FROM' => "{$dbprefix}files f", 'WHERE' => "f.last_down < {$totaldays} AND f.time < {$not_today} AND f.id > {$from} AND f.id_form <> '' AND f.id_form <> 'direct'", 'ORDER BY' => 'f.id ASC', 'LIMIT' => '20'); ($hook = kleeja_run_hook('qr_select_klj_clean_old_files_func')) ? eval($hook) : null; //run hook $result = $SQL->build($query); $num_of_files_to_delete = $SQL->num_rows($result); if ($num_of_files_to_delete == 0) { //update $stat_last_f_del !! $update_query = array('UPDATE' => "{$dbprefix}stats", 'SET' => "last_f_del ='" . time() . "'"); ($hook = kleeja_run_hook('qr_update_lstf_del_date_kcof')) ? eval($hook) : null; //run hook $SQL->build($update_query); //delete stats cache delete_cache("data_stats"); update_config('klj_clean_files_from', '0'); $SQL->freeresult($result); return; } $last_id_from = $files_num = $imgs_num = $real_num = $sizes = 0; $ids = array(); $ex_ids = array(); //$ex_types = explode(',', $config['livexts']); ($hook = kleeja_run_hook('beforewhile_klj_clean_old_files_func')) ? eval($hook) : null; //run hook //phpfalcon plugin $exlive_types = explode(',', $config['imagefolderexts']); //delete files while ($row = $SQL->fetch_array($result)) { $continue = true; $real_num++; $last_id_from = $row['id']; $is_image = in_array(strtolower(trim($row['type'])), array('gif', 'jpg', 'jpeg', 'bmp', 'png')) ? true : false; /* //excpetions if(in_array($row['type'], $ex_types) || $config['id_form'] == 'direct') { $ex_ids[] = $row['id']; continue; } */ //excpetions //if($config['id_form'] == 'direct') //{ //$ex_ids[] = $row['id']; //move on //continue; //} //your exepctions ($hook = kleeja_run_hook('while_klj_clean_old_files_func')) ? eval($hook) : null; //run hook //phpfalcon plugin if (in_array($row['type'], $exlive_types)) { $ex_ids[] = $row['id']; if ($real_num != $num_of_files_to_delete) { $continue = false; } } if ($continue) { //delete from folder .. if (file_exists($row['folder'] . "/" . $row['name'])) { @kleeja_unlink($row['folder'] . "/" . $row['name']); } //delete thumb if (file_exists($row['folder'] . "/thumbs/" . $row['name'])) { @kleeja_unlink($row['folder'] . "/thumbs/" . $row['name']); } $ids[] = $row['id']; if ($is_image) { $imgs_num++; } else { $files_num++; } $sizes += $row['size']; } } #END WHILE $SQL->freeresult($result); if (sizeof($ex_ids)) { $update_query = array('UPDATE' => "{$dbprefix}files", 'SET' => "last_down = '" . (time() + 2 * 86400) . "'", 'WHERE' => "id IN (" . implode(',', $ex_ids) . ")"); ($hook = kleeja_run_hook('qr_update_lstdown_old_files')) ? eval($hook) : null; //run hook $SQL->build($update_query); } if (sizeof($ids)) { $query_del = array('DELETE' => "{$dbprefix}files", 'WHERE' => "id IN (" . implode(',', $ids) . ")"); //update number of stats $update_query = array('UPDATE' => "{$dbprefix}stats", 'SET' => "sizes=sizes-{$sizes},files=files-{$files_num}, imgs=imgs-{$imgs_num}"); ($hook = kleeja_run_hook('qr_del_delf_old_files')) ? eval($hook) : null; //run hook $SQL->build($query_del); $SQL->build($update_query); } update_config('klj_clean_files_from', $last_id_from); } //stat_del }