static function Display() { global $wpdb, $user_ID; wpfb_loadclass('Admin', 'Output'); $_POST = stripslashes_deep($_POST); $_GET = stripslashes_deep($_GET); $action = !empty($_POST['action']) ? $_POST['action'] : (!empty($_GET['action']) ? $_GET['action'] : ''); $clean_uri = remove_query_arg(array('message', 'action', 'file_id', 'cat_id', 'deltpl', 'hash_sync')); // keep search keyword WPFB_Admin::PrintFlattrHead(); ?> <div class="wrap"><?php switch ($action) { default: ?> <div id="wpfilebase-donate"> <p><?php _e('If you like WP-Filebase I would appreciate a small donation to support my work. You can additionally add an idea to make WP-Filebase even better. Just click the button below. Thank you!', WPFB); ?> </p> <?php WPFB_Admin::PrintPayPalButton(); WPFB_Admin::PrintFlattrButton(); ?> </div> <?php break; } ?> </div> <!-- wrap --> <?php }
function testCreateTree() { $this->testSetUser(); wpfb_loadclass('Admin'); /** @var WPFB_Category $parent */ $parent = null; /** @var WPFB_Category[] $cats */ $cats = array(); for ($d = 0; $d < 4; $d++) { $res = WPFB_Admin::InsertCategory(array('cat_name' => "layer {$d}", 'cat_parent' => $parent ? $parent->GetId() : 0)); $this->assertEmpty($res['error']); /** @var WPFB_Category $cat */ $cat = $res['cat']; $this->assertTrue($parent ? $cat->GetParent()->Equals($parent) : is_null($cat->GetParent())); $this->assertTrue(is_dir($cat->GetLocalPath())); $cats[] = $cat; $parent = $cat; } // print_r(array_map( function($c) { return strval($c);}, $cats)); $files = new TestFileSet(); $res = WPFB_Admin::InsertFile(array('file_remote_uri' => 'file://' . $files->getImageBanner(), 'file_category' => $parent)); $this->assertEmpty($res['error'], $res['error']); /** @var WPFB_File $file01 */ $file01 = $res['file']; }
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 }
function testDownload() { $usr = wp_create_user('test_admin', 'test_admin'); $this->assertNotWPError($usr); wp_set_current_user($usr); $files = new TestFileSet(); $res = WPFB_Admin::InsertFile(array('file_remote_uri' => 'file://' . $files->getImageBanner())); $this->assertEmpty($res['error'], $res['error']); /** @var WPFB_File $file01 */ $file01 = $res['file']; $file01->Delete(); }
function test_new_file_remote() { $usr = wp_create_user('test_admin', 'test_admin'); $this->assertNotWPError($usr); wp_set_current_user($usr); wpfb_loadclass('Admin'); $res = WPFB_Admin::InsertFile(array('file_remote_uri' => 'https://wpfilebase.com/wp-content/blogs.dir/2/files/2015/03/banner_023.png')); $this->assertEmpty($res['error'], $res['error']); /** @var WPFB_File $file */ $file = $res['file']; $this->assertTrue($file->IsLocal(), 'IsLocal false'); $this->assertFileExists($file->GetLocalPath()); $this->assertNotEmpty($file->file_thumbnail); $this->assertFileExists($file->GetThumbPath()); $this->assertTrue($file->Remove()); }
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); } }
/** * @depends test_new_cat */ function test_cat_tree() { wpfb_loadclass('Admin'); $depth = 4; /** @var WPFB_Category $parent */ $parent = null; $cats = array(); for ($d = 0; $d < $depth; $d++) { $res = WPFB_Admin::InsertCategory(array('cat_name' => "layer {$d}", 'cat_parent' => $parent ? $parent->GetId() : 0)); $this->assertEmpty($res['error']); /** @var WPFB_Category $cat */ $cat = $res['cat']; $this->assertTrue($parent ? $cat->GetParent()->Equals($parent) : is_null($cat->GetParent())); $cats[] = $cat; } foreach (array_reverse($cats) as $cat) { $res = $cat->Delete(); $this->assertEmpty($res['error'], $res['error']); } }
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 }
/** * 1. Checks if file is actually present and readable on file system and either sets file offline or completly removes it * 2. If file hash not set, calculate it * 3. Try to generate a thumbnail if it does not exists * 4. Update ID3 info (with _async_ RPC if enabled) * * @param WPFB_File $file * @param bool $forced_refresh_thumb * @return bool */ static function ScanFile($file, $forced_refresh_thumb = false, $allow_async = true) { if (!empty($_GET['debug'])) { WPFB_Sync::PrintDebugTrace("scanning_file:" . $file->GetLocalPathRel()); } $file_path = $file->GetLocalPath(); $tmp_file = false; if (!$file->IsLocal()) { $res = WPFB_Admin::SideloadFile($file->GetRemoteUri(), $file_path); if ($res['error']) { return false; } $tmp_file = true; } elseif (!is_file($file_path) || !is_readable($file_path)) { if (WPFB_Core::$settings->remove_missing_files) { $file->Remove(); return true; } else { $file->file_offline = true; $file->file_mtime = 0; $file->file_rescan_pending = 1; $file->DbSave(); return true; } } if (empty($file->file_hash)) { $file->file_hash = WPFB_Admin::GetFileHash($file->GetLocalPath()); } if (empty($file->file_thumbnail) || $forced_refresh_thumb || !is_file($file->GetThumbPath())) { $file->Lock(true); $file->CreateThumbnail(); // this only deltes old thumb if success $file->Lock(false); if (WPFB_Core::$settings->base_auto_thumb && empty($file->file_thumbnail)) { $thumb = false; $pwe = substr($file->GetLocalPath(), 0, strrpos($file->GetLocalPath(), '.') + 1); if ($pwe && (file_exists($thumb = $pwe . 'png') || file_exists($thumb = $pwe . 'jpg') || file_exists($thumb = $pwe . 'gif'))) { $file->file_thumbnail = basename($thumb); $dthumb = $file->GetThumbPath(true); if ($dthumb != $thumb) { $dir = dirname($dthumb); if (!is_dir($dir)) { WPFB_Admin::Mkdir($dir); } rename($thumb, $dthumb); } } } } $file->file_rescan_pending = 1; $file->DBSave(); WPFB_GetID3::UpdateCachedFileInfo($file); return true; }
<input type="submit" name="change-order" value="<?php _e('Change Order', 'wp-filebase'); ?> " /> </form> <?php } // switch simple/extended form if (isset($_GET['exform'])) { $exform = !empty($_GET['exform']) && $_GET['exform'] == 1; update_user_option($user_ID, WPFB_OPT_NAME . '_exform_ep', $exform, true); } else { $exform = (bool) get_user_option(WPFB_OPT_NAME . '_exform_ep'); } //if( (WPFB_Core::CurUserCanUpload()&&empty($file))) TODO WPFB_Admin::PrintForm('file', $file, array('exform' => $exform, 'in_editor' => true, 'post_id' => $post_id)); ?> <h3 class="media-title"><?php _e('Attach existing file', 'wp-filebase'); ?> </h3> <ul id="attachbrowser" class="filetree"></ul> <?php wpfb_loadclass('TreeviewAdmin'); WPFB_TreeviewAdmin::RenderHTML("attachbrowser"); ?> </div> <!-- attach --> <?php if (!$manage_attachments) { ?>
function process_bulk_action() { if (!$this->current_action() || empty($_REQUEST['file']) && empty($_REQUEST['action2'])) { return; } // filter files current user can edit $files = isset($_REQUEST['file']) ? array_filter(array_map(array('WPFB_File', 'GetFile'), $_REQUEST['file']), create_function('$file', 'return ($file && $file->CurUserCan' . 'Edit' . '());')) : array(); $message = null; switch ($this->current_action()) { case 'delete': foreach ($files as $file) { $file->Remove(true); } WPFB_Admin::SyncCustomFields(); $message = sprintf(__("%d File(s) deleted.", WPFB), count($files)); break; case 'edit': if (isset($_REQUEST['action2']) && $_REQUEST['action2'] == 'apply') { $message = wpfb_call('AdminGuiBulkEdit', 'Process'); } else { wpfb_call('AdminGuiBulkEdit', 'Display'); exit; } break; case 'set_off': foreach ($files as $file) { $file->file_offline = 1; $file->DbSave(); } $message = sprintf(__("%d File(s) were set offline.", WPFB), count($files)); break; case 'set_on': foreach ($files as $file) { $file->file_offline = 0; $file->DbSave(); } $message = sprintf(__("%d File(s) were set online.", WPFB), count($files)); break; } if (!empty($message)) { ?> <div id="message" class="updated fade"><p><?php echo $message; ?> </p></div><?php } }
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': wpfb_loadclass('File', 'Admin'); $item = WPFB_Item::GetById($_POST['id'], $_POST['type']); if ($item && $item->CurUserCanEdit()) { $res = $item->ChangeCategoryOrName($_POST['new_cat_id']);
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 }
/** * 1. Checks if file is actually present and readable on file system and either sets file offline or completly removes it * 2. If file hash not set, calculate it * 3. Try to generate a thumbnail if it does not exists * 4. Update ID3 info (with _async_ RPC if enabled) * * @param WPFB_File $file * @param bool $forced_refresh_thumb * * @return bool */ static function ScanFile($file, $forced_refresh_thumb = false, $allow_async = true) { $forced_refresh_thumb = $forced_refresh_thumb || $file->file_rescan_pending > 1; $file->file_rescan_pending = max($file->file_rescan_pending, $forced_refresh_thumb ? 2 : 1); if (!$file->TryScanLock()) { WPFB_Core::LogMsg("ERROR: ScanFile {$file} locking failed!", 'sync'); return false; } $file_path = $file->GetLocalPath(); if (!$file->IsLocal()) { $res = WPFB_Admin::SideloadFile($file, $file_path); if ($res['error']) { WPFB_Core::LogMsg("ERROR: ScanFile({$file}) download {$file->GetRemoteUri()} failed {$res['error']}!", 'sync'); $file->file_rescan_pending = 0; $file->DbSave(true); return false; } } elseif (!is_file($file_path) || !is_readable($file_path)) { if (WPFB_Core::$settings->remove_missing_files) { WPFB_Core::LogMsg("ScanFile({$file}) removing missing file!", 'sync'); $file->Remove(); return true; } else { $file->file_offline = true; $file->file_mtime = 0; $file->DbSave(true); return true; } } if (empty($file->file_hash)) { $file->file_hash = WPFB_Admin::GetFileHash($file->GetLocalPath()); } if (empty($file->file_thumbnail) || $forced_refresh_thumb || !is_file($file->GetThumbPath())) { $file->Lock(true); $file->CreateThumbnail(); // this only deltes old thumb if success $file->Lock(false); if (WPFB_Core::$settings->base_auto_thumb && (empty($file->file_thumbnail) || !is_file($file->GetThumbPath()))) { $pwe = substr($file->GetLocalPath(), 0, strrpos($file->GetLocalPath(), '.') + 1); if ($pwe && (file_exists($thumb = $pwe . 'png') || file_exists($thumb = $pwe . 'thumb.png') || file_exists($thumb = $pwe . 'jpg') || file_exists($thumb = $pwe . 'thumb.jpg') || file_exists($thumb = $pwe . 'gif') || file_exists($thumb = $pwe . 'thumb.gif'))) { $file->file_thumbnail = basename($thumb); $dest_thumb = $file->GetThumbPath(true); if ($dest_thumb != $thumb) { $dir = dirname($dest_thumb); if (!is_dir($dir)) { WPFB_Admin::Mkdir($dir); } rename($thumb, $dest_thumb); } } } } $file->DBSave(true); // the UpdateCachedFileInfo/StoreFileInfo will delete the file if necessary! (no need of $tmp_file value!) if (!WPFB_GetID3::UpdateCachedFileInfo($file)) { WPFB_Core::LogMsg("ScanFile({$file}) file scan failed!", 'sync'); return false; } return true; }
static function WidgetAddFile($compact = false) { global $user_ID; // 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'); } wpfb_loadclass('Admin', 'File', 'Category'); WPFB_Admin::PrintForm('file', null, !$compact ? array('exform' => false, 'in_widget' => false) : array('exform' => false, 'in_widget' => true)); }
static function Display() { global $wpdb, $user_ID; if (!WPFB_Admin::CurUserCanCreateCat()) { wp_die(__('Cheatin’ uh?')); } wpfb_loadclass('Category', 'File', 'Admin', 'Output'); $_POST = stripslashes_deep($_POST); $_GET = stripslashes_deep($_GET); $action = !empty($_POST['action']) ? $_POST['action'] : (!empty($_GET['action']) ? $_GET['action'] : ''); $clean_uri = remove_query_arg(array('message', 'action', 'file_id', 'cat_id', 'deltpl', 'hash_sync')); // keep search keyword // 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); } else { $exform = (bool) get_user_option(WPFB_OPT_NAME . '_exform'); } ?> <div class="wrap"> <?php switch ($action) { case 'editcat': $cat_id = (int) $_GET['cat_id']; $file_category = WPFB_Category::GetCat($cat_id); if (is_null($file_category) || !$file_category->CurUserCanEdit()) { wp_die(__('Cheatin’ uh?')); } WPFB_Admin::PrintForm('cat', $file_category); break; case 'updatecat': $cat_id = (int) $_POST['cat_id']; $update = true; $file_category = WPFB_Category::GetCat($cat_id); if (is_null($file_category) || !$file_category->CurUserCanEdit()) { wp_die(__('Cheatin’ uh?')); } case 'addcat': $update = !empty($update); $result = WPFB_Admin::InsertCategory(array_merge(stripslashes_deep($_POST), $_FILES)); if (isset($result['error']) && $result['error']) { $message = $result['error']; } else { $message = $update ? __('Category updated.') : __('Category added.'); /*def*/ } //wp_redirect($clean_uri . '&action=manage_cats&message=' . urlencode($message)); //wp_redirect($clean_uri . '&action=manage_cats&message=' . urlencode($message)); default: if (!empty($_POST['deleteit'])) { foreach ((array) $_POST['delete'] as $cat_id) { if (is_object($cat = WPFB_Category::GetCat($cat_id)) && $cat->CurUserCanEdit()) { $cat->Delete(); } } } ?> <h2><?php echo str_replace(array('(<', '>)'), array('<', '>'), sprintf(__('Manage Categories (<a href="%s">add new</a>)', WPFB), '#addcat" class="add-new-h2')); 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 } ?> <form class="search-form topmargin" action="" method="get"><p class="search-box"> <input type="hidden" value="<?php echo esc_attr($_GET['page']); ?> " name="page" /> <label class="hidden" for="category-search-input"><?php _e('Search Categories'); ?> :</label> <input type="text" class="search-input" id="category-search-input" name="s" value="<?php echo isset($_GET['s']) ? esc_attr($_GET['s']) : ''; ?> " /> <input type="submit" value="<?php _e('Search Categories'); ?> " class="button" /> </p></form> <br class="clear" /> <form id="posts-filter" action="" method="post"> <div class="tablenav"> <?php $pagenum = max(isset($_GET['pagenum']) ? absint($_GET['pagenum']) : 0, 1); if (!isset($catsperpage) || $catsperpage < 0) { $catsperpage = 20; } $pagestart = ($pagenum - 1) * $catsperpage; $extra_sql = ''; if (!empty($_GET['s'])) { $s = esc_sql(trim($_GET['s'])); $extra_sql .= "WHERE cat_name LIKE '%{$s}%' OR cat_description LIKE '%{$s}%' OR cat_folder LIKE '%{$s}%' "; } if (!empty($_GET['order']) && in_array($_GET['order'], array_keys(get_class_vars('WPFB_Category')))) { $extra_sql .= "ORDER BY " . $_GET['order'] . " " . (!empty($_GET['desc']) ? "DESC" : "ASC"); } $cats = WPFB_Category::GetCats($extra_sql . " LIMIT {$pagestart}, {$catsperpage}"); $page_links = paginate_links(array('base' => add_query_arg('pagenum', '%#%'), 'format' => '', 'total' => ceil(count(WPFB_Category::GetCats($extra_sql)) / $catsperpage), 'current' => $pagenum)); if ($page_links) { echo "<div class='tablenav-pages'>{$page_links}</div>"; } ?> <div class="alignleft"><input type="submit" value="<?php _e('Delete'); ?> " name="deleteit" class="button delete" /><?php wp_nonce_field('bulk-categories'); ?> </div> </div> <br class="clear" /> <table class="widefat"> <thead> <tr> <th scope="col" class="check-column"><input type="checkbox" /></th> <th scope="col"><a href="<?php echo WPFB_Admin::AdminTableSortLink('cat_name'); ?> "><?php _e('Name'); ?> </a></th> <th scope="col"><a href="<?php echo WPFB_Admin::AdminTableSortLink('cat_description'); ?> "><?php _e('Description'); ?> </a></th> <th scope="col" class="num"><a href="<?php echo WPFB_Admin::AdminTableSortLink('cat_num_files'); ?> "><?php _e('Files', WPFB); ?> </a></th> <th scope="col"><a href="<?php echo WPFB_Admin::AdminTableSortLink('cat_parent'); ?> "><?php _e('Parent Category'); ?> </a></th> <th scope="col"><a href="<?php echo WPFB_Admin::AdminTableSortLink('cat_path'); ?> "><?php _e('Path'); ?> </a></th> <th scope="col"><a href="<?php echo WPFB_Admin::AdminTableSortLink('cat_user_roles'); ?> "><?php _e('Access Permission', WPFB); ?> </a></th> <th scope="col"><a href="<?php echo WPFB_Admin::AdminTableSortLink('cat_owner'); ?> "><?php _e('Owner', WPFB); ?> </a></th> <th scope="col"><a href="<?php echo WPFB_Admin::AdminTableSortLink('cat_order'); ?> "><?php _e('Custom Sort Order', WPFB); ?> </a></th> </tr> </thead> <tbody id="the-list" class="list:cat"> <?php foreach ($cats as $cat_id => &$cat) { if ($cat->CurUserCanEdit()) { self::CatRow($cat); } } ?> </tbody> </table> <div class="tablenav"><?php if ($page_links) { echo "<div class='tablenav-pages'>{$page_links}</div>"; } ?> </div> </form> <br class="clear" /> <?php if (WPFB_Admin::CurUserCanCreateCat()) { ?> <p><?php _e('<strong>Note:</strong><br />Deleting a category does not delete the files in that category. Instead, files that were assigned to the deleted category are set to the parent category.', WPFB); ?> </p><?php WPFB_Admin::PrintForm('cat'); } break; } ?> </div> <!-- wrap --> <?php }
static function Display() { global $wpdb, $user_ID; //register_shutdown_function( create_function('','$error = error_get_last(); if( $error && $error[\'type\'] != E_STRICT ){print_r( $error );}else{return true;}') ); wpfb_loadclass('File', 'Category', 'Admin', 'Output'); $_POST = stripslashes_deep($_POST); $_GET = stripslashes_deep($_GET); $action = !empty($_POST['action']) ? $_POST['action'] : (!empty($_GET['action']) ? $_GET['action'] : ''); $clean_uri = remove_query_arg(array('message', 'action', 'file_id', 'cat_id', 'deltpl', 'hash_sync', 'doit', 'ids', 'files', 'cats', 'batch_sync')); // keep search keyword // 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'); } if (!empty($_GET['wpfb-hide-how-start'])) { update_user_option($user_ID, WPFB_OPT_NAME . '_hide_how_start', 1); } $show_how_start = !(bool) get_user_option(WPFB_OPT_NAME . '_hide_how_start'); WPFB_Admin::PrintFlattrHead(); ?> <script type="text/javascript"> /* Liking/Donate Bar */ if(typeof(jQuery) != 'undefined') { jQuery(document).ready(function(){ if(getUserSetting("wpfilebase_hidesuprow",false) == 1) { jQuery('#wpfb-liking').hide(); jQuery('#wpfb-liking-toggle').addClass('closed'); } jQuery('#wpfb-liking-toggle').click(function(){ jQuery('#wpfb-liking').slideToggle(); jQuery(this).toggleClass('closed'); setUserSetting("wpfilebase_hidesuprow", 1-getUserSetting("wpfilebase_hidesuprow",false), 0); }); }); } </script> <div class="wrap"> <div id="icon-wpfilebase" class="icon32"><br /></div> <h2><?php echo WPFB_PLUGIN_NAME; ?> </h2> <?php if ($show_how_start) { wpfb_call('AdminHowToStart', 'Display'); } if (!empty($_GET['action'])) { echo '<p><a href="' . $clean_uri . '" class="button">' . __('Go back') . '</a></p>'; } switch ($action) { default: $clean_uri = remove_query_arg('pagenum', $clean_uri); $upload_dir = WPFB_Core::UploadDir(); $upload_dir_rel = str_replace(ABSPATH, '', $upload_dir); $chmod_cmd = "CHMOD " . WPFB_PERM_DIR . " " . $upload_dir_rel; if (!is_dir($upload_dir)) { $result = WPFB_Admin::Mkdir($upload_dir); if ($result['error']) { $error_msg = sprintf(__('The upload directory <code>%s</code> does not exists. It could not be created automatically because the directory <code>%s</code> is not writable. Please create <code>%s</code> and make it writable for the webserver by executing the following FTP command: <code>%s</code>', WPFB), $upload_dir_rel, str_replace(ABSPATH, '', $result['parent']), $upload_dir_rel, $chmod_cmd); } else { wpfb_call('Setup', 'ProtectUploadPath'); } } elseif (!is_writable($upload_dir)) { $error_msg = sprintf(__('The upload directory <code>%s</code> is not writable. Please make it writable for PHP by executing the follwing FTP command: <code>%s</code>', WPFB), $upload_dir_rel, $chmod_cmd); } if (!empty($error_msg)) { echo '<div class="error default-password-nag"><p>' . $error_msg . '</p></div>'; } if (!empty(WPFB_Core::$settings->tag_conv_req)) { echo '<div class="updated"><p><a href="' . add_query_arg('action', 'convert-tags') . '">'; _e('WP-Filebase content tags must be converted', WPFB); echo '</a></p></div><div style="clear:both;"></div>'; } if (!get_post(WPFB_Core::$settings->file_browser_post_id)) { echo '<div class="updated"><p>'; printf(__('File Browser post or page not set! Some features like search will not work. <a href="%s">Click here to set the File Browser Post ID.</a>', WPFB), esc_attr(admin_url('admin.php?page=wpfilebase_sets#' . sanitize_title(__('File Browser', WPFB))))); echo '</p></div><div style="clear:both;"></div>'; } /* wpfb_loadclass('Config'); if(!WPFB_Config::IsWritable()) { echo '<div class="updated"><p>'; printf(__('The config file %s is not writable or could not be created. Please create the file and make it writable for the webserver.',WPFB), WPFB_Config::$file); echo '</p></div><div style="clear:both;"></div>'; } */ ?> <?php if (self::PluginHasBeenUsedAWhile(true)) { self::ProUpgradeNag(); } if (self::PluginHasBeenUsedAWhile()) { ?> <div id="wpfb-support-col"> <div id="wpfb-liking-toggle"></div> <h3><?php _e('Like WP-Filebase?', WPFB); ?> </h3> <div id="wpfb-liking"> <!-- <div style="text-align: center;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwordpress.org%2Fextend%2Fplugins%2Fwp-filebase%2F&send=false&layout=button_count&width=150&show_faces=false&action=like&colorscheme=light&font&height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:140px; height:21px; display:inline-block; text-align:center;" <?php echo ' allowTransparency="true"'; ?> ></iframe></div> --> <div style="text-align: center;" ><a href="https://twitter.com/wpfilebase" class="twitter-follow-button" data-show-count="false">Follow @wpfilebase</a> <script type="text/javascript">!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script></div> <p>Please <a href="http://wordpress.org/support/view/plugin-reviews/wp-filebase">give it a good rating</a>.</p> <p>For Cloud support and lots of other advanced features consider an</p> <p style="text-align: center;"><a href="https://wpfilebase.com/?ref=dblike" class="button-primary">Upgrade to Pro</a></p> <p style="text-align:right;float:right;font-style:italic;">Thanks, Fabian</p> <!-- <div style="text-align: center;"> <?php //WPFB_Admin::PrintPayPalButton() ?> <?php //WPFB_Admin::PrintFlattrButton() ?> </div> --> </div> </div> <?php } ?> <div id="wpfb-stats-wrap" style="float:right; border-left: 1px solid #eee; margin-left: 5px;"> <div id="col-container"> <div id="col-right"> <div class="col-wrap"> <h3><?php _e('Traffic', WPFB); ?> </h3> <table class="wpfb-stats-table"> <?php $traffic_stats = wpfb_call('Misc', 'GetTraffic'); $limit_day = WPFB_Core::$settings->traffic_day * 1048576; $limit_month = WPFB_Core::$settings->traffic_month * 1073741824; ?> <tr> <td><?php if ($limit_day > 0) { self::ProgressBar($traffic_stats['today'] / $limit_day, WPFB_Output::FormatFilesize($traffic_stats['today']) . '/' . WPFB_Output::FormatFilesize($limit_day)); } else { echo WPFB_Output::FormatFilesize($traffic_stats['today']); } ?> </td> <th scope="row"><?php _e('Today', WPFB); ?> </th> </tr> <tr> <td><?php if ($limit_month > 0) { self::ProgressBar($traffic_stats['month'] / $limit_month, WPFB_Output::FormatFilesize($traffic_stats['month']) . '/' . WPFB_Output::FormatFilesize($limit_month)); } else { echo WPFB_Output::FormatFilesize($traffic_stats['month']); } ?> </td> <th scope="row"><?php _e('This Month', WPFB); ?> </th> </tr> <tr> <td><?php echo WPFB_Output::FormatFilesize($wpdb->get_var("SELECT SUM(file_size) FROM {$wpdb->wpfilebase_files}")); ?> </td> <th scope="row"><?php _e('Total File Size', WPFB); ?> </th> </tr> </table> </div> </div><!-- /col-right --> <div id="col-left"> <div class="col-wrap"> <h3><?php _e('Statistics', WPFB); ?> </h3> <table class="wpfb-stats-table"> <tr> <td><?php echo WPFB_File::GetNumFiles(); ?> </td> <th scope="row"><?php _e('Files', WPFB); ?> </th> </tr> <tr> <td><?php echo WPFB_Category::GetNumCats(); ?> </td> <th scope="row"><?php _e('Categories', WPFB); ?> </th> </tr> <tr> <td><?php echo "" . (int) $wpdb->get_var("SELECT SUM(file_hits) FROM {$wpdb->wpfilebase_files}"); ?> </td> <th scope="row"><?php _e('Downloads', WPFB); ?> </th> </tr> </table> </div> </div><!-- /col-left --> </div><!-- /col-container --> </div> <div> <!-- <h2><?php _e('Tools'); ?> </h2> --> <?php $cron_sync_desc = ''; if (WPFB_Core::$settings->cron_sync) { $cron_sync_desc .= __('Automatic sync is enabled. Cronjob scheduled hourly.'); $last_sync_time = intval(get_option(WPFB_OPT_NAME . '_cron_sync_time')); $cron_sync_desc .= $last_sync_time > 0 ? " (" . sprintf(__('Last cron sync on %1$s at %2$s.', WPFB), date_i18n(get_option('date_format'), $last_sync_time), date_i18n(get_option('time_format'), $last_sync_time)) . ")" : ''; } else { $cron_sync_desc .= __('Cron sync is disabled.', WPFB); } $tools = array(array('url' => add_query_arg(array('action' => 'sync')), 'icon' => 'activity', 'label' => __('Sync Filebase', WPFB), 'desc' => __('Synchronises the database with the file system. Use this to add FTP-uploaded files.', WPFB) . '<br />' . $cron_sync_desc)); if (current_user_can('install_plugins')) { // is admin? $new_tag = self::NewExtensionsAvailable() ? '<span class="wp-ui-notification new-exts">new</span>' : ''; $tools[] = array('url' => add_query_arg(array('action' => 'install-extensions')), 'icon' => 'plug', 'label' => __('Extensions', WPFB) . $new_tag, 'desc' => __('Install Extensions to extend functionality of WP-Filebase', WPFB)); } ?> <div id="wpfb-tools"> <h2><?php _e('Tools'); ?> </h2> <ul> <?php foreach ($tools as $id => $tool) { ?> <li id="wpfb-tool-<?php echo $id; ?> "><a href="<?php echo $tool['url']; ?> " <?php if (!empty($tool['confirm'])) { ?> onclick="return confirm('<?php echo $tool['confirm']; ?> ')" <?php } ?> class="button"><span style="background-image:url(<?php echo esc_attr(WPFB_PLUGIN_URI); ?> images/<?php echo $tool['icon']; ?> .png)"></span><?php echo $tool['label']; ?> </a></li> <?php } ?> </ul> <?php foreach ($tools as $id => $tool) { ?> <div id="wpfb-tool-desc-<?php echo $id; ?> " class="tool-desc"> <?php echo $tool['desc']; ?> </div> <?php } ?> <script> if(!jQuery(document.body).hasClass('mobile')) { jQuery('#wpfb-tools li').mouseenter(function(e) { jQuery('#wpfb-tools .tool-desc').hide(); jQuery('#wpfb-tool-desc-'+this.id.substr(10)).show(); }); } </script> <?php if (!empty(WPFB_Core::$settings->tag_conv_req)) { ?> <p><a href="<?php echo add_query_arg('action', 'convert-tags'); ?> " class="button"><?php _e('Convert old Tags', WPFB); ?> </a> <?php printf(__('Convert tags from versions earlier than %s.', WPFB), '0.2.0'); ?> </p> <?php } ?> <!-- <p><a href="<?php echo add_query_arg('action', 'add-urls'); ?> " class="button"><?php _e('Add multiple URLs', WPFB); ?> </a> <?php _e('Add multiple remote files at once.', WPFB); ?> </p> --> </div> <div style="clear: both;"></div> <?php if (WPFB_Core::CurUserCanUpload()) { WPFB_Admin::PrintForm('file', null, array('exform' => $exform)); } ?> <?php if (!$show_how_start) { // display how start here if its hidden wpfb_call('AdminHowToStart', 'Display'); } ?> <h2><?php _e('About'); ?> </h2> <p> <?php echo WPFB_PLUGIN_NAME . ' ' . WPFB_VERSION; ?> by Fabian Schlieper <a href="http://fabi.me/"> <?php if (strpos($_SERVER['SERVER_PROTOCOL'], 'HTTPS') === false) { ?> <img src="http://fabi.me/misc/wpfb_icon.gif?lang=<?php if (defined('WPLANG')) { echo WPLANG; } ?> " alt="" /><?php } ?> fabi.me</a><br/> Includes the great file analyzer <a href="http://www.getid3.org/">getID3()</a> by James Heinrich.<br /> Tools Icons by <a href="http://www.icondeposit.com/">Matt Gentile</a>. </p> <?php if (current_user_can('edit_files')) { ?> <p><a href="<?php echo admin_url('plugins.php?wpfb-uninstall=1'); ?> " class="button"><?php _e('Completely Uninstall WP-Filebase'); ?> </a></p> <?php } break; case 'convert-tags': ?> <h2><?php _e('Tag Conversion'); ?> </h2><?php if (empty($_REQUEST['doit'])) { echo '<div class="updated"><p>'; _e('<strong>Important:</strong> before updating, please <a href="http://codex.wordpress.org/WordPress_Backups">backup your database and files</a>. For help with updates, visit the <a href="http://codex.wordpress.org/Updating_WordPress">Updating WordPress</a> Codex page.'); echo '</p></div>'; echo '<p><a href="' . add_query_arg('doit', 1) . '" class="button">' . __('Continue') . '</a></p>'; break; } $result = wpfb_call('Setup', 'ConvertOldTags'); ?> <p><?php printf(__('%d Tags in %d Posts has been converted.'), $result['n_tags'], count($result['tags'])); ?> </p> <ul> <?php if (!empty($result['tags'])) { foreach ($result['tags'] as $post_title => $tags) { echo "<li><strong>" . esc_html($post_title) . "</strong><ul>"; foreach ($tags as $old => $new) { echo "<li>{$old} => {$new}</li>"; } echo "</ul></li>"; } } ?> </ul> <?php if (!empty($result['errors'])) { ?> <h2><?php _e('Errors'); ?> </h2> <ul><?php foreach ($result['errors'] as $post_title => $err) { echo "<li><strong>" . esc_html($post_title) . ": </strong> " . esc_html($err) . "<ul>"; } ?> </ul> <?php } $opts = WPFB_Core::GetOpt(); unset($opts['tag_conv_req']); update_option(WPFB_OPT_NAME, $opts); WPFB_Core::$settings = (object) $opts; break; // convert-tags // convert-tags case 'del': if (!empty($_REQUEST['files']) && WPFB_Core::CurUserCanUpload()) { $ids = explode(',', $_REQUEST['files']); $nd = 0; foreach ($ids as $id) { $id = intval($id); if (($file = WPFB_File::GetFile($id)) != null && $file->CurUserCanEdit()) { $file->Remove(true); $nd++; } } WPFB_File::UpdateTags(); echo '<div id="message" class="updated fade"><p>' . sprintf(__('%d Files removed'), $nd) . '</p></div>'; } if (!empty($_REQUEST['cats']) && WPFB_Core::CurUserCanCreateCat()) { $ids = explode(',', $_REQUEST['cats']); $nd = 0; foreach ($ids as $id) { $id = intval($id); if (($cat = WPFB_Category::GetCat($id)) != null) { $cat->Delete(); $nd++; } } echo '<div id="message" class="updated fade"><p>' . sprintf(__('%d Categories removed'), $nd) . '</p></div>'; } case 'sync': echo '<h2>' . __('Synchronisation') . '</h2>'; wpfb_loadclass('Sync'); $result = WPFB_Sync::Sync(!empty($_GET['hash_sync']), true); if (!is_null($result)) { WPFB_Sync::PrintResult($result); } if (empty($_GET['hash_sync'])) { echo '<p><a href="' . add_query_arg('hash_sync', 1) . '" class="button">' . __('Complete file sync', WPFB) . '</a> ' . __('Checks files for changes, so more reliable but might take much longer. Do this if you uploaded/changed files with FTP.', WPFB) . '</p>'; } break; // sync // sync case 'batch-upload': wpfb_loadclass('BatchUploader'); $batch_uploader = new WPFB_BatchUploader(); $batch_uploader->Display(); break; case 'reset-hits': global $wpdb; $n = 0; if (current_user_can('manage_options')) { $n = $wpdb->query("UPDATE `{$wpdb->wpfilebase_files}` SET file_hits = 0 WHERE 1=1"); } echo "<p>"; printf(__('Done. %d Files affected.'), $n); echo "</p>"; break; case 'install-extensions': wpfb_call('AdmInstallExt', 'Display'); break; } // switch ?> </div> <!-- wrap --> <?php }
static function Display() { global $wpdb, $user_ID; require_once ABSPATH . 'wp-admin/includes/dashboard.php'; wpfb_loadclass('AdminDashboard'); add_thickbox(); wp_enqueue_script('dashboard'); if (wp_is_mobile()) { wp_enqueue_script('jquery-touch-punch'); } //register_shutdown_function( create_function('','$error = error_get_last(); if( $error && $error[\'type\'] != E_STRICT ){print_r( $error );}else{return true;}') ); wpfb_loadclass('File', 'Category', 'Admin', 'Output'); $_POST = stripslashes_deep($_POST); $_GET = stripslashes_deep($_GET); $action = !empty($_POST['action']) ? $_POST['action'] : (!empty($_GET['action']) ? $_GET['action'] : ''); $clean_uri = remove_query_arg(array('message', 'action', 'file_id', 'cat_id', 'deltpl', 'hash_sync', 'doit', 'ids', 'files', 'cats', 'batch_sync')); // keep search keyword WPFB_Admin::PrintFlattrHead(); ?> <script type="text/javascript"> /* Liking/Donate Bar */ if(typeof(jQuery) != 'undefined') { jQuery(document).ready(function(){ if(getUserSetting("wpfilebase_hidesuprow",false) == 1) { jQuery('#wpfb-liking').hide(); jQuery('#wpfb-liking-toggle').addClass('closed'); } jQuery('#wpfb-liking-toggle').click(function(){ jQuery('#wpfb-liking').slideToggle(); jQuery(this).toggleClass('closed'); setUserSetting("wpfilebase_hidesuprow", 1-getUserSetting("wpfilebase_hidesuprow",false), 0); }); }); } </script> <div class="wrap"> <div id="icon-wpfilebase" class="icon32"><br /></div> <h2><?php echo WPFB_PLUGIN_NAME; ?> </h2> <?php switch ($action) { default: $clean_uri = remove_query_arg('pagenum', $clean_uri); $upload_dir = WPFB_Core::UploadDir(); $upload_dir_rel = str_replace(ABSPATH, '', $upload_dir); $chmod_cmd = "CHMOD " . WPFB_PERM_DIR . " " . $upload_dir_rel; if (!is_dir($upload_dir)) { $result = WPFB_Admin::Mkdir($upload_dir); if ($result['error']) { $error_msg = sprintf(__('The upload directory <code>%s</code> does not exists. It could not be created automatically because the directory <code>%s</code> is not writable. Please create <code>%s</code> and make it writable for the webserver by executing the following FTP command: <code>%s</code>', 'wp-filebase'), $upload_dir_rel, str_replace(ABSPATH, '', $result['parent']), $upload_dir_rel, $chmod_cmd); } else { wpfb_call('Setup', 'ProtectUploadPath'); } } elseif (!is_writable($upload_dir)) { $error_msg = sprintf(__('The upload directory <code>%s</code> is not writable. Please make it writable for PHP by executing the follwing FTP command: <code>%s</code>', 'wp-filebase'), $upload_dir_rel, $chmod_cmd); } if (!empty($error_msg)) { echo '<div class="error default-password-nag"><p>' . $error_msg . '</p></div>'; } if (!empty(WPFB_Core::$settings->tag_conv_req)) { echo '<div class="updated"><p><a href="' . add_query_arg('action', 'convert-tags') . '">'; _e('WP-Filebase content tags must be converted', 'wp-filebase'); echo '</a></p></div><div style="clear:both;"></div>'; } ?> <?php if (self::PluginHasBeenUsedAWhile(true)) { self::ProUpgradeNag(); } if (self::PluginHasBeenUsedAWhile()) { ?> <div id="wpfb-support-col"> <div id="wpfb-liking-toggle"></div> <h3><?php _e('Like WP-Filebase?', 'wp-filebase'); ?> </h3> <div id="wpfb-liking"> <!-- <div style="text-align: center;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwordpress.org%2Fextend%2Fplugins%2Fwp-filebase%2F&send=false&layout=button_count&width=150&show_faces=false&action=like&colorscheme=light&font&height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:140px; height:21px; display:inline-block; text-align:center;" <?php echo ' allowTransparency="true"'; ?> ></iframe></div> --> <div style="text-align: center;" ><a href="https://twitter.com/wpfilebase" class="twitter-follow-button" data-show-count="false">Follow @wpfilebase</a> <script type="text/javascript">!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script></div> <p>Please <a href="http://wordpress.org/support/view/plugin-reviews/wp-filebase">give it a good rating</a>.</p> <p>For Cloud support and lots of other advanced features consider an</p> <p style="text-align: center;"><a href="https://wpfilebase.com/?ref=dblike" class="button-primary">Upgrade to Pro</a></p> <p style="text-align: center;"><a href="http://demo.wpfilebase.com/?ref=dblike" class="button">Live Pro Demo</a></p> <p style="text-align:right;float:right;font-style:italic;">Thanks, Fabian</p> <!-- <div style="text-align: center;"> <?php //WPFB_Admin::PrintPayPalButton() ?> <?php //WPFB_Admin::PrintFlattrButton() ?> </div> --> </div> </div> <?php } ?> <div id="dashboard-widgets-wrap"> <?php wp_dashboard(); ?> </div><!-- dashboard-widgets-wrap --> <?php break; case 'convert-tags': ?> <h2><?php _e('Tag Conversion'); ?> </h2><?php if (empty($_REQUEST['doit'])) { echo '<div class="updated"><p>'; _e('<strong>Important:</strong> before updating, please <a href="http://codex.wordpress.org/WordPress_Backups">backup your database and files</a>. For help with updates, visit the <a href="http://codex.wordpress.org/Updating_WordPress">Updating WordPress</a> Codex page.'); echo '</p></div>'; echo '<p><a href="' . add_query_arg('doit', 1) . '" class="button">' . __('Continue') . '</a></p>'; break; } $result = wpfb_call('Setup', 'ConvertOldTags'); ?> <p><?php printf(__('%d Tags in %d Posts has been converted.'), $result['n_tags'], count($result['tags'])); ?> </p> <ul> <?php if (!empty($result['tags'])) { foreach ($result['tags'] as $post_title => $tags) { echo "<li><strong>" . esc_html($post_title) . "</strong><ul>"; foreach ($tags as $old => $new) { echo "<li>{$old} => {$new}</li>"; } echo "</ul></li>"; } } ?> </ul> <?php if (!empty($result['errors'])) { ?> <h2><?php _e('Errors'); ?> </h2> <ul><?php foreach ($result['errors'] as $post_title => $err) { echo "<li><strong>" . esc_html($post_title) . ": </strong> " . esc_html($err) . "<ul>"; } ?> </ul> <?php } $opts = WPFB_Core::GetOpt(); unset($opts['tag_conv_req']); update_option(WPFB_OPT_NAME, $opts); WPFB_Core::$settings = (object) $opts; break; // convert-tags // convert-tags case 'del': if (!empty($_REQUEST['files']) && WPFB_Core::CurUserCanUpload()) { $ids = explode(',', $_REQUEST['files']); $nd = 0; foreach ($ids as $id) { $id = intval($id); if (($file = WPFB_File::GetFile($id)) != null && $file->CurUserCanDelete()) { $file->Remove(true); $nd++; } } WPFB_File::UpdateTags(); echo '<div id="message" class="updated fade"><p>' . sprintf(__('%d Files removed'), $nd) . '</p></div>'; } if (!empty($_REQUEST['cats']) && WPFB_Core::CurUserCanCreateCat()) { $ids = explode(',', $_REQUEST['cats']); $nd = 0; foreach ($ids as $id) { $id = intval($id); if (($cat = WPFB_Category::GetCat($id)) != null) { $cat->Delete(); $nd++; } } echo '<div id="message" class="updated fade"><p>' . sprintf(__('%d Categories removed'), $nd) . '</p></div>'; } case 'sync': echo '<h2>' . __('Synchronisation') . '</h2>'; wpfb_loadclass('Sync'); $result = WPFB_Sync::Sync(!empty($_GET['hash_sync']), true); if (!is_null($result)) { WPFB_Sync::PrintResult($result); } if (empty($_GET['hash_sync'])) { echo '<p><a href="' . add_query_arg('hash_sync', 1) . '" class="button">' . __('Complete file sync', 'wp-filebase') . '</a> ' . __('Checks files for changes, so more reliable but might take much longer. Do this if you uploaded/changed files with FTP.', 'wp-filebase') . '</p>'; } if (empty($_GET['debug'])) { echo '<p><a href="' . add_query_arg('debug', 1) . '" class="button">' . __('Debug Sync', 'wp-filebase') . '</a> ' . __('Run to get more Debug Info in case Sync crashes', 'wp-filebase') . '</p>'; } break; // sync // sync case 'batch-upload': wpfb_loadclass('BatchUploader'); $batch_uploader = new WPFB_BatchUploader(); $batch_uploader->Display(); break; case 'reset-hits': global $wpdb; $n = 0; if (current_user_can('manage_options')) { $n = $wpdb->query("UPDATE `{$wpdb->wpfilebase_files}` SET file_hits = 0 WHERE 1=1"); } echo "<p>"; printf(__('Done. %d Files affected.'), $n); echo "</p>"; break; case 'install-extensions': wpfb_call('AdmInstallExt', 'Display'); break; } // switch if (!empty($_GET['action'])) { echo '<p><a href="' . $clean_uri . '" class="button">' . __('Go back') . '</a></p>'; } ?> </div> <!-- wrap --> <?php }
?> </label> <?php } ?> <div id="cat_perm_wrap" <?php if (!$update) { echo 'class="hidden"'; } ?> > <?php _e('Limit category access by selecting one or more user roles.', WPFB); ?> <div id="cat_user_roles"><?php WPFB_Admin::RolesCheckList('cat_user_roles', $user_roles); ?> </div> </div> </td> </tr> <?php if ($update) { ?> <tr> <th scope="row" valign="top"><label for="cat_child_apply_perm"><?php _e('Apply permission to all child files', WPFB); ?> </label></th>
/** * @depends testCreateCatAndFile */ function testCreateTree() { $this->testSetUser(); wpfb_loadclass('Admin'); WPFB_Category::DisableBubbling(false); /** @var WPFB_Category $parent */ $parent = null; /** @var WPFB_Category[] $cats */ $cats = array(); for ($d = 0; $d < 4; $d++) { $res = WPFB_Admin::InsertCategory(array('cat_name' => "layer {$d}", 'cat_parent' => $parent ? $parent->GetId() : 0)); $this->assertEmpty($res['error'], $res['error']); /** @var WPFB_Category $cat */ $cat = $res['cat']; $this->assertTrue($parent ? $cat->GetParent()->Equals($parent) : is_null($cat->GetParent())); $this->assertTrue(is_dir($cat->GetLocalPath())); $cats[] = $cat; $parent = $cat; } $this->assertEquals($cats[0]->cat_id, $cats[1]->GetParent()->cat_id); //$this->assertEquals($cats[2]->GetParent(), $cats[1], '', 0.0, 2, true); // print_r(array_map( function($c) { return strval($c);}, $cats)); $files = new TestFileSet(); $res = WPFB_Admin::InsertFile(array('file_remote_uri' => 'file://' . $files->getImageBanner(), 'file_category' => $parent)); $this->assertEmpty($res['error'], $res['error']); /** @var WPFB_File $file01 */ $file01 = $res['file']; $res = WPFB_Admin::InsertFile(array('file_remote_uri' => 'file://' . $files->getSmallTxt(), 'file_category' => $parent->GetParent())); $this->assertEmpty($res['error'], $res['error']); /** @var WPFB_File $file02 */ $file02 = $res['file']; $this->assertEquals($file01->GetParent()->cat_id, $parent->cat_id); $this->assertEquals($file02->GetParent()->cat_id, $parent->GetParent()->cat_id); $this->assertEquals($file02->GetParent(), $parent->GetParent()); $this->assertEquals(2, $parent->GetParent()->cat_num_files_total); $this->assertEquals(2, $file02->GetParent()->cat_num_files_total); $this->assertEquals(1, $file02->GetParent()->cat_num_files); $this->assertEquals(2, $cats[0]->cat_num_files_total); $this->assertEquals(1, count($parent->GetParent()->GetChildCats(true))); $this->assertEquals(1, count($file02->GetParent()->GetChildCats(true))); $this->assertEquals(2, count($cats[0]->GetChildFiles(true)), $cats[0]); $this->assertEquals(3, count($cats[0]->GetChildCats(true)), $cats[0]); $this->assertEquals(2, count($cats[2]->GetChildFiles(true)), $cats[2]); $this->assertEquals(1, count($cats[2]->GetChildCats(true)), $cats[2]); $this->assertEquals(2, count($cats[1]->GetChildCats(true)), $cats[1]); $this->assertEquals(2, count($cats[1]->GetChildFiles(true)), $cats[1]); $res = $parent->Delete(); $this->assertEmpty($res['error'], $res['error']); unset($cats[3]); $file01->DBReload(); // TODO fix: need to reload from DB! $this->assertFileExists($file01->GetLocalPath()); $this->assertFileExists($file01->GetThumbPath()); // print_r(array_map( function($c) { return strval($c);}, $cats)); $this->assertEquals(strval($file01->GetParent()), strval($file02->GetParent())); $this->assertEquals(0, count($cats[2]->DBReload()->GetChildCats(true)), $cats[2]); $this->assertEquals(2, count($cats[2]->GetChildFiles(false)), $cats[2]); $this->assertEquals(1, count($cats[1]->DBReload()->GetChildCats(true)), $cats[1]); $this->assertEquals(2, count($cats[1]->GetChildFiles(true)), $cats[1]); $this->assertEquals(2, count($cats[0]->DBReload()->GetChildCats(true)), $cats[0]); $this->assertEquals(2, count($cats[0]->GetChildFiles(true)), $cats[0]); foreach ($cats as $cat) { $res = $cat->DBReload()->Delete(); $this->assertEmpty($res['error'], $res['error']); } $thumb = $file01->GetThumbPath(); $this->assertTrue($file01->DBReload()->Delete()); $this->assertTrue($file02->DBReload()->Delete()); $this->assertFileNotExists($thumb); }
static function DisplayUploadPresets($prefix, $cat_select = true) { $defaults = array('display_name' => '', 'category' => 0, 'tags' => '', 'description' => '', 'version' => '', 'author' => '', 'license' => '', 'post_id' => 0, 'languages' => '', 'offline' => 0, 'user_roles' => '', 'direct_linking' => 1, 'platforms' => '', 'requirements' => ''); ?> <table class="form-table"> <?php if ($cat_select) { ?> <tr class="form-field"> <th scope="row"><label for="batch_category"><?php _e('Category'); ?> </label></th> <td><select name="file_category" id="<?php echo $prefix; ?> _category" class="wpfb-cat-select"> <?php echo WPFB_Output::CatSelTree(array('selected' => $defaults['category'], 'add_cats' => true)); ?> </select> </td> </tr> <?php } ?> <tr class="form-field"> <th scope="row"><label for="batch_tags"><?php _e('Tags'); ?> </label></th> <td><input name="file_tags" id="<?php echo $prefix; ?> _tags" type="text" value="<?php echo esc_attr(trim($defaults['tags'], ',')); ?> " maxlength="250" autocomplete="off" /></td> </tr> <tr class="form-field"> <th scope="row"><label for="batch_description"><?php _e('Description'); ?> </label></th> <td><textarea name="file_description" id="<?php echo $prefix; ?> _description" rows="2"><?php echo esc_html($defaults['description']); ?> </textarea></td> </tr> <tr class="form-field"> <th scope="row"><label for="batch_author"><?php _e('Author'); ?> </label></th> <td><input name="file_author" id="<?php echo $prefix; ?> _author" type="text" value="<?php echo esc_attr($defaults['author']); ?> " /></td> </tr> <?php if (WPFB_Core::$settings->licenses) { ?> <tr class="form-field"> <th scope="row"><label for="batch_license"><?php _e('License', 'wp-filebase'); ?> </label></th> <td><select id="<?php echo $prefix; ?> _license" name="file_license"><?php echo WPFB_Admin::MakeFormOptsList('licenses', $defaults['license'], true); ?> </select></td> </tr> <?php } ?> <tr class="form-field"> <th scope="row"><label for="<?php echo $prefix; ?> _post_id"><?php _e('Attach to Post', 'wp-filebase'); ?> </label></th> <td>ID: <input type="text" name="file_post_id" class="num" style="width:60px; text-align:right;" id="<?php echo $prefix; ?> _post_id" value="<?php echo esc_attr($defaults['post_id']); ?> " /> <span id="<?php echo $prefix; ?> _post_title" style="font-style:italic;"><?php if ($defaults['post_id'] > 0) { echo get_the_title($defaults['post_id']); } ?> </span> <a href="javascript:;" class="button" onclick="WPFB_PostBrowser('<?php echo $prefix; ?> _post_id', '<?php echo $prefix; ?> _post_title');"><?php _e('Select'); ?> </a></td> </tr> <tr> <td></td> <td><input type="checkbox" name="file_offline" id="<?php echo $prefix; ?> _offline" value="1" <?php checked('1', $defaults['offline']); ?> /> <label for="<?php echo $prefix; ?> _offline" style="display: inline;"><?php _e('Don\'t publish uploaded files (set offline)', 'wp-filebase'); ?> </label></td> </tr> <?php /*ADV_BATCH_UPLOADER*/ ?> </table> <?php }
static function OnActivateOrVerChange($old_ver = null) { global $wpdb; // make sure that either wp-filebase or wp-filebase pro is enabled bot not both! if (!function_exists('is_plugin_active')) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } if (is_plugin_active('wp-filebase-pro/wp-filebase.php')) { deactivate_plugins('wp-filebase/wp-filebase.php'); } wpfb_loadclass('Admin', 'File', 'Category'); self::SetupDBTables($old_ver); $old_options = get_option(WPFB_OPT_NAME); self::AddOptions(); self::AddTpls($old_ver); $new_options = get_option(WPFB_OPT_NAME); WPFB_Admin::SettingsUpdated($old_options, $new_options); self::ProtectUploadPath(); WPFB_Admin::WPCacheRejectUri(WPFB_Core::$settings->download_base . '/', $old_options['download_base'] . '/'); $ncats = WPFB_Category::GetNumCats(); $nfiles = WPFB_File::GetNumFiles(); if ($ncats < self::MANY_CATEGORIES && $nfiles < self::MANY_FILES) { // avoid long activation time wpfb_loadclass('Sync'); WPFB_Sync::SyncCats(); WPFB_Sync::UpdateItemsPath(); } if (!wp_next_scheduled(WPFB . '_cron')) { wp_schedule_event(time(), 'hourly', WPFB . '_cron'); } if (!get_option('wpfb_install_time')) { add_option('wpfb_install_time', ($ft = (int) mysql2date('U', $wpdb->get_var("SELECT file_mtime FROM {$wpdb->wpfilebase_files} ORDER BY file_mtime ASC LIMIT 1"))) > 0 ? $ft : time(), null, 'no'); } // move old css if (file_exists(WPFB_Core::GetOldCustomCssPath())) { $wp_upload = wp_upload_dir(); $wp_upload_ok = empty($wp_upload['error']) && is_writable($wp_upload['basedir']); if ($wp_upload_ok && @rename(WPFB_Core::GetOldCustomCssPath(), $wp_upload['basedir'] . '/wp-filebase.css')) { update_option('wpfb_css', $wp_upload['baseurl'] . '/wp-filebase.css?t=' . time()); } } flush_rewrite_rules(); //delete_option('wpfilebase_dismiss_support_ending'); }
static function AddNewFiles($sync_data, $progress_bar = null, $max_batch_size = 0) { self::PrintDebugTrace(); $keys = array_keys($sync_data->new_files); $upload_dir = self::cleanPath(WPFB_Core::UploadDir()); $upload_dir_len = strlen($upload_dir); $batch_size = 0; $start_time = $cur_time = time(); foreach ($keys as $i) { $fn = $sync_data->new_files[$i]; $rel_path = substr($fn, $upload_dir_len); unset($sync_data->new_files[$i]); if (empty($fn)) { continue; } // skip files that where already added, for some reason if (is_null($ex_file = WPFB_Item::GetByPath($rel_path))) { self::PrintDebugTrace("add_existing_file:{$fn}"); $res = WPFB_Admin::AddExistingFile($fn, empty($sync_data->thumbnails[$fn]) ? null : $sync_data->thumbnails[$fn]); self::PrintDebugTrace("added_existing_file"); if (empty($res['error'])) { $sync_data->log['added'][] = empty($res['file']) ? substr($fn, $upload_dir_len) : $res['file']; $sync_data->known_filenames[] = $rel_path; if (!empty($res['file']) && $res['file']->GetThumbPath()) { $sync_data->known_filenames[] = substr(self::cleanPath($res['file']->GetThumbPath()), $upload_dir_len); } } else { $sync_data->log['error'][] = $res['error'] . " (file {$fn})"; } } else { //$res = array('file' => $ex_file); $sync_data->log['added'][] = $ex_file; $sync_data->known_filenames[] = $rel_path; } $sync_data->num_files_processed++; if (!empty($progress_bar)) { $progress_bar->step(); } if (!empty($res['file'])) { $batch_size += $res['file']->file_size; if ($max_batch_size > 0 && $batch_size > $max_batch_size) { return false; } } } if (!empty($progress_bar)) { $progress_bar->complete(); } return true; }
static function TplForm($type, $tpl_tag = null) { $new = empty($tpl_tag); $cat = $type == 'cat'; $list = $type == 'list'; $code_id = 'tplinp_' . $type; if (!$list) { if ($new) { $tpl_code = empty($_POST['tplcode']) ? '' : $_POST['tplcode']; } else { $tpl_code = WPFB_Core::GetTpls($type, $tpl_tag); if (empty($tpl_code)) { $tpl_code = ''; } } $item = $cat ? self::$sample_cat : self::$sample_file; } else { $tpl = $new ? new WPFB_ListTpl() : WPFB_ListTpl::Get($tpl_tag); } ?> <h2><?php $new ? _e('Add Template', 'wp-filebase') : _e('Edit Template', 'wp-filebase'); if (!empty($tpl_tag)) { echo ' ' . self::TplTitle($tpl_tag); } ?> </h2> <form action="<?php echo remove_query_arg(array('action', 'type', 'tpl')) . '#' . $type; ?> " method="post"> <?php wp_nonce_field(($new ? 'add' : 'update') . '-' . $type, 'wpfb-tpl-nonce'); ?> <input type="hidden" name="action" value="<?php echo $new ? 'add' : 'update'; ?> " /> <input type="hidden" name="type" value="<?php echo $type; ?> " /> <?php if ($new) { ?> <p> <label for="tpltag"><?php _e('Template Tag (a single word to describe the template):', 'wp-filebase'); ?> </label> <input type="text" name="tpltag" value="<?php if (!empty($_POST['tpltag'])) { echo esc_attr($_POST['tpltag']); } ?> " tabindex="1" maxlength="20" /> </p> <?php } else { ?> <input type="hidden" name="tpltag" value="<?php echo esc_attr($tpl_tag); ?> " /><?php } if ($list) { ?> <table class="form-table"> <tr class="form-field"> <th scope="row" valign="top"><label for="tpl-list-header"><?php _e('Header', 'wp-filebase'); ?> </label></th> <td width="100%"> <textarea id="tpl-list-header" name="tpl-list-header" cols="70" rows="<?php echo max(2, count(explode("\n", $tpl->header))) + 3; ?> " wrap="off" class="codepress html wpfilebase-tpledit" onkeyup="WPFB_PreviewTpl(this, '<?php echo $type; ?> ')" onchange="WPFB_PreviewTpl(this, '<?php echo $type; ?> ')"><?php echo htmlspecialchars($tpl->header); ?> </textarea><br /> </td> </tr> <tr class="form-field"> <th scope="row" valign="top"><label for="tpl-list-cat-tpl"><?php _e('Category Template', 'wp-filebase'); ?> </label></th> <td width=""> <select id="tpl-list-cat-tpl" name="tpl-list-cat-tpl" onchange="WPFB_PreviewTpl(this, '<?php echo $type; ?> ')"><?php echo WPFB_Admin::TplDropDown('cat', $tpl->cat_tpl_tag); ?> </select> </td> </tr> <tr class="form-field"> <th scope="row" valign="top"><label for="tpl-list-file-tpl"><?php _e('File Template', 'wp-filebase'); ?> </label></th> <td> <select id="tpl-list-file-tpl" name="tpl-list-file-tpl" onchange="WPFB_PreviewTpl(this, '<?php echo $type; ?> ')"><?php echo WPFB_Admin::TplDropDown('file', $tpl->file_tpl_tag); ?> </select> </td> </tr> <tr class="form-field"> <th scope="row" valign="top"><label for="tpl-list-footer"><?php _e('Footer', 'wp-filebase'); ?> </label></th> <td> <textarea id="tpl-list-footer" name="tpl-list-footer" cols="70" rows="<?php echo max(2, count(explode("\n", $tpl->footer))) + 3; ?> " wrap="off" class="codepress html wpfilebase-tpledit" onkeyup="WPFB_PreviewTpl(this, '<?php echo $type; ?> ')" onchange="WPFB_PreviewTpl(this, '<?php echo $type; ?> ')"><?php echo htmlspecialchars($tpl->footer); ?> </textarea><br /> </td> </tr> </table> <?php } else { ?> <p> <?php _e('Template Code:', 'wp-filebase'); ?> <br /> <textarea id="<?php echo $code_id; ?> " cols="70" rows="<?php echo max(2, count(explode("\n", $tpl_code))) + 3; ?> " wrap="off" name="tplcode" class="codepress html wpfilebase-tpledit" onkeyup="WPFB_PreviewTpl(this, '<?php echo $type; ?> ')" onchange="WPFB_PreviewTpl(this, '<?php echo $type; ?> ')"><?php echo htmlspecialchars($tpl_code); ?> </textarea><br /> <?php wpfb_loadclass('Models'); echo WPFB_Models::TplFieldsSelect($code_id, false, $cat); ?> </p> <?php } ?> <p class="submit"><input type="submit" name="submit" class="button-primary" value="<?php echo esc_attr__($new ? 'Add Template' : 'Submit Template Changes', 'wp-filebase'); ?> " /></p> </form> <div class="entry-content wpfilebase-tpl-preview"> <div id="<?php echo $code_id; ?> _preview"><?php if ($list) { echo $tpl->Sample(self::$sample_cat, self::$sample_file); } else { echo empty($tpl_code) ? '<i>' . __('Preview') . '</i>' : $item->GenTpl(WPFB_TplLib::Parse($tpl_code), 'sample'); } ?> </div> <div style="height: 50px; float: left;"></div> <div class="clear"></div> </div> <?php }
function ChangeCategoryOrName($new_cat_id, $new_name = null, $add_existing = false, $overwrite = false) { // 1. apply new values (inherit permissions if nothing (Everyone) set!) // 2. check for name collision and rename // 3. move stuff // 4. notify parents // 5. update child paths if (empty($new_name)) { $new_name = $this->GetName(); } $this->Lock(true); $new_cat_id = intval($new_cat_id); $old_cat_id = $this->GetParentId(); $old_path_rel = $this->GetLocalPathRel(true); $old_path = $this->GetLocalPath(); $old_name = $this->GetName(); if ($this->is_file) { $old_thumb_path = $this->GetThumbPath(); } $old_cat = $this->GetParent(); $new_cat = WPFB_Category::GetCat($new_cat_id); if (!$new_cat) { $new_cat_id = 0; } $cat_changed = $new_cat_id != $old_cat_id; if ($cat_changed && $new_cat_id > 0 && $this->IsAncestorOf($new_cat)) { return array('error' => __('Cannot move category into a sub-category of itself.', WPFB)); } if ($this->is_file) { $this->file_category = $new_cat_id; $this->file_name = $new_name; $this->file_category_name = $new_cat_id == 0 ? '' : $new_cat->GetTitle(); } else { $this->cat_parent = $new_cat_id; $this->cat_folder = $new_name; } // inherit user roles if (count($this->GetReadPermissions()) == 0) { $this->SetReadPermissions($new_cat_id != 0 ? $new_cat->GetReadPermissions() : WPFB_Core::$settings->default_roles); } // flush cache $this->last_parent_id = -1; $new_path_rel = $this->GetLocalPathRel(true); $new_path = $this->GetLocalPath(); if ($new_path_rel != $old_path_rel) { $i = 1; if (!$add_existing) { $name = $this->GetName(); if ($overwrite) { if (@file_exists($new_path)) { $ex_file = WPFB_File::GetByPath($new_path_rel); if (!is_null($ex_file)) { $ex_file->Remove(); } else { @unlink($new_path); } } } else { // rename item if filename collision (ignore if coliding with $this) while (@file_exists($new_path) || !is_null($ex_file = WPFB_File::GetByPath($new_path_rel)) && !$this->Equals($ex_file)) { $i++; if ($this->is_file) { $p = strrpos($name, '.'); $this->file_name = $p <= 0 ? "{$name}({$i})" : substr($name, 0, $p) . "({$i})" . substr($name, $p); } else { $this->cat_folder = "{$name}({$i})"; } $new_path_rel = $this->GetLocalPathRel(true); $new_path = $this->GetLocalPath(); } } } // finally move it! if (!empty($old_name) && @file_exists($old_path)) { if ($this->is_file && $this->IsLocal()) { if (!@rename($old_path, $new_path)) { return array('error' => sprintf('Unable to move file %s!', $old_path)); } @chmod($new_path, octdec(WPFB_PERM_FILE)); } else { if (!@is_dir($new_path)) { wp_mkdir_p($new_path); } wpfb_loadclass('FileUtils'); if (!@WPFB_FileUtils::MoveDir($old_path, $new_path)) { return array('error' => sprintf('Could not move folder %s to %s', $old_path, $new_path)); } } } else { if ($this->is_category) { if (!@is_dir($new_path) && !wp_mkdir_p($new_path)) { return array('error' => sprintf(__('Unable to create directory %s. Is it\'s parent directory writable?'), $new_path)); } } } // move thumb if ($this->is_file && !empty($old_thumb_path) && @is_file($old_thumb_path)) { $thumb_path = $this->GetThumbPath(); if ($i > 1) { $p = strrpos($thumb_path, '-'); if ($p <= 0) { $p = strrpos($thumb_path, '.'); } $thumb_path = substr($thumb_path, 0, $p) . "({$i})" . substr($thumb_path, $p); $this->file_thumbnail = basename($thumb_path); } if (!is_dir(dirname($thumb_path))) { WPFB_Admin::Mkdir(dirname($thumb_path)); } if (!@rename($old_thumb_path, $thumb_path)) { return array('error' => 'Unable to move thumbnail! ' . $thumb_path); } @chmod($thumb_path, octdec(WPFB_PERM_FILE)); } $all_files = $this->is_file || $this->GetId() > 0 ? $this->GetChildFiles(true) : array(); // all children files (recursively) if (!empty($all_files)) { foreach ($all_files as $file) { if ($cat_changed) { if ($old_cat) { $old_cat->NotifyFileRemoved($file); } // notify parent cat to remove files if ($new_cat) { $new_cat->NotifyFileAdded($file); } } $file->GetLocalPathRel(true); // update file's path } } unset($all_files); if ($this->is_category && $this->GetId() > 0) { $cats = $this->GetChildCats(true); if (!empty($cats)) { foreach ($cats as $cat) { $cat->GetLocalPathRel(true); // update cats's path } } unset($cats); } } $this->Lock(false); if (!$this->locked) { $this->DBSave(); } return array('error' => false); /* * // create the directory if it doesnt exist // move file if($this->IsLocal() && !empty($old_file_path) && @is_file($old_file_path) && $new_file_path != $old_file_path) { if(!@rename($old_file_path, $new_file_path)) return array( 'error' => sprintf('Unable to move file %s!', $this->GetLocalPath())); @chmod($new_file_path, octdec(WPFB_PERM_FILE)); } */ }
function CreateThumbnail($src_image = '', $del_src = false) { wpfb_loadclass('FileUtils'); $src_set = !empty($src_image) && file_exists($src_image); $tmp_src = $del_src; if (!$src_set) { if (file_exists($this->GetLocalPath())) { $src_image = $this->GetLocalPath(); } elseif ($this->IsRemote()) { // if remote file, download it and use as source $res = wpfb_call('Admin', 'SideloadFile', $this->GetRemoteUri()); $src_image = $res['file']; $tmp_src = true; } } if (!file_exists($src_image) || @filesize($src_image) < 3) { if ($tmp_src) { @unlink($src_image); } return; } $ext = trim($this->GetExtension(), '.'); $src_size = array(); if (!WPFB_FileUtils::FileHasImageExt($this->file_name) && !($src_set && WPFB_FileUtils::IsValidImage($src_image, $src_size))) { // check if valid image if ($tmp_src) { @unlink($src_image); } return; } $this->DeleteThumbnail(); // delete old thumbnail $thumb_size = (int) WPFB_Core::$settings->thumbnail_size; if ($thumb_size == 0) { if ($tmp_src) { @unlink($src_image); } return; } $thumb = WPFB_FileUtils::CreateThumbnail($src_image, $thumb_size); $success = !empty($thumb) && !is_wp_error($thumb) && is_string($thumb) && file_exists($thumb); if (!$src_set && !$success) { $this->file_thumbnail = null; } else { // fallback to source image WARNING: src img will be moved or deleted! if ($src_set && !$success) { $thumb = $src_image; } $this->file_thumbnail = basename(trim($thumb, '.')); // FIX: need to trim . when image has no extension if (!is_dir(dirname($this->GetThumbPath()))) { WPFB_Admin::Mkdir(dirname($this->GetThumbPath())); } if (!@rename($thumb, $this->GetThumbPath())) { $this->file_thumbnail = null; @unlink($thumb); } else { @chmod($this->GetThumbPath(), octdec(WPFB_PERM_FILE)); } } if ($tmp_src) { @unlink($src_image); } }
static function OnActivateOrVerChange($old_ver = null) { global $wpdb; // make sure that either wp-filebase or wp-filebase pro is enabled bot not both! if (!function_exists('is_plugin_active')) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } if (is_plugin_active('wp-filebase-pro/wp-filebase.php')) { deactivate_plugins('wp-filebase/wp-filebase.php'); } wpfb_loadclass('Admin', 'File', 'Category'); self::SetupDBTables($old_ver); $old_options = get_option(WPFB_OPT_NAME); self::AddOptions(); self::AddTpls($old_ver); $new_options = get_option(WPFB_OPT_NAME); WPFB_Admin::SettingsUpdated($old_options, $new_options); self::ProtectUploadPath(); $sync_data_file = WPFB_Core::UploadDir() . '/._sync.data'; is_file($sync_data_file) && unlink($sync_data_file); WPFB_Admin::WPCacheRejectUri(WPFB_Core::$settings->download_base . '/', $old_options['download_base'] . '/'); // TODO, do this in background if (WPFB_Category::GetNumCats() < self::MANY_CATEGORIES && WPFB_File::GetNumFiles() < self::MANY_FILES) { // avoid long activation time wpfb_loadclass('Sync'); WPFB_Sync::SyncCats(); WPFB_Sync::UpdateItemsPath(); } if (!wp_next_scheduled(WPFB . '_cron')) { wp_schedule_event(time() + 20, 'hourly', WPFB . '_cron'); } if (!get_option('wpfb_install_time')) { add_option('wpfb_install_time', ($ft = (int) mysql2date('U', $wpdb->get_var("SELECT file_mtime FROM {$wpdb->wpfilebase_files} ORDER BY file_mtime ASC LIMIT 1"))) > 0 ? $ft : time(), null, 'no'); } $wp_upload = wp_upload_dir(); // move old css if (file_exists(WPFB_Core::GetOldCustomCssPath())) { $wp_upload_ok = empty($wp_upload['error']) && is_writable($wp_upload['basedir']); if ($wp_upload_ok && @rename(WPFB_Core::GetOldCustomCssPath(), $wp_upload['basedir'] . '/wp-filebase.css')) { update_option('wpfb_css', $wp_upload['baseurl'] . '/wp-filebase.css?t=' . time()); } } // refresh css URL (in case upload_dir changed or upgrade from free to pro) update_option('wpfb_css', trailingslashit(file_exists($wp_upload['basedir'] . '/wp-filebase.css') ? $wp_upload['baseurl'] : WPFB_PLUGIN_URI) . 'wp-filebase.css?t=' . time()); flush_rewrite_rules(); // change mapping of file browser folder icons (2340897_sdf.svg => svg-.....svg!) $image_mappings = array('1449888880_folder.svg' => 'svg-folder.svg', '1449888883_folder.svg' => 'svg-folder-blue.svg', '1449888885_folder-blue.svg' => 'svg-folderblue.svg', '1449888886_folder-green.svg' => 'svg-folder-green.svg'); $folder_icons_base = '/plugins/wp-filebase/images/folder-icons/'; $folder_icon = substr(WPFB_Core::$settings->folder_icon, strlen($folder_icons_base)); if (isset($image_mappings[$folder_icon])) { WPFB_Core::UpdateOption('folder_icon', $folder_icons_base . $image_mappings[$folder_icon]); } //delete_option('wpfilebase_dismiss_support_ending'); // fixes files that where offline if ($old_ver === "3.4.2") { $wpdb->query("UPDATE `{$wpdb->wpfilebase_files}` SET file_offline = '0' WHERE 1"); wpfb_loadclass('Sync'); WPFB_Sync::list_files(WPFB_Core::UploadDir()); } }
public static function SettingsUpdated($old, &$new) { $messages = array(); wpfb_call('Setup', 'ProtectUploadPath'); // custom fields: $messages = array_merge($messages, WPFB_Admin::SyncCustomFields()); if ($old['thumbnail_path'] != $new['thumbnail_path']) { update_option(WPFB_OPT_NAME, $old); // temporaly restore old settings WPFB_Core::$settings = (object) $old; $items = array_merge(WPFB_File::GetFiles2(), WPFB_Category::GetCats()); $old_thumbs = array(); foreach ($items as $i => $item) { $old_thumbs[$i] = $item->GetThumbPath(true); } update_option(WPFB_OPT_NAME, $new); // restore new settings WPFB_Core::$settings = (object) $new; $n = 0; foreach ($items as $i => $item) { if (!empty($old_thumbs[$i]) && is_file($old_thumbs[$i])) { $new_path = $item->GetThumbPath(true); $dir = dirname($new_path); if (!is_dir($dir)) { self::Mkdir($dir); } if (rename($old_thumbs[$i], $new_path)) { $n++; } else { $messages[] = sprintf(__('Could not move thumnail %s to %s.', WPFB), $old_thumbs[$i], $new_path); } } } if (count($n > 0)) { $messages[] = sprintf(__('%d Thumbnails moved.', WPFB), $n); } } flush_rewrite_rules(); return $messages; }
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 }
?> </label> <?php } ?> <div id="file_perm_wrap" <?php if (!$update) { echo 'class="hidden"'; } ?> > <?php _e('Limit file access by selecting one or more user roles.'); ?> <div id="file_user_roles"><?php WPFB_Admin::RolesCheckList('file_user_roles', $user_roles); ?> </div> </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>