static function Display() { wpfb_loadclass('Output', 'File', 'Category', 'TplLib'); $content = ''; $file_tpls = WPFB_Core::GetTpls('file'); $cat_tpls = WPFB_Core::GetTpls('cat'); if (true || !isset($file_tpls['filebrowser_admin'])) { $file_tpls['filebrowser_admin'] = '%file_small_icon% ' . '%file_display_name% (%file_size%) ' . '<!-- IF %file_user_can_edit% --><a href="%file_edit_url%" class="edit" onclick="wpfbFBEditFile(event)">%\'Edit\'%</a><!-- ENDIF -->' . '<!-- IF %file_user_can_edit% --><a href="#" class="delete" onclick="return confirm(\'Sure?\') && wpfbFBDelete(event) && false;">%\'Delete\'%</a><!-- ENDIF -->'; WPFB_Core::SetFileTpls($file_tpls); //WPFB_Admin::ParseTpls(); } if (true || !isset($cat_tpls['filebrowser_admin'])) { $cat_tpls['filebrowser_admin'] = '<span class="cat-icon" style="background-image:url(\'%cat_icon_url%\');"><span class="cat-icon-overlay"></span></span>' . '%cat_name% ' . '<!-- IF %cat_user_can_edit% --><a href="%cat_edit_url%" class="edit" onclick="wpfbFBEditCat(event)">%\'Edit\'%</a><!-- ENDIF -->' . '<!-- IF %cat_user_can_edit% --><a href="#" class="delete" onclick="return confirm(\'Sure?\') && wpfbFBDelete(event) && false;">%\'Delete\'%</a><!-- ENDIF -->'; WPFB_Core::SetCatTpls($cat_tpls); WPFB_Admin::ParseTpls(); } WPFB_Output::FileBrowser($content, 0, empty($_GET['wpfb_cat']) ? 0 : intval($_GET['wpfb_cat'])); WPFB_Core::PrintJS(); ?> <div class="wrap filebrowser-admin"> <h2><?php _e('File Browser', 'wp-filebase'); ?> </h2> <?php echo '<div>' . __('You can Drag & Drop (multiple) files directly on Categories to upload them. Dragging a category or an existing file to another category is also possible.', 'wp-filebase') . '</div>'; echo $content; ?> </div> <script> function wpfbFBEditCat(e) { e.stopPropagation(); } function wpfbFBEditFile(e) { e.stopPropagation(); } function wpfbFBDelete(e) { e.stopPropagation(); var t = jQuery(e.currentTarget).parents('li').first(); var d = {wpfb_action: 'delete'}; var tid = t.attr('id').split('-'); d[tid[tid.length-2]+'_id'] = +tid[tid.length-1]; jQuery.ajax({type: 'POST', url: wpfbConf.ajurl, data: d, //async: false, success: (function (data) { if (data == '1') { t.fadeOut(300, function() { t.remove(); }); } }) }); return false; } </script> <?php }
static function AddTraffic($bytes) { $traffic = wpfb_call('Misc', 'GetTraffic'); $traffic['month'] = $traffic['month'] + $bytes; $traffic['today'] = $traffic['today'] + $bytes; $traffic['time'] = time(); WPFB_Core::UpdateOption('traffic_stats', $traffic); }
function _manually_load_plugin() { require dirname(dirname(__FILE__)) . '/wp-filebase.php'; add_action('init', function () { require_once dirname(dirname(__FILE__)) . '/classes/Core.php'; wpfb_loadclass('Setup'); WPFB_Setup::OnActivateOrVerChange(null); WPFB_Core::$settings = (object) get_option(WPFB_OPT_NAME); WPFB_Core::InitClass(); }, 1); }
static function AdminBar() { global $wp_admin_bar; WPFB_Core::PrintJS(); $wp_admin_bar->add_menu(array('id' => WPFB, 'title' => WPFB_PLUGIN_NAME, 'href' => admin_url('admin.php?page=wpfilebase_manage'))); $wp_admin_bar->add_menu(array('parent' => WPFB, 'id' => WPFB . '-add-file', 'title' => __('Add File', WPFB), 'href' => admin_url('admin.php?page=wpfilebase_files#addfile'))); $current_object = get_queried_object(); if (!empty($current_object) && !empty($current_object->post_type) && $current_object->ID > 0) { $link = WPFB_PLUGIN_URI . 'editor_plugin.php?manage_attachments=1&post_id=' . $current_object->ID; $wp_admin_bar->add_menu(array('parent' => WPFB, 'id' => WPFB . '-attachments', 'title' => __('Manage attachments', WPFB), 'href' => $link, 'meta' => array('onclick' => 'window.open("' . $link . '", "wpfb-manage-attachments", "width=680,height=400,menubar=no,location=no,resizable=no,status=no,toolbar=no,scrollbars=yes");return false;'))); } $wp_admin_bar->add_menu(array('parent' => WPFB, 'id' => WPFB . '-add-file', 'title' => __('Sync Filebase', WPFB), 'href' => admin_url('admin.php?page=wpfilebase_manage&action=sync'))); $wp_admin_bar->add_menu(array('parent' => WPFB, 'id' => WPFB . '-toggle-context-menu', 'title' => __(!empty(WPFB_Core::$settings->file_context_menu) ? 'Disable file context menu' : 'Enable file context menu', WPFB), 'href' => 'javascript:;', 'meta' => array('onclick' => 'return wpfb_toggleContextMenu();'))); }
static function GetEngine() { if (!self::$engine) { if (!class_exists('getID3')) { $tmp_dir = WPFB_Core::UploadDir() . '/.tmp'; if (!is_dir($tmp_dir)) { @mkdir($tmp_dir); } define('GETID3_TEMP_DIR', $tmp_dir . '/'); unset($tmp_dir); require_once WPFB_PLUGIN_ROOT . 'extras/getid3/getid3.php'; } self::$engine = new getID3(); } return self::$engine; }
function __construct() { wpfb_loadclass('Download', 'Admin'); $dir = WPFB_Core::UploadDir() . '/.tmp/'; WPFB_Admin::Mkdir($dir); $test_files = array('banner.png' => 'https://wpfilebase.com/wp-content/blogs.dir/2/files/2015/03/banner_023.png', 'small.txt' => 'https://wpfilebase.com/robots.txt'); $this->local_files = array(); foreach ($test_files as $f => $u) { $fn = $dir . $f; $this->local_files[$f] = $fn; if (file_exists($fn)) { continue; } echo "Downloading test file {$u}\n"; WPFB_Download::SideloadFile($u, $fn); } }
static function AdminBar() { global $wp_admin_bar; WPFB_Core::PrintJS(); $wp_admin_bar->add_menu(array('id' => WPFB, 'title' => WPFB_PLUGIN_NAME, 'href' => admin_url('admin.php?page=wpfilebase_manage'))); $wp_admin_bar->add_menu(array('parent' => WPFB, 'id' => WPFB . '-add-file', 'title' => __('Add File', 'wp-filebase'), 'href' => admin_url('admin.php?page=wpfilebase_files#addfile'))); $current_object = get_queried_object(); $is_filebrowser = false; if (!empty($current_object) && !empty($current_object->post_type) && $current_object->ID > 0) { $is_filebrowser = $current_object->ID == WPFB_Core::$settings->file_browser_post_id; $link = esc_attr(admin_url('?wpfilebase-screen=editor-plugin&manage_attachments=1&post_id=' . $current_object->ID)); $wp_admin_bar->add_menu(array('parent' => WPFB, 'id' => WPFB . '-attachments', 'title' => __('Manage attachments', 'wp-filebase'), 'href' => $link, 'meta' => array('onclick' => 'window.open("' . $link . '", "wpfb-manage-attachments", "width=680,height=400,menubar=no,location=no,resizable=no,status=no,toolbar=no,scrollbars=yes");return false;'))); } $wp_admin_bar->add_menu(array('parent' => WPFB, 'id' => WPFB . '-add-file', 'title' => __('Sync Filebase', 'wp-filebase'), 'href' => admin_url('admin.php?page=wpfilebase_manage&action=sync'))); $wp_admin_bar->add_menu(array('parent' => WPFB, 'id' => WPFB . '-toggle-context-menu', 'title' => !empty(WPFB_Core::$settings->file_context_menu) ? __('Disable file context menu', 'wp-filebase') : __('Enable file context menu', 'wp-filebase'), 'href' => 'javascript:;', 'meta' => array('onclick' => 'return wpfb_toggleContextMenu();'))); if ($is_filebrowser) { $wp_admin_bar->add_menu(array('parent' => WPFB, 'id' => WPFB . '-toggle-drag-drop', 'title' => get_user_option('wpfb_set_fbdd') ? __('Disable file browser Drag & Drop', 'wp-filebase') : __('Enable file browser Drag & Drop', 'wp-filebase'), 'href' => 'javascript:;', 'meta' => array('onclick' => 'jQuery.ajax({url:wpfbConf.ajurl,type:"POST",data:{wpfb_action:"set-user-setting",name:"fbdd",value:' . (get_user_option('wpfb_set_fbdd') ? 0 : 1) . '},async:false});location.reload();return false;'))); } }
static function Display() { wpfb_loadclass('Output', 'File', 'Category', 'TplLib'); $content = ''; $file_tpls = WPFB_Core::GetTpls('file'); $cat_tpls = WPFB_Core::GetTpls('cat'); if (true || !isset($file_tpls['filebrowser_admin'])) { $file_tpls['filebrowser_admin'] = '%file_small_icon% ' . '%file_display_name% (%file_size%) ' . '<!-- IF %file_user_can_edit% --><a href="%file_edit_url%" class="edit" onclick="wpfbFBEditFile(event)">%\'Edit\'%</a><!-- ENDIF -->'; WPFB_Core::SetFileTpls($file_tpls); //WPFB_Admin::ParseTpls(); } if (true || !isset($cat_tpls['filebrowser_admin'])) { $cat_tpls['filebrowser_admin'] = '<span class="cat-icon" style="background-image:url(\'%cat_icon_url%\');"><span class="cat-icon-overlay"></span></span>' . '%cat_name% ' . '<!-- IF %cat_user_can_edit% --><a href="%cat_edit_url%" class="edit" onclick="wpfbFBEditCat(event)">%\'Edit\'%</a><!-- ENDIF -->'; WPFB_Core::SetCatTpls($cat_tpls); WPFB_Admin::ParseTpls(); } WPFB_Output::FileBrowser($content, 0, empty($_GET['wpfb_cat']) ? 0 : intval($_GET['wpfb_cat'])); WPFB_Core::PrintJS(); ?> <div class="wrap filebrowser-admin"> <h2><?php _e('File Browser', WPFB); ?> </h2> <?php echo '<div>' . __('You can Drag & Drop (multiple) files directly on Categories to upload them. Dragging a category or an existing file to another category is also possible.', WPFB) . '</div>'; echo $content; ?> </div> <script> function wpfbFBEditCat(e) { e.stopPropagation(); } function wpfbFBEditFile(e) { e.stopPropagation(); } </script> <?php }
function GetIconUrl($size = null) { // todo: remove file operations! if ($this->is_category) { // add mtime for cache updates return empty($this->cat_icon) ? WP_CONTENT_URL . WPFB_Core::$settings->folder_icon : WPFB_Core::PluginUrl("wp-filebase_thumb.php?cid={$this->cat_id}&t=" . @filemtime($this->GetThumbPath())); } if (!empty($this->file_thumbnail)) { return WPFB_Core::PluginUrl('wp-filebase_thumb.php?fid=' . $this->file_id . '&name=' . $this->file_thumbnail); // name var only for correct caching! } $type = $this->GetType(); $ext = substr($this->GetExtension(), 1); $img_path = ABSPATH . WPINC . '/images/'; $img_url = get_option('siteurl') . '/' . WPINC . '/images/'; $custom_folder = '/images/fileicons/'; // check for custom icons if (file_exists(WP_CONTENT_DIR . $custom_folder . $ext . '.png')) { return WP_CONTENT_URL . $custom_folder . $ext . '.png'; } if (file_exists(WP_CONTENT_DIR . $custom_folder . $type . '.png')) { return WP_CONTENT_URL . $custom_folder . $type . '.png'; } // todo: cache file_exists if (file_exists($img_path . 'crystal/' . $ext . '.png')) { return $img_url . 'crystal/' . $ext . '.png'; } if (file_exists($img_path . 'crystal/' . $type . '.png')) { return $img_url . 'crystal/' . $type . '.png'; } if (file_exists($img_path . $ext . '.png')) { return $img_url . $ext . '.png'; } if (file_exists($img_path . $type . '.png')) { return $img_url . $type . '.png'; } // fallback to default if (file_exists($img_path . 'crystal/default.png')) { return $img_url . 'crystal/default.png'; } if (file_exists($img_path . 'default.png')) { return $img_url . 'default.png'; } // fallback to blank :( return $img_url . 'blank.gif'; }
if (($n = count($tags)) > 0) { $ks = array_keys($tags); for ($i = 0; $i < $n; $i++) { if (stripos($ks[$i], $tag) === 0) { while ($i < $n && stripos($ks[$i], $tag) === 0) { $props[] = array('t' => $ks[$i], 'n' => $tags[$ks[$i]]); $i++; } //break; } } } wpfb_print_json($props); exit; case 'new-cat': if (!WPFB_Core::CurUserCanCreateCat()) { die('-1'); } wpfb_loadclass('Admin'); $result = WPFB_Admin::InsertCategory($_POST); if (isset($result['error']) && $result['error']) { wpfb_print_json(array('error' => $result['error'])); exit; } $cat = $result['cat']; $args = WPFB_Output::fileBrowserArgs($_POST['args']); $filesel = $args['type'] === 'fileselect'; $catsel = $args['type'] === 'catselect'; wpfb_print_json(array('error' => 0, 'id' => $cat->GetId(), 'name' => $cat->GetTitle(), 'id_str' => $args['idp'] . 'cat-' . $cat->cat_id, 'url' => $cat->GetUrl(), 'text' => WPFB_Output::fileBrowserCatItemText($catsel, $filesel, $cat, $args['onselect'], empty($_REQUEST['is_admin']) ? 'filebrowser' : 'filebrowser_admin'), 'classes' => $filesel || $catsel ? 'folder' : null)); exit; case 'change-category':
<body class="single single-post"> <div id="page" class="site"> <div id="main" class="wrapper"> <div id="primary" class="site-content"> <div id="content" role="main"> <div class="entry-content"> <?php if ($list) { $tpl = WPFB_ListTpl::Get($tag); if (is_null($tpl)) { exit; } echo do_shortcode($tpl->Sample(WPFB_AdminGuiTpls::$sample_cat, WPFB_AdminGuiTpls::$sample_file)); } else { $tpl_src = WPFB_Core::GetTpls($type, $tag); if (!is_string($tpl_src) || empty($tpl_src)) { exit; } $table_found = strpos($tpl_src, '<table') !== false; if (!$list && !$table_found && strpos($tpl_src, '<tr') !== false) { $tpl_src = "<table>{$tpl_src}</table>"; } $item = $type == 'cat' ? WPFB_AdminGuiTpls::$sample_cat : WPFB_AdminGuiTpls::$sample_file; echo do_shortcode($item->GenTpl(WPFB_TplLib::Parse($tpl_src), 'sample')); } ?> </div> </div> </div> </div>
static function Chmod($base_dir, $files) { $result = array(); $upload_dir = self::cleanPath(WPFB_Core::UploadDir()); $upload_dir_len = strlen($upload_dir); // chmod if (is_writable($upload_dir)) { @chmod($upload_dir, octdec(WPFB_PERM_DIR)); } for ($i = 0; $i < count($files); $i++) { $f = "{$base_dir}/" . $files[$i]; if (file_exists($f)) { @chmod($f, octdec(WPFB_PERM_FILE)); if (!is_writable($f) && !is_writable(dirname($f))) { $result[] = sprintf(__('File <b>%s</b> is not writable!', WPFB), substr($f, $upload_dir_len)); } } } return $result; }
function PrintScripts($prefix = '', $auto_submit = false) { $this->Scripts($prefix); $minify = true; if ($minify) { ob_start(); } ?> <script type="text/javascript"> /* <![CDATA[ */ function fileQueued(fileObj) { jQuery('#file-upload-progress').show().html('<div class="progress"><div class="percent">0%</div><div class="bar" style="width: 30px"></div></div><div class="filename original"> ' + fileObj.name + '</div>'); jQuery('.progress', '#file-upload-progress').show(); jQuery('.filename', '#file-upload-progress').show(); jQuery("#media-upload-error").empty(); jQuery('.upload-flash-bypass').hide(); jQuery('#file-submit').prop('disabled', true); jQuery('#cancel-upload').show().prop('disabled', false); /* delete already uploaded temp file */ if(jQuery('#file_flash_upload').val() != '0') { jQuery.ajax({type: 'POST', async: true, url:"<?php echo esc_attr(WPFB_Core::PluginUrl('wpfb-async-upload.php')); ?> ", data: {<?php echo $this->GetAjaxAuthData(true); ?> , "delupload": jQuery('#file_flash_upload').val()}, success: (function(data){}) }); jQuery('#file_flash_upload').val(0); } } function wpFileError(fileObj, message) { jQuery('#media-upload-error').show().html(message); jQuery('.upload-flash-bypass').show(); jQuery("#file-upload-progress").hide().empty(); jQuery('#cancel-upload').hide().prop('disabled', true); } function uploadError(fileObj, errorCode, message, uploader) { wpFileError(fileObj, "Error "+errorCode+": "+message); } function uploadSuccess(fileObj, serverData) { /* if async-upload returned an error message, place it in the media item div and return */ if ( serverData.match('media-upload-error') || serverData.match('error-div') ) { wpFileError(fileObj, serverData); return; } var file_obj = jQuery.parseJSON(serverData); if(file_obj && 'undefined' != typeof(file_obj.file_id)) { jQuery('#file_form_action').val("updatefile"); jQuery('#file_id').val(file_obj.file_id); if(file_obj.file_thumbnail) { jQuery('#file_thumbnail_wrap').show(); jQuery('#file_thumbnail_wrap').children('img').attr('src', file_obj.file_thumbnail_url); jQuery('#file_thumbnail_name').html(file_obj.file_thumbnail); } else { jQuery('#file_thumbnail_wrap').hide(); } jQuery('#file_display_name').val(file_obj.file_display_name); jQuery('#file_version').val(file_obj.file_version); jQuery('#wpfb-file-nonce').val(file_obj.nonce); } else { jQuery('#file_flash_upload').val(serverData); } jQuery('#file-submit').prop('disabled', false); <?php if ($auto_submit) { ?> jQuery('#file_flash_upload').closest("form").submit(); <?php } ?> } function uploadComplete(fileObj) { jQuery('#cancel-upload').hide().prop('disabled', true); } /* ]]> */ </script> <?php if ($minify) { // todo: remove // comments!! echo str_replace(array(" /* <![CDATA[ */ ", " /* ]]> */ "), array("\r\n/* <![CDATA[ */\r\n", "\r\n/* ]]> */\r\n"), str_replace(array("\r\n", "\n"), " ", ob_get_clean())); } }
// ############# THIS FILE IS DEPRECATED!! ############ // ########################################################## // ########################################################## // ob_start(); define('WPFB_NO_CORE_INIT', true); define('WP_INSTALLING', true); // make wp load faster if (empty($_GET['rp'])) { // if rel path not set, need to load whole WP stuff to get to path to custom CSS! require_once dirname(__FILE__) . '/../../../cms/wp-load.php'; } require_once dirname(__FILE__) . '/wp-filebase.php'; // this only loads some wp-filebase stuff, NOT WP! wpfb_loadclass('Core'); WPFB_Core::InitDirectScriptAccess(); $file = WPFB_Core::GetOldCustomCssPath(stripslashes(@$_GET['rp'])); //echo $file; //@ob_end_clean(); if (empty($file) || !@file_exists($file) || !@is_writable($file)) { // TODO: remove writable check? this is for security! $file = WPFB_PLUGIN_ROOT . 'wp-filebase.css'; } $ftime = filemtime($file); header("Content-Type: text/css"); header("Cache-Control: max-age=3600"); header("Last-Modified: " . gmdate("D, d M Y H:i:s", $ftime) . " GMT"); header("Content-Length: " . filesize($file)); if (!empty($_SERVER['HTTP_IF_MODIFIED_SINCE']) && @strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $ftime) { header("HTTP/1.x 304 Not Modified"); exit; }
static function OnDeactivate() { wp_clear_scheduled_hook(WPFB . '_cron'); self::UnProtectUploadPath(); $sync_data_file = WPFB_Core::UploadDir() . '/._sync.data'; is_file($sync_data_file) && unlink($sync_data_file); //delete_option('wpfilebase_dismiss_support_ending'); delete_option('wpfb_license_nag'); if (get_option('wpfb_uninstall')) { self::RemoveOptions(); self::DropDBTables(); self::RemoveTpls(); delete_option('wpfilebase_cron_sync_time'); delete_option('wpfilebase_cron_sync_stats'); delete_option('wpfb_license_key'); delete_option('wpfilebase_last_check'); delete_option('wpfilebase_forms'); delete_option('wpfilebase_ftags'); delete_option('wpfilebase_rsyncs'); delete_option('wpfb_uninstall'); delete_option('wpfilebase_dismiss_support_ending'); } }
static function FileSortFields() { return array_merge(array('file_display_name' => __('Title', WPFB), 'file_name' => __('Name of the file', WPFB), 'file_version' => __('File version', WPFB), 'file_hits' => __('How many times this file has been downloaded.', WPFB), 'file_size' => __('Formatted file size', WPFB), 'file_date' => __('Formatted file date', WPFB), 'file_last_dl_time' => __('Time of the last download', WPFB), 'file_path' => __('Relative path of the file'), 'file_id' => __('File ID'), 'file_category_name' => __('Category Name', WPFB), 'file_category' => __('Category ID', WPFB), 'file_description' => __('Short description', WPFB), 'file_author' => __('Author', WPFB), 'file_license' => __('License', WPFB), 'file_post_id' => __('ID of the post/page this file belongs to', WPFB), 'file_added_by' => __('User Name of the owner', WPFB)), WPFB_Core::GetCustomFields(true)); }
*/ if (defined('WP_ADMIN') && WP_ADMIN) { require_once ABSPATH . 'wp-admin/admin.php'; } else { if (!function_exists('get_current_screen')) { function get_current_screen() { return null; } } if (!function_exists('add_meta_box')) { function add_meta_box() { return null; } } } if (SUPPRESS_LOADING_OUTPUT) { //@ob_flush(); @flush(); // restore ob_level while (@ob_get_level() > WPFB_OB_LEVEL_PL && @ob_end_clean()) { } // destroy all ob buffers } if (defined('WP_INSTALLING') && WP_INSTALLING) { require_once dirname(__FILE__) . '/wp-filebase.php'; // load wp-filebase only, no other plugins wpfb_loadclass('Core'); } WPFB_Core::InitDirectScriptAccess();
function widget($args, $instance) { wpfb_loadclass('File', 'Category', 'Output'); extract($args); $title = apply_filters('widget_title', $instance['title']); echo $before_widget, $before_title . (empty($title) ? __('Files', WPFB) : $title) . $after_title; // special handling for empty cats if (!empty($instance['cat']) && !is_null($cat = WPFB_Category::GetCat($instance['cat'])) && $cat->cat_num_files == 0) { $instance['cat'] = array(); foreach ($cat->GetChildCats() as $c) { $instance['cat'][] = $c->cat_id; } } $files = WPFB_File::GetFiles2(empty($instance['cat']) ? null : WPFB_File::GetSqlCatWhereStr($instance['cat']), WPFB_Core::$settings->hide_inaccessible, array($instance['sort-by'] => $instance['sort-asc'] ? 'ASC' : 'DESC'), (int) $instance['limit']); //$instance['tpl_parsed'] //WPFB_FileListWidget $tpl_func = WPFB_Core::CreateTplFunc($instance['tpl_parsed']); echo '<ul>'; foreach ($files as $file) { echo '<li>', $tpl_func($file), '</li>'; } echo '</ul>'; echo $after_widget; }
</div> </td> <th scope="row" valign="top"></th> <td><input type="checkbox" name="file_offline" id="file_offline" value="1" <?php checked('1', $file->file_offline); ?> /> <label for="file_offline"><?php _e('Offline', WPFB); ?> </label></td> </tr> <?php } $custom_fields = WPFB_Core::GetCustomFields(false, $custom_defaults); foreach ($custom_fields as $ct => $cn) { $hid = 'file_custom_' . esc_attr($ct); ?> <tr class="form-field"> <th scope="row" valign="top"><label for="<?php echo $hid; ?> "><?php echo esc_html($cn); ?> </label></th> <td colspan="3"><textarea name="<?php echo $hid; ?> " id="<?php
static function ParseQuery(&$query) { // conditional loading of the search hooks global $wp_query; if (!empty($wp_query->query_vars['s'])) { wpfb_loadclass('Search'); } if (!empty($_GET['wpfb_s']) || !empty($_GET['s'])) { WPFB_Core::$file_browser_search = true; add_filter('the_excerpt', array(__CLASS__, 'SearchExcerptFilter'), 100); // must be lower than 11 (before do_shortcode) and after wpautop (>9) } // check if current post is file browser if (($id = self::GetPostId($query)) == WPFB_Core::$settings->file_browser_post_id) { wpfb_loadclass('File', 'Category'); if (!empty($_GET['wpfb_file'])) { self::$file_browser_item = WPFB_File::GetFile($_GET['wpfb_file']); } elseif (!empty($_GET['wpfb_cat'])) { self::$file_browser_item = WPFB_Category::GetCat($_GET['wpfb_cat']); } else { $url = (is_ssl() ? 'https' : 'http') . '://' . $_SERVER["HTTP_HOST"] . stripslashes($_SERVER['REQUEST_URI']); if (($qs = strpos($url, '?')) !== false) { $url = substr($url, 0, $qs); } // remove query string $path = trim(substr($url, strlen(WPFB_Core::GetPostUrl($id))), '/'); if (!empty($path)) { self::$file_browser_item = WPFB_Item::GetByPath(urldecode($path)); if (is_null(self::$file_browser_item)) { self::$file_browser_item = WPFB_Item::GetByPath($path); } } } } }
static function AdminDashboardSetup() { if (WPFB_Core::CurUserCanUpload()) { wp_add_dashboard_widget('wpfb-add-file-widget', WPFB_PLUGIN_NAME . ': ' . __('Add File', WPFB), wpfb_callback('Admin', 'AddFileWidget')); } }
static function PostsSearch($sql) { global $wp_query, $wpdb; if (empty($sql)) { return $sql; } wpfb_loadclass('File'); $is_wp_search = !empty($_GET['s']) && empty($_GET['wpfb_s']); $search_id3 = WPFB_Core::$settings->search_id3; $no_matches = false; $where = self::SearchWhereSql($search_id3); $where = "({$where} AND (" . WPFB_File::GetReadPermsWhere() . "))"; // check if there are matching files, if there are, include the filebrowser page/post in the resulst! // if we have file pages, only include the file browser if file search widget was used! $file_browser_id = intval(WPFB_Core::$settings->file_browser_post_id); if ($file_browser_id > 0 && WPFB_File::GetNumFiles2($where, true) > 0) { $where = "({$where} OR ({$wpdb->posts}.ID = {$file_browser_id}))"; // TODO! wpfb_loadclass('Output'); WPFB_Core::$file_browser_search = true; } // OR' the $where to existing search conditions $p = strpos($sql, "("); $sql = substr($sql, 0, $p) . "( " . substr($sql, $p); $p = strrpos($sql, ")))"); $sql = substr($sql, 0, $p + 3) . " OR {$where})" . substr($sql, $p + 3); //echo "<br>".$sql; return $sql; }
function prepare_items() { global $wpdb; $columns = $this->get_columns(); $hidden = array(); $sortable = $this->get_sortable_columns(); $this->_column_headers = array($columns, $hidden, $sortable); $this->process_bulk_action(); $pagenum = $this->get_pagenum(); if (!isset($filesperpage) || $filesperpage < 0) { $filesperpage = 50; } $pagestart = ($pagenum - 1) * $filesperpage; $where = $this->get_file_where_cond(empty($_REQUEST['view']) ? null : $_REQUEST['view']); $order = "{$wpdb->wpfilebase_files}." . (!empty($_REQUEST['orderby']) && in_array($_REQUEST['orderby'], array_merge(array_keys(get_class_vars('WPFB_File')), array_keys(WPFB_Core::GetCustomFields(true)))) ? $_REQUEST['orderby'] . " " . (!empty($_REQUEST['order']) && $_REQUEST['order'] == "desc" ? "DESC" : "ASC") : "file_id DESC"); $total_items = WPFB_File::GetNumFiles2($where, 'edit'); $files = WPFB_File::GetFiles2($where, 'edit', $order, $filesperpage, $pagestart); if (empty($files) && !empty($wpdb->last_error)) { wp_die("<b>Database error</b>: " . $wpdb->last_error); } $this->items = $files; $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $filesperpage, 'total_pages' => ceil($total_items / $filesperpage))); }
public function Display() { WPFB_Core::PrintJS(); wp_print_scripts('utils'); // setUserSetting ?> <style type="text/css" media="screen">@import url(<?php echo WPFB_PLUGIN_URI . 'css/batch-uploader.css'; ?> );</style> <div id="<?php echo $this->prefix; ?> -uploader-wrap"> <div id="<?php echo $this->prefix; ?> -uploader-interface" class="wpfb-batch-uploader-interface"> <div class="form-wrap uploader-presets" id="<?php echo $this->prefix; ?> -uploader-presets"> <form method="POST" action="" class="validate" name="batch_presets"> <h2><?php _e('Upload Presets', 'wp-filebase'); ?> </h2> <?php self::DisplayUploadPresets($this->prefix); //wp_nonce_field('batch-presets'); // TODO validate this! ?> </form> </div> <div id="<?php echo $this->prefix; ?> -drag-drop-uploader" class="drag-drop-uploader"> <h2>Drag & Drop</h2> <div id="<?php echo $this->prefix; ?> -drag-drop-area" class="drag-drop-area"> <div style="margin: 70px auto 0;"> <p class="drag-drop-info"><?php _e('Drop files here'); ?> </p> <p><?php _ex('or', 'Uploader: Drop files here - or - Select Files'); ?> </p> <p class="drag-drop-buttons"><input id="<?php echo $this->prefix; ?> -browse-button" type="button" value="<?php esc_attr_e('Select Files'); ?> " class="button" /></p> </div> </div> <div id="<?php echo $this->prefix; ?> -uploader-errors"></div> </div> <div style="clear: both;"></div> </div> <div id="<?php echo $this->prefix; ?> -uploader-files" style="position:relative;"></div> </div> <?php wp_print_scripts('jquery-color'); wp_print_scripts('jquery-deserialize'); ?> <script type="text/javascript"> var mouseDragPos = []; var presetData = ''; var morePresets = 0; jQuery(document).ready( function() { var form = jQuery('#<?php echo $this->prefix; ?> -uploader-presets').find('form'); jQuery('#<?php echo $this->prefix; ?> -drag-drop-area').bind('dragover', function(e){ mouseDragPos = [e.originalEvent.pageX, e.originalEvent.pageY]; }); <?php ?> wpfb_setupFormAutoSave(form,'batch_presets'); <?php ?> // "more" toggle init form.find('tr.more').hide(); form.find('tr.more-more').hide(); morePresets = 0; jQuery('#<?php echo $this->prefix; ?> -uploader-presets-more-toggle').click(function() { var pm = morePresets; pm++; pm %= 3; batchUploaderSetPresetsMore(pm); }); batchUploaderSetPresetsMore(typeof(getUserSetting) !== 'function' || getUserSetting('wpfb_batch_presets_more') || 0); }); function batchUploaderSetPresetsMore(m) { if(isNaN(m)) m = 0; var form = jQuery('#<?php echo $this->prefix; ?> -uploader-presets').find('form'); var s = (m+morePresets); if( s==1||s==2 ) form.find('tr.more').toggle(400); if( m==2||morePresets==2) form.find('tr.more-more').toggle(400); morePresets = m; // TODO show any field with non-default value!! //form.find('tr.more').toggle(morePresets > 0); //form.find('tr.more-more').toggle(morePresets > 1); if(typeof(setUserSetting) !== 'undefined') setUserSetting('wpfb_batch_presets_more',''+morePresets); jQuery('#<?php echo $this->prefix; ?> -uploader-presets-more-toggle td span').html(m==2?'<?php _e('less'); ?> ':'<?php _e('more'); ?> '); } function batchUploaderFilesQueued(up, files) { var form = jQuery('#<?php echo $this->prefix; ?> -uploader-presets').find('form'); up.settings.multipart_params["presets"] = form.serialize(); var hidden_params = form.find('input[type=hidden]').serializeArray(); for (var i = 0; i < hidden_params.length; ++i) { up.settings.multipart_params[hidden_params[i].name] = hidden_params[i].value; } form .css({ background: "rgba(255,255,0,0.0)" }) .animate({ backgroundColor: "rgba(255,255,0,0.5)"}, 100) .animate({ backgroundColor: "rgba(255,255,0,0.0)"}, 400); form.find('input,textarea,select') .animate({ opacity: 0.2}, 100) .animate({ opacity: 1.0}, 400); form.find("input[name='file_display_name']").val(''); } function batchUploaderFileQueued(up, file) { //file.name, file.size jQuery('#<?php echo $this->prefix; ?> -uploader-files').prepend('<div id="<?php echo $this->prefix; ?> -uploader-file-'+file.id+'-spacer" class="batch-uploader-file-spacer"></div>'); jQuery('#<?php echo $this->prefix; ?> -uploader-files').prepend('<div id="'+file.dom_id+'" class="media-item batch-uploader-file">'+ '<div class="progress"><div class="percent">0%</div><div class="bar"></div></div>'+ '<img src="<?php echo site_url(WPINC . '/images/crystal/default.png'); ?> " alt="Loading..." /><span class="filename">'+file.name+'</span><span class="error"></span></div>'); var fileEl = jQuery('#'+file.dom_id); var spacerEl = jQuery('#<?php echo $this->prefix; ?> -uploader-file-'+file.id+'-spacer'); var dest = fileEl.offset(); var ppos = fileEl.parent().offset(); var destWidth = fileEl.width(); fileEl.css({position:'absolute', zIndex:100, top:mouseDragPos[1]-ppos.top, left:mouseDragPos[0]-ppos.left-15}); fileEl.animate({ //opacity: 0.25, left: dest.left-ppos.left, top: dest.top-ppos.top }, 400, function() { spacerEl.remove(); var startWidth = jQuery(this).width(); jQuery(this) .css({position:'',top:0,left:0,width:startWidth}) .animate({width: destWidth}, 200); }); spacerEl.animate({height: fileEl.outerHeight(true)}, 400); jQuery('.error', fileEl).hide(); } function batchUploaderSuccess(file, serverData) { var item = jQuery('#'+file.dom_id); if(!serverData || serverData == -1 || 'object' != typeof(serverData)) { jQuery('.error', item).show().html('Server response error! '+serverData); console.log(serverData); return; } var url = serverData.file_cur_user_can_edit ? serverData.file_edit_url : serverData.file_download_url; jQuery('.filename', item).html('<a href="'+url+'" target="_blank">'+serverData.file_display_name+'</a> <span class="ok"><?php _e('Upload OK!', 'wp-filebase'); ?> </span>'); jQuery('img', item).attr('src', serverData.file_thumbnail_url); } </script> <?php wpfb_loadclass('PLUploader'); $uploader = new WPFB_PLUploader(); $uploader->js_file_queued = 'batchUploaderFileQueued'; $uploader->js_files_queued = 'batchUploaderFilesQueued'; $uploader->js_upload_success = 'batchUploaderSuccess'; $uploader->post_params['file_add_now'] = true; if (!empty($this->hidden_vars)) { $uploader->post_params = array_merge($uploader->post_params, $this->hidden_vars); } $uploader->Init($this->prefix . '-drag-drop-area', $this->prefix . '-browse-button', $this->prefix . '-uploader-errors'); }
function GenerateList(&$content, $categories, $list_args = null) { if (!empty($list_args)) { $this->current_list = (object) $list_args; unset($list_args); } $hia = WPFB_Core::$settings->hide_inaccessible; $sort = WPFB_Core::GetSortSql($this->current_list->file_order); if ($this->current_list->page_limit > 0) { // pagination $page = empty($_REQUEST['wpfb_list_page']) || $_REQUEST['wpfb_list_page'] < 1 ? 1 : intval($_REQUEST['wpfb_list_page']); $start = $this->current_list->page_limit * ($page - 1); } else { $start = -1; } $search_term = empty($_GET['wpfb_s']) ? null : stripslashes($_GET['wpfb_s']); if ($search_term || WPFB_Core::$file_browser_search) { // search wpfb_loadclass('Search'); $where = WPFB_Search::SearchWhereSql(WPFB_Core::$settings->search_id3, $search_term); } else { $where = '1=1'; } $num_total_files = 0; if (is_null($categories)) { // if null, just list all files! $files = WPFB_File::GetFiles2($where, $hia, $sort, $this->current_list->page_limit, $start); $num_total_files = WPFB_File::GetNumFiles2($where, $hia); foreach ($files as $file) { $content .= $file->GenTpl2($this->file_tpl_tag); } } else { if (!empty($this->current_list->cat_order)) { WPFB_Item::Sort($categories, $this->current_list->cat_order); } $cat = reset($categories); // get first category // here we check if single category and cat has at least one file (also secondary cat files!) if (count($categories) == 1 && $cat->cat_num_files > 0) { // single cat if (!$cat->CurUserCanAccess()) { return ''; } $where = "({$where}) AND " . WPFB_File::GetSqlCatWhereStr($cat->cat_id); $files = WPFB_File::GetFiles2($where, $hia, $sort, $this->current_list->page_limit, $start); $num_total_files = WPFB_File::GetNumFiles2($where, $hia); if ($this->current_list->cat_grouping && $num_total_files > 0) { $content .= $cat->GenTpl2($this->cat_tpl_tag); } foreach ($files as $file) { $content .= $file->GenTpl2($this->file_tpl_tag); } } else { // multi-cat // TODO: multi-cat list pagination does not work properly yet // special handling of categories that do not have files directly: list child cats! if (count($categories) == 1 && $cat->cat_num_files == 0) { $categories = $cat->GetChildCats(true, true); if (!empty($this->current_list->cat_order)) { WPFB_Item::Sort($categories, $this->current_list->cat_order); } } if ($this->current_list->cat_grouping) { // group by categories $n = 0; foreach ($categories as $cat) { if (!$cat->CurUserCanAccess()) { continue; } $num_total_files = max($nf = WPFB_File::GetNumFiles2("({$where}) AND " . WPFB_File::GetSqlCatWhereStr($cat->cat_id), $hia), $num_total_files); // TODO //if($n > $this->current_list->page_limit) break; // TODO!! if ($nf > 0) { $files = WPFB_File::GetFiles2("({$where}) AND " . WPFB_File::GetSqlCatWhereStr($cat->cat_id), $hia, $sort, $this->current_list->page_limit, $start); if (count($files) > 0) { $content .= $cat->GenTpl2($this->cat_tpl_tag); // check for file count again, due to pagination! foreach ($files as $file) { $content .= $file->GenTpl2($this->file_tpl_tag); } } } } } else { // this is not very efficient, because all files are loaded, no pagination! $all_files = array(); foreach ($categories as $cat) { if (!$cat->CurUserCanAccess()) { continue; } $all_files += WPFB_File::GetFiles2("({$where}) AND " . WPFB_File::GetSqlCatWhereStr($cat->cat_id), $hia, $sort); } $num_total_files = count($all_files); WPFB_Item::Sort($all_files, $sort); $keys = array_keys($all_files); if ($start == -1) { $start = 0; } $last = $this->current_list->page_limit > 0 ? min($start + $this->current_list->page_limit, $num_total_files) : $num_total_files; for ($i = $start; $i < $last; $i++) { $content .= $all_files[$keys[$i]]->GenTpl2($this->file_tpl_tag); } } } } return $num_total_files; }
function Display() { global $is_IE, $is_opera; $id = $this->id; $upload_size_unit = $max_upload_size = WPFB_Core::GetMaxUlSize(); $sizes = array('KB', 'MB', 'GB'); for ($u = -1; $upload_size_unit > 1024 && $u < count($sizes) - 1; $u++) { $upload_size_unit /= 1024; } if ($u < 0) { $upload_size_unit = 0; $u = 0; } else { $upload_size_unit = (int) $upload_size_unit; } do_action('pre-upload-ui'); $plupload_init = array('runtimes' => 'html5,silverlight,flash,html4', 'browse_button' => 'plupload-browse-button', 'container' => 'plupload-upload-ui', 'drop_element' => 'drag-drop-area', 'file_data_name' => 'async-upload', 'multiple_queues' => false, 'max_file_size' => $max_upload_size . 'b', 'url' => add_query_arg('wpfb_action', 'upload', WPFB_Core::$ajax_url_public), 'flash_swf_url' => includes_url('js/plupload/plupload.flash.swf'), 'silverlight_xap_url' => includes_url('js/plupload/plupload.silverlight.xap'), 'filters' => array(array('title' => __('Allowed Files'), 'extensions' => '*')), 'multipart' => true, 'urlstream_upload' => true, 'multipart_params' => $this->GetAjaxAuthData()); $plupload_init = apply_filters('plupload_init', $plupload_init); ?> <script type="text/javascript"> var resize_height = 1024, resize_width = 1024, // this is for img resizing (not used here!) wpUploaderInit = <?php echo json_encode($plupload_init); ?> ; </script> <input type="hidden" id="file_flash_upload" name="file_flash_upload" value="0" /> <div id="plupload-upload-ui" class="hide-if-no-js"> <?php do_action('pre-plupload-upload-ui'); // hook change, old name: 'pre-flash-upload-ui' ?> <div id="drag-drop-area"> <div class="drag-drop-inside"> <p class="drag-drop-info"><?php _e('Drop files here - or -', 'wp-filebase'); ?> </p> <div class="drag-drop-buttons"><input id="plupload-browse-button" type="button" value="<?php esc_attr_e('Select Files'); ?> " class="button" /></div> <div class="drag-drop-info-spacer"></div> </div> </div> <p class="upload-flash-bypass"> <?php printf(__('You are using the multi-file uploader. Problems? Try the <a href="%1$s">browser uploader</a> instead.'), esc_url(add_query_arg('flash', 0))); ?> </p> </div> <?php if (($is_IE || $is_opera) && $max_upload_size > 100 * 1024 * 1024) { ?> <span class="big-file-warning"><?php _e('Your browser has some limitations uploading large files with the multi-file uploader. Please use the browser uploader for files over 100MB.'); ?> </span> <?php } ?> <div id="media-upload-error"></div> <div id="file-upload-progress" class="media-item" style="width: auto;"></div> <?php //do_action('post-upload-ui'); }
</div> <!-- attach --> <?php if (!$manage_attachments) { ?> <form id="filetplselect" class="insert"> <h2><?php _e('Select Template', 'wp-filebase'); ?> </h2> <label><input type="radio" name="filetpl" value="" checked="checked" /><i><?php _e('Default Template', 'wp-filebase'); ?> </i></label><br /> <?php $tpls = WPFB_Core::GetFileTpls(); if (!empty($tpls)) { foreach ($tpls as $tpl_tag => $tpl_src) { echo '<label><input type="radio" name="filetpl" value="' . esc_attr($tpl_tag) . '" />' . esc_html($tpl_tag) . '</label><br />'; } } ?> <i><a href="<?php echo admin_url('admin.php?page=wpfilebase_tpls#file'); ?> " target="_parent"><?php _e('Add Template', 'wp-filebase'); ?> </a></i> </form> <div id="fileselect" class="container">
function GetThumbPath($refresh = false) { static $base_dir = ''; if (empty($base_dir) || $refresh) { $base_dir = (empty(WPFB_Core::$settings->thumbnail_path) ? WPFB_Core::UploadDir() : path_join(ABSPATH, WPFB_Core::$settings->thumbnail_path)) . '/'; } if ($this->is_file) { if (empty($this->file_thumbnail)) { return null; } return dirname($base_dir . $this->GetLocalPathRel()) . '/' . $this->file_thumbnail; } else { if (empty($this->cat_icon)) { return null; } return $base_dir . $this->GetLocalPathRel() . '/' . $this->cat_icon; } }
static function Display() { global $wpdb, $user_ID; wpfb_loadclass('File', 'Category', 'Admin', 'Output'); $_POST = stripslashes_deep($_POST); $_GET = stripslashes_deep($_GET); $action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : ''; $clean_uri = remove_query_arg(array('message', 'action', 'file_id', 'cat_id', 'deltpl', 'hash_sync')); // keep search keyword // nonce/referer check (security) if ($action == 'updatefile' || $action == 'addfile') { $nonce_action = WPFB . "-" . $action; if ($action == 'updatefile') { $nonce_action .= $_POST['file_id']; } if (!check_admin_referer($nonce_action, 'wpfb-file-nonce')) { wp_die(__('Cheatin’ uh?')); } } // switch simple/extended form if (isset($_GET['exform'])) { $exform = !empty($_GET['exform']) && $_GET['exform'] == 1; update_user_option($user_ID, WPFB_OPT_NAME . '_exform', $exform, true); } else { $exform = (bool) get_user_option(WPFB_OPT_NAME . '_exform'); } ?> <div class="wrap"> <?php switch ($action) { case 'editfile': if (!current_user_can('upload_files')) { wp_die(__('Cheatin’ uh?')); } if (!empty($_POST['files'])) { if (!is_array($_POST['files'])) { $_POST['files'] = explode(',', $_POST['files']); } $files = array(); foreach ($_POST['files'] as $file_id) { $file = WPFB_File::GetFile($file_id); if (!is_null($file) && $file->CurUserCanEdit()) { $files[] = $file; } } if (count($files) > 0) { WPFB_Admin::PrintForm('file', $files, array('multi_edit' => true)); } else { wp_die('No files to edit.'); } } else { $file = WPFB_File::GetFile($_GET['file_id']); if (is_null($file) || !$file->CurUserCanEdit()) { wp_die(__('You do not have the permission to edit this file!', 'wp-filebase')); } WPFB_Admin::PrintForm('file', $file); } break; case 'updatefile': $file_id = (int) $_POST['file_id']; $update = true; $file = WPFB_File::GetFile($file_id); if (is_null($file) || !$file->CurUserCanEdit()) { wp_die(__('Cheatin’ uh?')); } case 'addfile': $update = !empty($update); if (!WPFB_Core::CurUserCanUpload()) { wp_die(__('Cheatin’ uh?')); } extract($_POST); if (isset($jj) && isset($ss)) { $jj = $jj > 31 ? 31 : $jj; $hh = $hh > 23 ? $hh - 24 : $hh; $mn = $mn > 59 ? $mn - 60 : $mn; $ss = $ss > 59 ? $ss - 60 : $ss; $_POST['file_date'] = sprintf("%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss); } $result = WPFB_Admin::InsertFile(stripslashes_deep(array_merge($_POST, $_FILES)), true); if (isset($result['error']) && $result['error']) { $message = $result['error'] . '<br /><a href="javascript:history.back()">' . __("Go back") . '</a>'; } else { $message = $update ? __('File updated.', 'wp-filebase') : __('File added.', 'wp-filebase'); } default: if (!current_user_can('upload_files')) { wp_die(__('Cheatin’ uh?')); } if (!empty($_REQUEST['redirect']) && !empty($_REQUEST['redirect_to'])) { WPFB_AdminLite::JsRedirect($_REQUEST['redirect_to']); exit; } if (!empty($_POST['deleteit'])) { foreach ((array) $_POST['delete'] as $file_id) { if (is_object($file = WPFB_File::GetFile($file_id)) && $file->CurUserCanDelete()) { $file->Remove(true); } } WPFB_File::UpdateTags(); } ?> <h2><?php echo str_replace(array('(<', '>)'), array('<', '>'), sprintf(__('Manage Files (<a href="%s">add new</a>)', 'wp-filebase'), '#addfile" class="add-new-h2')); echo '<a href="' . admin_url('admin.php?page=wpfilebase_manage&action=batch-upload') . '" class="add-new-h2">' . __('Batch Upload', 'wp-filebase') . '</a>'; if (isset($_GET['s']) && $_GET['s']) { printf('<span class="subtitle">' . __('Search results for “%s”') . '</span>', esc_html(stripslashes($_GET['s']))); } ?> </h2> <?php if (!empty($message)) { ?> <div id="message" class="updated fade"><p><?php echo $message; ?> </p></div><?php } if (WPFB_Core::CurUserCanUpload() && ($action == 'addfile' || $action == 'updatefile')) { unset($file); WPFB_Admin::PrintForm('file', null, array('exform' => $exform, 'item' => new WPFB_File(isset($result['error']) && $result['error'] ? $_POST : null))); } wpfb_loadclass('FileListTable'); $file_table = new WPFB_FileListTable(); $file_table->prepare_items(); ?> <form class="search-form topmargin" action="" method="get"> <input type="hidden" value="<?php echo esc_attr($_GET['page']); ?> " name="page" /> <input type="hidden" value="<?php echo empty($_GET['view']) ? '' : esc_attr(@$_GET['view']); ?> " name="view" /> <?php $file_table->search_box(__('Search Files', 'wp-filebase'), 's'); ?> </form> <?php $file_table->views(); ?> <form id="posts-filter" action="" method="post"> <input type="hidden" name="page" value="<?php echo $_REQUEST['page']; ?> " /> <?php $file_table->display(); ?> </form> <br class="clear" /> <?php if ($action != 'addfile' && $action != 'updatefile' && WPFB_Core::CurUserCanUpload()) { unset($file); WPFB_Admin::PrintForm('file', null, array('exform' => $exform)); } break; // default } /* $file_list_table = new WPFB_File_List_Table(); $pagenum = $file_list_table->get_pagenum(); $doaction = $file_list_table->current_action(); $file_list_table->prepare_items(); $file_list_table->views(); $file_list_table->search_box( "asdf", 'post' ); $file_list_table->display(); */ ?> </div> <!-- wrap --> <?php }
static function Display() { global $wpdb; wpfb_loadclass('Admin', 'Output'); WPFB_Core::PrintJS(); // prints wpfbConf.ajurl wp_register_script('jquery-imagepicker', WPFB_PLUGIN_URI . 'extras/jquery/image-picker/image-picker.min.js', array('jquery'), WPFB_VERSION); wp_register_style('jquery-imagepicker', WPFB_PLUGIN_URI . 'extras/jquery/image-picker/image-picker.css', array(), WPFB_VERSION); if (!current_user_can('manage_options')) { wp_die(__('Cheatin’ uh?') . '<!-- manage_options -->'); } // nonce and referer check (security) if ((!empty($_POST['reset']) || !empty($_POST['submit'])) && !check_admin_referer('wpfb-update-settings', 'wpfb-nonce')) { wp_die(__('Cheatin’ uh?')); } $post = stripslashes_deep($_POST); $action = !empty($post['action']) ? $post['action'] : (!empty($_GET['action']) ? $_GET['action'] : ''); $messages = array(); $errors = array(); $options = get_option(WPFB_OPT_NAME); $option_fields = WPFB_Admin::SettingsSchema(); if (isset($post['reset'])) { // keep templates $file_tpl = WPFB_Core::$settings->template_file; $cat_tpl = WPFB_Core::$settings->template_cat; wpfb_loadclass('Setup'); WPFB_Setup::ResetOptions(); WPFB_Core::UpdateOption('template_file', $file_tpl); WPFB_Core::UpdateOption('template_cat', $cat_tpl); $new_options = get_option(WPFB_OPT_NAME); $messages = array_merge($messages, WPFB_Admin::SettingsUpdated($options, $new_options)); unset($new_options); $messages[] = __('Settings reseted.', WPFB); $options = get_option(WPFB_OPT_NAME); } elseif (isset($post['submit'])) { // cleanup foreach ($option_fields as $opt_tag => $opt_data) { if (isset($post[$opt_tag])) { if (!is_array($post[$opt_tag])) { $post[$opt_tag] = trim($post[$opt_tag]); } switch ($opt_data['type']) { case 'number': $post[$opt_tag] = intval($post[$opt_tag]); break; case 'select': // check if value is in options array, if not set to default if (!in_array($post[$opt_tag], array_keys($opt_data['options']))) { $post[$opt_tag] = $opt_data['default']; } break; case 'roles': $post[$opt_tag] = array_values(array_filter($post[$opt_tag])); // the following must not be removed! if the roles array is empty, permissions are assumed to be set for everyone! // so make sure that the admin is explicitly set! if (!empty($opt_data['not_everyone']) && !in_array('administrator', $post[$opt_tag])) { if (!is_array($post[$opt_tag])) { $post[$opt_tag] = array(); } array_unshift($post[$opt_tag], 'administrator'); } break; case 'cat': $post[$opt_tag] = empty($post[$opt_tag]) || is_null($cat = WPFB_Category::GetCat($post[$opt_tag])) ? 0 : intval($post[$opt_tag]); break; } } } $post['upload_path'] = str_replace(ABSPATH, '', $post['upload_path']); $options['upload_path'] = str_replace(ABSPATH, '', $options['upload_path']); $post['download_base'] = trim($post['download_base'], '/'); if (WPFB_Admin::WPCacheRejectUri($post['download_base'] . '/', $options['download_base'] . '/')) { $messages[] = sprintf(__('/%s/ added to rejected URIs list of WP Super Cache.', WPFB), $post['download_base']); } $tpl_file = $post['template_file']; $tpl_cat = $post['template_cat']; if (!empty($tpl_file) && (empty($options['template_file_parsed']) || $tpl_file != $options['template_file'])) { wpfb_loadclass('TplLib'); $tpl_file = WPFB_TplLib::Parse($tpl_file); $result = WPFB_TplLib::Check($tpl_file); if (!$result['error']) { $options['template_file_parsed'] = $tpl_file; $messages[] = __('File template successfully parsed.', WPFB); } else { $errors[] = sprintf(__('Could not parse template: error (%s) in line %s.', WPFB), $result['msg'], $result['line']); } } if (!empty($tpl_cat) && (empty($options['template_cat_parsed']) || $tpl_cat != $options['template_cat'])) { wpfb_loadclass('TplLib'); $tpl_cat = WPFB_TplLib::Parse($tpl_cat); $result = WPFB_TplLib::Check($tpl_cat); if (!$result['error']) { $options['template_cat_parsed'] = $tpl_cat; $messages[] = __('Category template successfully parsed.', WPFB); } else { $errors[] = sprintf(__('Could not parse template: error (%s) in line %s.', WPFB), $result['msg'], $result['line']); } } $fb_sub_pages = get_pages(array('child_of' => $options['file_browser_post_id'])); if ($options['file_browser_post_id'] > 0 && count($fb_sub_pages)) { $messages[] = sprintf(__('Warning: The Filebrowser page <b>%s</b> has at least one subpage <b>%s</b>. This will cause unexpected behavior, since all requests to the subpages are redirected to the File Browser Page. Please choose a Page that does not have any subpages for File Browser.', WPFB), get_the_title($post['file_browser_post_id']), get_the_title($fb_sub_pages[0]->ID)); } // save options foreach ($option_fields as $opt_tag => $opt_data) { $val = isset($post[$opt_tag]) ? $post[$opt_tag] : ''; $options[$opt_tag] = $val; } // make sure a short tag exists, if not append one $select_opts = array('languages', 'platforms', 'licenses', 'requirements', 'custom_fields'); foreach ($select_opts as $opt_tag) { if (empty($options[$opt_tag])) { $options[$opt_tag] = ''; continue; } $lines = explode("\n", $options[$opt_tag]); $lines2 = array(); for ($i = 0; $i < count($lines); $i++) { $lines[$i] = str_replace('||', '|', trim($lines[$i], "|\r")); if (empty($lines[$i]) || $lines[$i] == '|') { continue; } $pos = strpos($lines[$i], '|'); if ($pos <= 0) { $lines[$i] .= '|' . sanitize_key(substr($lines[$i], 0, min(8, strlen($lines[$i])))); } $lines2[] = $lines[$i]; } $options[$opt_tag] = implode("\n", $lines2); } $old_options = get_option(WPFB_OPT_NAME); update_option(WPFB_OPT_NAME, $options); WPFB_Core::$settings = (object) $options; $messages = array_merge($messages, WPFB_Admin::SettingsUpdated($old_options, $options)); if (count($errors) == 0) { $messages[] = __('Settings updated.', WPFB); } //refresh any description which can contain opt values $option_fields = WPFB_Admin::SettingsSchema(); } if (WPFB_Core::$settings->allow_srv_script_upload) { $messages[] = __('WARNING: Script upload enabled!', WPFB); } $upload_path = WPFB_Core::$settings->upload_path; if (!empty($old_options) && path_is_absolute($upload_path) && !path_is_absolute($old_options['upload_path'])) { $rel_path = str_replace('\\', '/', $upload_path); $rel_path = substr($rel_path, strpos($rel_path, '/') + 1); $messages[] = __(sprintf('NOTICE: The upload path <code>%s</code> is rooted to the filesystem. You should remove the leading slash if you want to use a folder inside your Wordpress directory (i.e: <code>%s</code>)', $upload_path, $rel_path), WPFB); } $action_uri = admin_url('admin.php') . '?page=' . $_GET['page'] . '&updated=true'; if (!empty($messages)) { $message = ''; foreach ($messages as $msg) { $message .= '<p>' . $msg . '</p>'; } ?> <div id="message" class="updated fade"><?php echo $message; ?> </div> <?php } if (!empty($errors)) { $error = ''; foreach ($errors as $err) { $error .= '<p>' . $err . '</p>'; } ?> <div id="message" class="error fade"><?php echo $error; ?> </div> <?php } ?> <script type="text/javascript"> /* Option tabs */ jQuery(document).ready( function() { try { jQuery('#wpfb-tabs').tabs(); } catch(ex) {} /*if(typeof(CKEDITOR) != 'undefined') { CKEDITOR.plugins.addExternal('wpfilebase', ajaxurl+'/../../wp-content/plugins/wp-filebase/extras/ckeditor/'); alert( ajaxurl+'/../../wp-content/plugins/wp-filebase/extras/ckeditor/'); }*/ }); </script> <div class="wrap"> <div id="icon-options-general" class="icon32"><br /></div> <h2><?php echo WPFB_PLUGIN_NAME; echo ' '; _e("Settings"); ?> </h2> <form method="post" action="<?php echo $action_uri; ?> " name="wpfilebase-options"> <?php wp_nonce_field('wpfb-update-settings', 'wpfb-nonce'); ?> <p class="submit"> <input type="submit" name="submit" value="<?php _e('Save Changes'); ?> " class="button-primary" /> </p> <?php $misc_tags = array('disable_id3', 'search_id3', 'thumbnail_path', 'use_path_tags', 'no_name_formatting'); if (function_exists('wp_admin_bar_render')) { $misc_tags[] = 'admin_bar'; } $limits = array('bitrate_unregistered', 'bitrate_registered', 'traffic_day', 'traffic_month', 'traffic_exceeded_msg', 'file_offline_msg', 'daily_user_limits', 'daily_limit_subscriber', 'daily_limit_contributor', 'daily_limit_author', 'daily_limit_editor', 'daily_limit_exceeded_msg'); $option_categories = array(__('Common', WPFB) => array('upload_path', 'search_integration'), __('Display', WPFB) => array('file_date_format', 'thumbnail_size', 'auto_attach_files', 'attach_loop', 'attach_pos', 'filelist_sorting', 'filelist_sorting_dir', 'filelist_num', 'decimal_size_format', 'search_result_tpl', 'disable_css'), __('File Browser', WPFB) => array('file_browser_post_id', 'file_browser_cat_sort_by', 'file_browser_cat_sort_dir', 'file_browser_file_sort_by', 'file_browser_file_sort_dir', 'file_browser_fbc', 'late_script_loading', 'folder_icon', 'small_icon_size', 'disable_footer_credits', 'footer_credits_style'), __('Download', WPFB) => array('hide_links', 'disable_permalinks', 'download_base', 'force_download', 'range_download', 'http_nocache', 'ignore_admin_dls', 'accept_empty_referers', 'allowed_referers', 'use_fpassthru'), __('Form Presets', WPFB) => array('default_author', 'default_roles', 'default_cat', 'default_direct_linking', 'languages', 'platforms', 'licenses', 'requirements', 'custom_fields'), __('Limits', WPFB) => $limits, __('Security', WPFB) => array('allow_srv_script_upload', 'fext_blacklist', 'frontend_upload', 'hide_inaccessible', 'inaccessible_msg', 'inaccessible_redirect', 'cat_inaccessible_msg', 'login_redirect_src', 'protect_upload_path', 'private_files'), __('Templates and Scripts', WPFB) => array('template_file', 'template_cat', 'dlclick_js'), __('Sync', WPFB) => array('cron_sync', 'base_auto_thumb', 'remove_missing_files', 'fake_md5'), __('Misc') => $misc_tags); ?> <div id="wpfb-tabs"> <ul class="wpfb-tab-menu"> <?php foreach ($option_categories as $key => $val) { echo '<li><a href="#' . sanitize_title($key) . '">' . esc_html($key) . '</a></li>'; } ?> </ul> <?php $page_option_list = ''; $n = 0; foreach ($option_categories as $opt_cat => $opt_cat_fields) { //echo "\n".'<h3>'.$opt_cat.'</h3>'; echo "\n\n" . '<div id="' . sanitize_title($opt_cat) . '" class="wpfilebase-opttab"><h3>' . $opt_cat . '</h3><table class="form-table">'; foreach ($opt_cat_fields as $opt_tag) { $field_data = $option_fields[$opt_tag]; $opt_val = $options[$opt_tag]; echo "\n" . '<tr valign="top">' . "\n" . '<th scope="row">' . $field_data['title'] . '</th>' . "\n" . '<td>'; $style_class = ''; if (!empty($field_data['class'])) { $style_class .= ' class="' . $field_data['class'] . '"'; } if (!empty($field_data['style'])) { $style_class .= ' style="' . $field_data['style'] . '"'; } switch ($field_data['type']) { case 'text': case 'number': case 'checkbox': echo '<input name="' . $opt_tag . '" type="' . $field_data['type'] . '" id="' . $opt_tag . '"'; echo !empty($field_data['class']) ? ' class="' . $field_data['class'] . '"' : ''; if ($field_data['type'] == 'checkbox') { echo ' value="1" '; checked('1', $opt_val); } elseif ($field_data['type'] == 'number') { echo ' value="' . intval($opt_val) . '" size="5" style="text-align: right"'; } else { echo ' value="' . esc_attr($opt_val) . '"'; if (isset($field_data['size'])) { echo ' size="' . (int) $field_data['size'] . '"'; } } echo $style_class . ' />'; break; case 'textarea': $code_edit = strpos($opt_tag, 'template_') !== false || isset($field_data['class']) && strpos($field_data['class'], 'code') !== false; $nowrap = !empty($field_data['nowrap']); echo '<textarea name="' . $opt_tag . '" id="' . $opt_tag . '"'; if ($nowrap || $code_edit) { echo ' cols="100" wrap="off" style="width: 100%;' . ($code_edit ? 'font-size: 9px;' : '') . '"'; } else { echo ' cols="50"'; } echo ' rows="' . ($code_edit ? 20 : 5) . '"'; echo $style_class; echo '>'; echo esc_html($opt_val); echo '</textarea>'; break; case 'select': echo '<select name="' . $opt_tag . '" id="' . $opt_tag . '">'; foreach ($field_data['options'] as $opt_v => $opt_n) { echo '<option value="' . esc_attr($opt_v) . '"' . ($opt_v == $opt_val ? ' selected="selected" ' : '') . $style_class . '>' . (!is_numeric($opt_v) && $opt_v !== $opt_n ? esc_html($opt_v) . ': ' : '') . esc_html($opt_n) . '</option>'; } echo '</select>'; break; case 'roles': WPFB_Admin::RolesCheckList($opt_tag, $opt_val, empty($field_data['not_everyone'])); break; case 'icon': wp_print_scripts('jquery-imagepicker'); wp_print_styles('jquery-imagepicker'); echo '<select class="image-picker show-html" name="' . $opt_tag . '" id="' . $opt_tag . '">'; ?> <?php foreach ($field_data['icons'] as $icon) { echo '<option data-img-src="' . $icon['url'] . '" value="' . $icon['path'] . '" ' . ($icon['path'] === $opt_val ? ' selected="selected" ' : '') . '>' . basename($icon['path']) . '</option>'; } ?> </select> <script type="text/javascript"> jQuery(document).ready( function() { jQuery("#<?php echo $opt_tag; ?> ").imagepicker(); }); </script> <?php break; case 'cat': echo "<select name='{$opt_tag}' id='{$opt_tag}'>"; echo WPFB_Output::CatSelTree(array('selected' => $opt_val)); echo "</select>"; break; } if (!empty($field_data['unit'])) { echo ' ' . $field_data['unit']; } if (!empty($field_data['desc'])) { echo "\n" . '<br />' . str_replace('%value%', is_array($opt_val) ? join(', ', $opt_val) : $opt_val, $field_data['desc']); } echo "\n</td>\n</tr>"; $page_option_list .= $opt_tag . ','; } echo '</table></div>' . "\n"; } ?> </div> <!--wpfilebase-opttabs--> <input type="hidden" name="action" value="update" /> <input type="hidden" name="page_options" value="<?php echo $page_option_list; ?> " /> <p class="submit"> <input type="submit" name="submit" value="<?php _e('Save Changes'); ?> " class="button-primary" /> <input type="submit" name="reset" value="<?php _e('Restore Default Settings', WPFB); ?> " onclick="return confirm('<?php _e('All settings (except default file and category template) will be set to default values. Continue?', WPFB); ?> ')" class="button delete" style="float: right;" /> </p> </form> </div> <!-- wrap --> <?php }