Example #1
0
 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());
     }
 }
Example #2
0
 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');
 }
Example #3
0
 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('&nbsp;&nbsp; ', $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('&nbsp;&nbsp; ', $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;
 }
Example #4
0
    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 PluginHasBeenUsedAWhile($long_while = false)
 {
     global $wpdb;
     static $n = -1, $first_file_time = -1;
     if ($n === -1) {
         $n = WPFB_File::GetNumFiles();
         $first_file_time = mysql2date('U', $wpdb->get_var("SELECT file_date FROM {$wpdb->wpfilebase_files} ORDER BY file_date ASC LIMIT 1"));
     }
     if ($n < ($long_while ? 20 : 5)) {
         return false;
     }
     return $first_file_time > 1 && time() - $first_file_time > 86400 * ($long_while ? 20 : 4);
     // 4 days
 }
Example #6
0
 static function PluginHasBeenUsedAWhile()
 {
     global $wpdb;
     if (WPFB_File::GetNumFiles() < 5) {
         return false;
     }
     $first_file_time = mysql2date('U', $wpdb->get_var("SELECT file_date FROM {$wpdb->wpfilebase_files} ORDER BY file_date ASC LIMIT 1"));
     return $first_file_time > 1 && time() - $first_file_time > 86400 * 4;
     // 4 days
 }