prefix . 'al3x_fl_mngr_users'; // file download hook and function if ($_REQUEST['al3x_download'] == 'file') { add_action('init', 'al3x_download'); } // AJAX hook, only for filemanager if ($_REQUEST['page'] == 'file_manager/file') { add_action('admin_head', 'al3x_display_js'); function al3x_display_js() { echo al3x_tree_js(); } } // admin menue hook add_action('admin_menu','al3x_adm_menu'); function al3x_adm_menu() { global $al3x_set; add_menu_page(__('File Manager'), 'File Manager', 4, 'file_manager/user', 'al3x_file_manager_user', $al3x_set['url'] . '/images/afm.png' ); add_submenu_page('file_manager/user', 'File Manager: manage users', 'user panel', 4, 'file_manager/user', 'al3x_file_manager_user'); add_submenu_page('file_manager/user', 'File Manager: manage files', 'file panel', 4, 'file_manager/file', 'al3x_file_manager_file'); add_submenu_page('file_manager/user', 'File Manager: faq', 'faq', 4, 'file_manager/faq', 'al3x_file_manager_faq'); } function al3x_file_manager_user() { global $wpdb, $al3x_set; include('usermanager.php'); } function al3x_file_manager_file() { global $wpdb, $al3x_set; include('filemanager.php'); } function al3x_file_manager_faq() { include('faq.php'); } // frontend hooks add_action('the_content', 'al3x_frontend'); // activation and deactivation hooks and functions register_activation_hook(__FILE__, 'install_al3x_file_manager'); register_uninstall_hook(__FILE__,'uninstall_al3x_file_manager'); function install_al3x_file_manager() { global $wpdb, $al3x_set; $tab1 = 'CREATE TABLE IF NOT EXISTS `' . $wpdb->prefix . 'al3x_fl_mngr_users' . '` ( `id` BIGINT( 23 ) UNSIGNED NOT NULL AUTO_INCREMENT , `uname` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL , `pword` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL , PRIMARY KEY ( `id` ) , UNIQUE ( `uname` ) ) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci COMMENT = \'al3x file manager table containing user information\';'; $file_path=ABSPATH . 'wp-admin/includes/upgrade.php'; require_once($file_path); dbDelta($tab1); } function uninstall_al3x_file_manager() { global $al3x_set, $wpdb; $sql = 'DROP TABLE IF EXISTS `' . $wpdb->prefix . 'al3x_fl_mngr_users' . '`'; $wpdb->query($sql); } // various functions function al3x_download() { global $al3x_set; global $current_user; if (! headers_sent()) { $user_info = get_userdata($current_user->ID); $userlevel = (int)$user_info->user_level; if ( ( $userlevel >= 4 && is_numeric($_REQUEST['userid']) ) || ( is_numeric($_REQUEST['userid']) && md5($_REQUEST['userid'] . $_SESSION['al3x']['sid']) == $_REQUEST['checksum']) || $_REQUEST['userid'] == 'PUBLIC') { if ($_REQUEST['userid'] == 'PUBLIC') $upath = '0'; else $upath = $_REQUEST['userid']; $al3xfile = $al3x_set['updir'] . '/' . $upath . '/' . addslashes($_REQUEST['filepath']); if (is_file($al3xfile)) { header('HTTP/1.0 200 OK'); header('Cache-Control: no-cache, must-revalidate'); header('Content-Description: File Transfer'); header('Content-Disposition: attachment; filename='.basename($al3xfile)); header('Content-Type: application/octet-stream'); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Pragma: public'); header('Content-Length: ' . filesize($al3xfile)); ob_clean(); flush(); readfile($al3xfile); } } else { header('HTTP/1.0 403 Forbidden'); header('Content-Type: text/plain'); echo "error 403: no permission"; } } exit(); } function al3x_create_dir($dirname, $parentdir) { $return_val = false; $dirname = preg_replace("/\W/", "_", $dirname); if ( chdir($parentdir)) { mkdir($dirname); $return_val = true; } return $return_val; } function al3x_get_user_by_id($id) { global $wpdb, $al3x_set; if (is_numeric($id) ) { $sql = 'SELECT * FROM `' . $al3x_set['usertab'] . '` WHERE id = "' . $id . '"'; $re = $wpdb->get_results($sql); } return $re; } function al3x_del_user_by_id($id) { global $wpdb, $al3x_set; $sql = 'DELETE FROM `' . $al3x_set['usertab'] . '` WHERE `' . $al3x_set['usertab'] . '`.`id` = ' . $id ; $wpdb->query($sql); if (is_dir($al3x_set['updir']. '/' . $id) ) al3x_delete_dir_tree($al3x_set['updir'] . '/' . $id); } function al3x_edit_user($uname, $pword, $uid = '' ) { global $wpdb, $al3x_set; $return_value = false; if ( ctype_alnum(trim($uname)) && trim($pword) ) { if (is_numeric($uid) ) $mode = "REPLACE"; else $mode = "INSERT"; $sql = $mode . ' INTO ' . $al3x_set['usertab'] . ' VALUES("' . $uid . '","' . $uname . '","' . $wpdb->escape($pword) . '")'; if ($wpdb->query($sql)) $return_value = true; } return $return_value; } function al3x_notify($msg,$type='updated') { echo '
' . $msg . '
'; } function al3x_verify_updir() { global $al3x_set; $return_val = false; $htac = '.htaccess'; if (is_writable($al3x_set['updir'] . '/' . $htac) ) { $return_val = true; } elseif (is_dir($al3x_set['updir']) ) { if ($hf = fopen($al3x_set['updir'] .'/'. $htac, 'w') ) { fwrite($hf, "order allow,deny\ndeny from all" ); fclose($hf); $return_val = true; } } if ($indexf = fopen($al3x_set['updir'] .'/index.php', 'w') ) { fwrite($indexf, "\n" ); fclose($indexf); } return $return_val; } function al3x_get_all_users($where='1 = 1', $order='uname') { global $wpdb, $al3x_set; $sql = 'SELECT * FROM `' . $al3x_set['usertab'] . '` WHERE ' . $where . ' ORDER BY ' . $order ; return $wpdb->get_results($sql); } function al3x_build_html_options( $arrDir, $index="0", $levelprefix="> " ) { if (is_array($arrDir) ) { // sort by path! foreach ($arrDir as $key => $arrEntry) { if ($arrEntry['type'] == 'dir') $arrSortbyPath[$arrEntry['path']] = $key; } ksort($arrSortbyPath); // sort end foreach ($arrSortbyPath as $path => $key) { if ($key == 0) $path = 'root directory (default)'; else $path = substr($path, 2); $htmloption .= '