function __construct() { wpfb_loadclass('Download', 'Admin'); $dir = WPFB_Core::UploadDir() . '/.tmp/'; WPFB_Admin::Mkdir($dir); $test_files = array('banner.png' => 'https://wpfilebase.com/wp-content/blogs.dir/2/files/2015/03/banner_023.png', 'small.txt' => 'https://wpfilebase.com/robots.txt'); $this->local_files = array(); foreach ($test_files as $f => $u) { $fn = $dir . $f; $this->local_files[$f] = $fn; if (file_exists($fn)) { continue; } echo "Downloading test file {$u}\n"; WPFB_Download::SideloadFile($u, $fn); } }
static function UnProtectUploadPath() { $dir = WPFB_Core::UploadDir(); if (!is_dir($dir)) { WPFB_Admin::Mkdir($dir); } $htaccess = "{$dir}/.htaccess"; if (is_file($htaccess)) { @unlink($htaccess); } return $htaccess; }
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)); } */ }
/** * 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; }
/** * 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; }
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 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 }