/** * Get category objects * * @access public * * @param int $id ID * @return WPFB_Category */ static function GetCat($id) { $id = intval($id); if ($id > 0 && (isset(self::$cache[$id]) || WPFB_Category::GetCats("WHERE cat_id = {$id}"))) { return self::$cache[$id]; } return null; }
function __construct($init = false) { if ($init) { $this->queryDbState(); $this->cats = WPFB_Category::GetCats(); $this->log = array('missing_files' => array(), 'missing_folders' => array(), 'changed' => array(), 'not_added' => array(), 'error' => array(), 'updated_categories' => array(), 'warnings' => array()); $this->new_files = array(); $this->missing_files = array(); $this->num_files_to_add = 0; $this->num_all_files = 0; $this->num_files_processed = 0; $this->time_begin = microtime(true); $this->mem_peak = memory_get_peak_usage(); } }
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; }
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; }
private static function catInfo($args) { wpfb_loadclass('Category', 'Output'); if (empty($args['id']) || !is_numeric($args['id'])) { die('-1'); } $cat = WPFB_Category::GetCat((int) $args['id']); if ($cat != null && $cat->CurUserCanAccess(true)) { wp_send_json(array('id' => $cat->GetId(), 'url' => $cat->GetUrl(), 'path' => $cat->GetLocalPathRel(), 'roles' => $cat->GetReadPermissions(), 'roles_str' => WPFB_Output::RoleNames($cat->GetReadPermissions(), true))); } else { echo '-1'; } }
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()); } }
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 WPFB_SyncData($init = false) { if ($init) { $this->files = WPFB_File::GetFiles2(); $this->cats = WPFB_Category::GetCats(); $this->log = array('missing_files' => array(), 'missing_folders' => array(), 'changed' => array(), 'not_added' => array(), 'error' => array(), 'updated_categories' => array(), 'warnings' => array()); $this->known_filenames = array(); $this->new_files = array(); $this->missing_files = array(); $this->num_files_to_add = 0; $this->num_all_files = 0; $this->num_files_processed = 0; $this->time_begin = microtime(true); $this->mem_peak = memory_get_peak_usage(); } }
function Delete() { global $wpdb; // TODO: error handling $cats = $this->GetChildCats(); $files = $this->GetChildFiles(); $parent_id = $this->GetParentId(); foreach ($cats as $cat) { $cat->ChangeCategoryOrName($parent_id); } foreach ($files as $file) { $file->ChangeCategoryOrName($parent_id); } self::$cache_complete = false; unset(self::$cache[0 + $this->cat_id]); // delete the category @unlink($this->GetLocalPath()); @rmdir($this->GetLocalPath()); $wpdb->query("DELETE FROM {$wpdb->wpfilebase_cats} WHERE cat_id = " . (int) $this->GetId()); return array('error' => false); }
static function WidgetStats() { global $wpdb; ?> <div id="col-container"> <div id="col-right"> <div class="col-wrap"> <h3><?php _e('Traffic', 'wp-filebase'); ?> </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) { WPFB_AdminGuiManage::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', 'wp-filebase'); ?> </th> </tr> <tr> <td><?php if ($limit_month > 0) { WPFB_AdminGuiManage::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', 'wp-filebase'); ?> </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', 'wp-filebase'); ?> </th> </tr> </table> </div> </div><!-- /col-right --> <div id="col-left"> <div class="col-wrap"> <h3><?php _e('Statistics', 'wp-filebase'); ?> </h3> <table class="wpfb-stats-table"> <tr> <td><?php echo WPFB_File::GetNumFiles(); ?> </td> <th scope="row"><?php _e('Files', 'wp-filebase'); ?> </th> </tr> <tr> <td><?php echo WPFB_Category::GetNumCats(); ?> </td> <th scope="row"><?php _e('Categories'); ?> </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', 'wp-filebase'); ?> </th> </tr> </table> </div> </div><!-- /col-left --> </div><!-- /col-container --> <?php }
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 }
private static function upload($args) { define('TMP_FILE_MAX_AGE', 3600 * 3); $frontend_upload = !empty($args['frontend_upload']) && $args['frontend_upload'] !== "false"; $file_add_now = !empty($args['file_add_now']) && $args['file_add_now'] !== "false"; // TODO: need to check if frontend_upload and user logged in state // Flash often fails to send cookies with the POST or upload, so we need to pass it in GET or POST instead if (!is_user_logged_in()) { if (is_ssl() && empty($_COOKIE[SECURE_AUTH_COOKIE]) && !empty($_REQUEST['auth_cookie'])) { $_COOKIE[SECURE_AUTH_COOKIE] = $_REQUEST['auth_cookie']; } elseif (empty($_COOKIE[AUTH_COOKIE]) && !empty($_REQUEST['auth_cookie'])) { $_COOKIE[AUTH_COOKIE] = $_REQUEST['auth_cookie']; } if (empty($_COOKIE[LOGGED_IN_COOKIE]) && !empty($_REQUEST['logged_in_cookie'])) { $_COOKIE[LOGGED_IN_COOKIE] = $_REQUEST['logged_in_cookie']; } if (!empty($_REQUEST['auth_cookie']) || !empty($_REQUEST['logged_in_cookie'])) { wp_set_current_user(wp_validate_auth_cookie()); } } wpfb_loadclass('Category', 'File'); $parent_cat = empty($args['cat_id']) ? null : WPFB_Category::GetCat($args['cat_id']); if ($frontend_upload) { if ($file_add_now) { wpfb_ajax_die('Unsupported upload!'); } else { if (!WPFB_Core::$settings->frontend_upload && !current_user_can('upload_files')) { wpfb_ajax_die(__('You do not have permission to upload files.')); } } } else { if (!WPFB_Core::CurUserCanUpload() && !$parent_cat && !$parent_cat->CurUserCanAddFiles()) { wpfb_ajax_die(__('You do not have permission to upload files.')); } check_admin_referer(WPFB . '-async-upload'); } wpfb_loadclass('Admin'); if (!empty($args['delupload'])) { $del_upload = @json_decode($args['delupload']); if ($del_upload && is_file($tmp = WPFB_Core::UploadDir() . '/.tmp/' . str_replace(array('../', '.tmp/'), '', $del_upload->tmp_name))) { echo (int) @unlink($tmp); } // delete other old temp files require_once ABSPATH . 'wp-admin/includes/file.php'; $tmp_files = list_files(WPFB_Core::UploadDir() . '/.tmp'); foreach ($tmp_files as $tmp) { if (time() - filemtime($tmp) >= TMP_FILE_MAX_AGE) { @unlink($tmp); } } exit; } if (empty($_FILES['async-upload'])) { wpfb_ajax_die(__('No file was uploaded.', 'wp-filebase') . ' (ASYNC)'); } if (!is_uploaded_file($_FILES['async-upload']['tmp_name']) || !($tmp = WPFB_Admin::GetTmpFile($_FILES['async-upload']['name'])) || !move_uploaded_file($_FILES['async-upload']['tmp_name'], $tmp)) { wpfb_ajax_die(sprintf(__('“%s” has failed to upload due to an error'), esc_html($_FILES['async-upload']['name']))); } $_FILES['async-upload']['tmp_name'] = trim(substr($tmp, strlen(WPFB_Core::UploadDir())), '/'); $json = json_encode($_FILES['async-upload']); if ($file_add_now) { $file_data = array('file_flash_upload' => $json, 'file_category' => 0); if (!empty($args['presets'])) { $presets = array(); parse_str($args['presets'], $presets); WPFB_Admin::AdaptPresets($presets); $file_data = array_merge($file_data, $presets); } $result = WPFB_Admin::InsertFile($file_data, false); if (empty($result['error'])) { $resp = array_merge((array) $result['file'], array('file_thumbnail_url' => $result['file']->GetIconUrl(), 'file_edit_url' => $result['file']->GetEditUrl(), 'file_cur_user_can_edit' => $result['file']->CurUserCanEdit(), 'file_download_url' => $result['file']->GetUrl(), 'nonce' => wp_create_nonce(WPFB . '-updatefile' . $result['file_id']))); if (isset($args['tpl_tag'])) { $tpl_tag = $args['tpl_tag']; if ($tpl_tag === 'false') { $tpl_tag = null; } $resp['tpl'] = $result['file']->GenTpl2($tpl_tag); } } else { wpfb_ajax_die($result['error']); } $json = json_encode($resp); } header('Content-Type: application/json; charset=' . get_option('blog_charset')); //header('Content-Length: ' . strlen($json)); echo $json; }
<?php $update = isset($item) && is_object($item) && !empty($item->cat_id); if ($update) { $file_category =& $item; $exform = true; } else { $file_category = new WPFB_Category(); } $action = $update ? 'updatecat' : 'addcat'; $title = $update ? __('Edit Category') : __('Add Category', WPFB); /*def*/ $form_name = $update ? 'editcat' : 'addcat'; $nonce_action = WPFB . "-" . $action . ($update ? $file_category->cat_id : ''); $default_roles = WPFB_Core::$settings->default_roles; $user_roles = $update || empty($default_roles) ? $file_category->GetReadPermissions() : $default_roles; $cat_members_only = !empty($user_roles); $form_action = add_query_arg('page', 'wpfilebase_cats', remove_query_arg(array('cat_id', 'page', 'action'))); ?> <div class="wrap"> <h2><?php echo $title; ?> </h2> <div id="ajax-response"></div> <form enctype="multipart/form-data" method="post" name="<?php echo $form_name; ?> " id="<?php echo $form_name;
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 }
static function CatSelTree($args = null, $root_cat_id = 0, $depth = 0) { static $s_sel, $s_ex, $s_nol, $s_count, $s_add_cats; if (!is_null($args)) { if (is_array($args)) { $s_sel = empty($args['selected']) ? 0 : intval($args['selected']); $s_ex = empty($args['exclude']) ? 0 : intval($args['exclude']); $s_nol = empty($args['none_label']) ? 0 : $args['none_label']; $s_count = !empty($args['file_count']); $s_add_cats = !empty($args['add_cats']); } else { $s_sel = intval($args); $s_ex = 0; $s_nol = null; $s_count = false; $s_add_cats = false; } } $out = ''; if ($root_cat_id <= 0) { $out .= '<option value="0"' . (0 == $s_sel ? ' selected="selected"' : '') . ' style="font-style:italic;">' . (empty($s_nol) ? __('None') : $s_nol) . ($s_count ? ' (' . WPFB_File::GetNumFiles(0) . ')' : '') . '</option>'; $cats = WPFB_Category::GetCats(); foreach ($cats as $c) { if ($c->cat_parent <= 0 && $c->cat_id != $s_ex && $c->CurUserCanAccess()) { $out .= self::CatSelTree(null, $c->cat_id, 0); } } if ($s_add_cats) { $out .= '<option value="+0" class="add-cat">+ ' . __('Add Category', WPFB) . '</option>'; } } else { $cat = WPFB_Category::GetCat($root_cat_id); $out .= '<option value="' . $root_cat_id . '"' . ($root_cat_id == $s_sel ? ' selected="selected"' : '') . '>' . str_repeat(' ', $depth) . esc_html($cat->cat_name) . ($s_count ? ' (' . $cat->cat_num_files . ')' : '') . '</option>'; if ($s_add_cats) { $out .= '<option value="+' . $root_cat_id . '" class="add-cat">' . str_repeat(' ', $depth + 1) . '+ ' . __('Add Category', WPFB) . '</option>'; } if (isset($cat->cat_childs)) { foreach ($cat->cat_childs as $c) { if ($c->cat_id != $s_ex && $c->CurUserCanAccess()) { $out .= self::CatSelTree(null, $c->cat_id, $depth + 1); } } } } return $out; }
} } else { $file = WPFB_File::GetFile((int) $_REQUEST['id']); } if ($file != null && $file->CurUserCanAccess(true)) { wpfb_print_json(array('id' => $file->GetId(), 'url' => $file->GetUrl(), 'path' => $file->GetLocalPathRel())); } else { echo '-1'; } exit; case 'catinfo': wpfb_loadclass('Category', 'Output'); if (empty($_REQUEST['id']) || !is_numeric($_REQUEST['id'])) { die('-1'); } $cat = WPFB_Category::GetCat((int) $_REQUEST['id']); if ($cat != null && $cat->CurUserCanAccess(true)) { wpfb_print_json(array('id' => $cat->GetId(), 'url' => $cat->GetUrl(), 'path' => $cat->GetLocalPathRel(), 'roles' => $cat->GetReadPermissions(), 'roles_str' => WPFB_Output::RoleNames($cat->GetReadPermissions(), true))); } else { echo '-1'; } exit; case 'postbrowser': if (!current_user_can('edit_posts')) { wpfb_print_json(array(array('id' => '0', 'text' => __('Cheatin’ uh?'), 'classes' => '', 'hasChildren' => false))); exit; } $id = empty($_REQUEST['root']) || $_REQUEST['root'] == 'source' ? 0 : intval($_REQUEST['root']); $onclick = empty($_REQUEST['onclick']) ? '' : $_REQUEST['onclick']; $args = array('hide_empty' => 0, 'hierarchical' => 1, 'orderby' => 'name', 'parent' => $id); $terms = get_terms('category', $args);
/** * @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 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 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'); }
<?php define('FASTLOAD', true); require_once 'wpfb-load.php'; wpfb_loadclass('Core', 'File', 'Category', 'Download'); $item = null; if (isset($_GET['fid'])) { $fid = intval($_GET['fid']); if ($fid == 0) { $img_path = ABSPATH . WPINC . '/images/'; if (file_exists($img = $img_path . 'crystal/default.png') || file_exists($img = $img_path . 'default.png') || file_exists($img = $img_path . 'blank.gif')) { WPFB_Download::SendFile($img, array('cache_max_age' => -1)); } //was 3600 * 12 exit; } $item = WPFB_File::GetFile($fid); } elseif (isset($_GET['cid'])) { $item = WPFB_Category::GetCat(intval($_GET['cid'])); } if ($item == null || !$item->CurUserCanAccess(true)) { exit; } // if no thumbnail, redirect if (empty($item->file_thumbnail) && empty($item->cat_icon)) { header('Location: ' . $item->GetIconUrl()); exit; } // send thumbnail WPFB_Download::SendFile($item->GetThumbPath(), array('cache_max_age' => -1)); // was 3600 * 12
<?php if (!defined('WPFB')) { exit; } /* make sure we loaded the pluggable functions */ require ABSPATH . WPINC . '/pluggable.php'; define('WPFB_NO_CORE_INIT', true); wpfb_loadclass('Core', 'File', 'Category', 'Download'); $item = null; if (isset($_GET['fid'])) { $item = WPFB_File::GetFile(0 + $_GET['fid']); } elseif (isset($_GET['cid'])) { $item = WPFB_Category::GetCat(0 + $_GET['cid']); } if ($item == null || !$item->CurUserCanAccess(true)) { header('X-Fallback-Thumb: 1'); $img_path = ABSPATH . WPINC . '/images/'; if (file_exists($img = $img_path . 'crystal/default.png') || file_exists($img = $img_path . 'media/default.png')) { WPFB_Download::SendFile($img, array('cache_max_age' => -1)); //was 3600 * 12 } else { // single transparent pixel gif header('Content-Type: image/gif'); header('Cache-Control: public'); echo base64_decode('R0lGODlhAQABAJAAAP8AAAAAACH5BAUQAAAALAAAAAABAAEAAAICBAEAOw=='); } exit; } // if no thumbnail, redirect if (empty($item->file_thumbnail) && empty($item->cat_icon)) {