コード例 #1
0
ファイル: thumbnail.php プロジェクト: noxian/WP-Filebase
<?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)) {
コード例 #2
0
ファイル: wpfb_form_file.php プロジェクト: parsonsc/dofe
<?php

wpfb_loadclass('File');
$multi_edit = !empty($multi_edit);
$in_widget = !empty($in_widget);
$in_editor = !empty($in_editor);
$update = $multi_edit ? !empty($item) : isset($item) && is_object($item) && !empty($item->file_id);
$exform = $update || !empty($exform);
if (empty($item)) {
    $file = new WPFB_File();
} else {
    $file =& $item;
}
if (!empty($post_id)) {
    $file->file_post_id = $post_id;
}
$action = $update ? 'updatefile' : 'addfile';
$title = $update ? __('Edit File', WPFB) : __('Add File', WPFB);
$default_roles = WPFB_Core::$settings->default_roles;
$user_roles = $update || empty($default_roles) ? $file->GetReadPermissions() : $default_roles;
$file_members_only = !empty($user_roles);
if (empty($form_url)) {
    $form_url = $in_editor ? remove_query_arg(array('file_id', 'page', 'action')) : add_query_arg('page', 'wpfilebase_files', admin_url('admin.php'));
}
if (!empty($_GET['redirect_to'])) {
    $form_url = add_query_arg(array('redirect' => 1, 'redirect_to' => urlencode($_GET['redirect_to'])), $form_url);
}
if (empty($nonce_action)) {
    $nonce_action = WPFB . "-" . $action;
    if ($update) {
        $nonce_action .= $multi_edit ? $item_ids : $file->file_id;
コード例 #3
0
ファイル: ListTpl.php プロジェクト: parsonsc/dofe
 function GenerateList(&$content, $categories, $list_args = null)
 {
     if (!empty($list_args)) {
         $this->current_list = (object) $list_args;
         unset($list_args);
     }
     $hia = WPFB_Core::$settings->hide_inaccessible;
     $sort = WPFB_Core::GetSortSql($this->current_list->file_order);
     if ($this->current_list->page_limit > 0) {
         // pagination
         $page = empty($_REQUEST['wpfb_list_page']) || $_REQUEST['wpfb_list_page'] < 1 ? 1 : intval($_REQUEST['wpfb_list_page']);
         $start = $this->current_list->page_limit * ($page - 1);
     } else {
         $start = -1;
     }
     $search_term = empty($_GET['wpfb_s']) ? null : stripslashes($_GET['wpfb_s']);
     if ($search_term || WPFB_Core::$file_browser_search) {
         // search
         wpfb_loadclass('Search');
         $where = WPFB_Search::SearchWhereSql(WPFB_Core::$settings->search_id3, $search_term);
     } else {
         $where = '1=1';
     }
     $num_total_files = 0;
     if (is_null($categories)) {
         // if null, just list all files!
         $files = WPFB_File::GetFiles2($where, $hia, $sort, $this->current_list->page_limit, $start);
         $num_total_files = WPFB_File::GetNumFiles2($where, $hia);
         foreach ($files as $file) {
             $content .= $file->GenTpl2($this->file_tpl_tag);
         }
     } else {
         if (!empty($this->current_list->cat_order)) {
             WPFB_Item::Sort($categories, $this->current_list->cat_order);
         }
         $cat = reset($categories);
         // get first category
         // here we check if single category and cat has at least one file (also secondary cat files!)
         if (count($categories) == 1 && $cat->cat_num_files > 0) {
             // single cat
             if (!$cat->CurUserCanAccess()) {
                 return '';
             }
             $where = "({$where}) AND " . WPFB_File::GetSqlCatWhereStr($cat->cat_id);
             $files = WPFB_File::GetFiles2($where, $hia, $sort, $this->current_list->page_limit, $start);
             $num_total_files = WPFB_File::GetNumFiles2($where, $hia);
             if ($this->current_list->cat_grouping && $num_total_files > 0) {
                 $content .= $cat->GenTpl2($this->cat_tpl_tag);
             }
             foreach ($files as $file) {
                 $content .= $file->GenTpl2($this->file_tpl_tag);
             }
         } else {
             // multi-cat
             // TODO: multi-cat list pagination does not work properly yet
             // special handling of categories that do not have files directly: list child cats!
             if (count($categories) == 1 && $cat->cat_num_files == 0) {
                 $categories = $cat->GetChildCats(true, true);
                 if (!empty($this->current_list->cat_order)) {
                     WPFB_Item::Sort($categories, $this->current_list->cat_order);
                 }
             }
             if ($this->current_list->cat_grouping) {
                 // group by categories
                 $n = 0;
                 foreach ($categories as $cat) {
                     if (!$cat->CurUserCanAccess()) {
                         continue;
                     }
                     $num_total_files = max($nf = WPFB_File::GetNumFiles2("({$where}) AND " . WPFB_File::GetSqlCatWhereStr($cat->cat_id), $hia), $num_total_files);
                     // TODO
                     //if($n > $this->current_list->page_limit) break; // TODO!!
                     if ($nf > 0) {
                         $files = WPFB_File::GetFiles2("({$where}) AND " . WPFB_File::GetSqlCatWhereStr($cat->cat_id), $hia, $sort, $this->current_list->page_limit, $start);
                         if (count($files) > 0) {
                             $content .= $cat->GenTpl2($this->cat_tpl_tag);
                             // check for file count again, due to pagination!
                             foreach ($files as $file) {
                                 $content .= $file->GenTpl2($this->file_tpl_tag);
                             }
                         }
                     }
                 }
             } else {
                 // this is not very efficient, because all files are loaded, no pagination!
                 $all_files = array();
                 foreach ($categories as $cat) {
                     if (!$cat->CurUserCanAccess()) {
                         continue;
                     }
                     $all_files += WPFB_File::GetFiles2("({$where}) AND " . WPFB_File::GetSqlCatWhereStr($cat->cat_id), $hia, $sort);
                 }
                 $num_total_files = count($all_files);
                 WPFB_Item::Sort($all_files, $sort);
                 $keys = array_keys($all_files);
                 if ($start == -1) {
                     $start = 0;
                 }
                 $last = $this->current_list->page_limit > 0 ? min($start + $this->current_list->page_limit, $num_total_files) : $num_total_files;
                 for ($i = $start; $i < $last; $i++) {
                     $content .= $all_files[$keys[$i]]->GenTpl2($this->file_tpl_tag);
                 }
             }
         }
     }
     return $num_total_files;
 }
コード例 #4
0
ファイル: Search.php プロジェクト: parsonsc/dofe
 static function FileSearchContent(&$ref_content)
 {
     wpfb_loadclass('ListTpl');
     $tpl = WPFB_ListTpl::Get(WPFB_Core::$settings->search_result_tpl);
     if ($tpl !== null) {
         $ref_content .= $tpl->Generate(null, array('page_limit' => WPFB_Core::$settings->filelist_num));
     } else {
         $files = WPFB_File::GetFiles2(self::SearchWhereSql(WPFB_Core::$settings->search_id3, stripslashes($_GET['wpfb_s'])), WPFB_Core::$settings->hide_inaccessible);
         foreach ($files as $file) {
             $ref_content .= $file->GenTpl2();
         }
     }
 }
コード例 #5
0
 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));
     		}
     */
 }
コード例 #6
0
ファイル: FileListTable.php プロジェクト: parsonsc/dofe
 function prepare_items()
 {
     global $wpdb;
     $columns = $this->get_columns();
     $hidden = array();
     $sortable = $this->get_sortable_columns();
     $this->_column_headers = array($columns, $hidden, $sortable);
     $this->process_bulk_action();
     $pagenum = $this->get_pagenum();
     if (!isset($filesperpage) || $filesperpage < 0) {
         $filesperpage = 50;
     }
     $pagestart = ($pagenum - 1) * $filesperpage;
     $where = $this->get_file_where_cond(empty($_REQUEST['view']) ? null : $_REQUEST['view']);
     $order = "{$wpdb->wpfilebase_files}." . (!empty($_REQUEST['orderby']) && in_array($_REQUEST['orderby'], array_merge(array_keys(get_class_vars('WPFB_File')), array_keys(WPFB_Core::GetCustomFields(true)))) ? $_REQUEST['orderby'] . " " . (!empty($_REQUEST['order']) && $_REQUEST['order'] == "desc" ? "DESC" : "ASC") : "file_id DESC");
     $total_items = WPFB_File::GetNumFiles2($where, 'edit');
     $files = WPFB_File::GetFiles2($where, 'edit', $order, $filesperpage, $pagestart);
     if (empty($files) && !empty($wpdb->last_error)) {
         wp_die("<b>Database error</b>: " . $wpdb->last_error);
     }
     $this->items = $files;
     $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $filesperpage, 'total_pages' => ceil($total_items / $filesperpage)));
 }
コード例 #7
0
    static function Display()
    {
        list($file_ids, $cat_ids, $sql_where) = self::getFileAndCatIds();
        $num_files = WPFB_File::GetNumFiles2($sql_where, 'edit');
        $prefix = "bulk";
        ?>
<div class="form-wrap">
	<h3><?php 
        printf(__('Batch edit %d files', 'wp-filebase'), $num_files);
        ?>
</h3>
<form action="<?php 
        echo remove_query_arg(array('action'));
        ?>
" method="post">
	<input type="hidden" name="action" value="edit" />	
	<input type="hidden" name="action2" value="apply" />	
	<input type="hidden" name="files" value="<?php 
        echo esc_attr(json_encode($file_ids));
        ?>
" />
	<input type="hidden" name="cats" value="<?php 
        echo esc_attr(json_encode($cat_ids));
        ?>
" />
		
	<div>
		<label for="<?php 
        echo $prefix;
        ?>
file_category"><?php 
        _e('Category', 'wp-filebase');
        ?>
</label>
		<select name="file_category" id="<?php 
        echo $prefix;
        ?>
file_category" class="wpfb-cat-select"><?php 
        wpfb_loadclass('Category');
        echo WPFB_Output::CatSelTree(array('none_label' => __('&mdash; No Change &mdash;'), 'check_add_perm' => true, 'add_cats' => true));
        ?>
</select>
	</div>
	<div class="form-field">		
		<label for="<?php 
        echo $prefix;
        ?>
file_tags"><?php 
        _e('Add Tags');
        ?>
</label>
		<input id="<?php 
        echo $prefix;
        ?>
file_tags" name="file_tags" type="text" />
	</div>

	<div class="form-field">		
		<label for="<?php 
        echo $prefix;
        ?>
file_author"><?php 
        _e('Author');
        ?>
</label>
		<input id="<?php 
        echo $prefix;
        ?>
file_author" name="file_author" type="text" placeholder="<?php 
        _e('&mdash; No Change &mdash;');
        ?>
" />
	</div>

<!--
	<div class="form-field">		
		<label for="<?php 
        echo $prefix;
        ?>
file_author"><?php 
        _e('Author');
        ?>
</label>
		<input id="<?php 
        echo $prefix;
        ?>
file_author" name="file_author" type="text" placeholder="<?php 
        _e('&mdash; No Change &mdash;');
        ?>
" />
	</div>


	<div class="form-field">		
		<label for="<?php 
        echo $prefix;
        ?>
file_description"><?php 
        _e('Description');
        ?>
</label>
		<textarea id="<?php 
        echo $prefix;
        ?>
file_description" name="file_description"></textarea>
	</div>
-->
	<div class="" style="float: left;">	
		<fieldset><legend class=""><?php 
        _e('Direct Linking', 'wp-filebase');
        ?>
</legend>
		<label title="<?php 
        _e('&mdash; No Change &mdash;');
        ?>
"><input type="radio" name="file_direct_linking" value="" <?php 
        checked(1);
        ?>
/> <?php 
        _e('&mdash; No Change &mdash;');
        ?>
</label>
		<label title="<?php 
        _e('Yes');
        ?>
"><input type="radio" name="file_direct_linking" value="1" /> <?php 
        _e('Allow direct linking', 'wp-filebase');
        ?>
</label>
		<label title="<?php 
        _e('No');
        ?>
"><input type="radio" name="file_direct_linking" value="0" /> <?php 
        _e('Redirect to post', 'wp-filebase');
        ?>
</label>

		</fieldset>
	</div>

	<div class="">	
		<fieldset><legend class=""><?php 
        _e('Offline', 'wp-filebase');
        ?>
</legend>
		<label title="<?php 
        _e('&mdash; No Change &mdash;');
        ?>
"><input type="radio" name="file_offline" value="" <?php 
        checked(1);
        ?>
/> <?php 
        _e('&mdash; No Change &mdash;');
        ?>
</label>
		<label title="<?php 
        _e('Yes');
        ?>
"><input type="radio" name="file_offline" value="1" /> <?php 
        _e('Set offline', 'wp-filebase');
        ?>
</label>
		<label title="<?php 
        _e('No');
        ?>
"><input type="radio" name="file_offline" value="0" /> <?php 
        _e('Set online', 'wp-filebase');
        ?>
</label>
		</fieldset>
	</div>

<div style="clear:both;"></div>

<!--

-->



<p class="submit"><input type="submit" name="submit" class="button-primary" value="<?php 
        _e("Submit");
        ?>
" /></p>
</form>
</div>
<!--
post,
access permission,
version,
custom vars,
lang,
platforms,
requirements,
date
secondary cats,
download counter, 
-->
<?php 
    }
コード例 #8
0
 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();
     }
 }
コード例 #9
0
ファイル: AdminDashboard.php プロジェクト: noxian/WP-Filebase
    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 
    }
コード例 #10
0
ファイル: wpfb_form_file.php プロジェクト: noxian/WP-Filebase
<?php

wpfb_loadclass('File');
$multi_edit = !empty($multi_edit);
$in_widget = !empty($in_widget);
$in_editor = !empty($in_editor);
$update = $multi_edit ? !empty($item) : isset($item) && is_object($item) && !empty($item->file_id);
$exform = $update || !empty($exform);
if (empty($item)) {
    $file = new WPFB_File();
} else {
    $file =& $item;
}
if (!empty($post_id)) {
    $file->file_post_id = $post_id;
}
$action = $update ? 'updatefile' : 'addfile';
$title = $update ? __('Edit File', 'wp-filebase') : __('Add File', 'wp-filebase');
$default_roles = WPFB_Core::$settings->default_roles;
$user_roles = $update || empty($default_roles) ? $file->GetReadPermissions() : $default_roles;
$file_members_only = !empty($user_roles);
if (empty($form_url)) {
    $form_url = $in_editor ? remove_query_arg(array('file_id', 'page', 'action')) : add_query_arg('page', 'wpfilebase_files', admin_url('admin.php'));
}
if (!empty($_GET['redirect_to'])) {
    $form_url = add_query_arg(array('redirect' => 1, 'redirect_to' => urlencode($_GET['redirect_to'])), $form_url);
} elseif (!empty($_GET['redirect_referer'])) {
    $form_url = add_query_arg(array('redirect' => 1, 'redirect_to' => urlencode($_SERVER['HTTP_REFERER'])), $form_url);
}
if (empty($nonce_action)) {
    $nonce_action = WPFB . "-" . $action;
コード例 #11
0
 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
 }
コード例 #12
0
ファイル: Ajax.php プロジェクト: noxian/WP-Filebase
 private static function actionAttachFile($args)
 {
     wpfb_loadclass('File');
     if (!current_user_can('upload_files') || empty($args['post_id']) || empty($args['file_id']) || !($file = WPFB_File::GetFile($args['file_id']))) {
         die('-1');
     }
     $file->SetPostId($args['post_id']);
     die('1');
 }
コード例 #13
0
ファイル: add-file.php プロジェクト: noxian/WP-Filebase
<?php

wpfb_loadclass('File');
$file = new WPFB_File();
if (empty($form_url)) {
    $form_url = $in_editor ? remove_query_arg(array('file_id', 'page', 'action')) : add_query_arg('page', 'wpfilebase_files', admin_url('admin.php'));
}
if (!empty($_GET['redirect_to'])) {
    $form_url = add_query_arg(array('redirect' => 1, 'redirect_to' => urlencode($_GET['redirect_to'])), $form_url);
} elseif (!empty($_GET['redirect_referer'])) {
    $form_url = add_query_arg(array('redirect' => 1, 'redirect_to' => urlencode($_SERVER['HTTP_REFERER'])), $form_url);
}
if (empty($nonce_action)) {
    $nonce_action = WPFB . "-" . $action;
    if ($update) {
        $nonce_action .= $multi_edit ? $item_ids : $file->file_id;
    }
    if ($in_editor) {
        $nonce_action .= "-editor";
    }
}
if ($update) {
    $file_category = $file->file_category;
} else {
    $cats = array_filter(array(@$_REQUEST['file_category'], $file->file_category, WPFB_Core::$settings->default_cat));
    $file_category = reset($cats);
}
//$file_category = ($update || empty($_REQUEST['file_category'])) ? $file->file_category : $_REQUEST['file_category'];
if (!$update) {
    $file->file_direct_linking = WPFB_Core::$settings->default_direct_linking;
}
コード例 #14
0
 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;
 }
コード例 #15
0
ファイル: Output.php プロジェクト: parsonsc/dofe
 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;
 }
コード例 #16
0
ファイル: Sync.php プロジェクト: noxian/WP-Filebase
 /**
  * @return WPFB_File
  */
 public function getFile()
 {
     if ($this->_file) {
         return $this->_file;
     }
     return $this->_file = WPFB_File::GetFile($this->id);
 }
コード例 #17
0
ファイル: Setup.php プロジェクト: parsonsc/dofe
 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');
 }
コード例 #18
0
ファイル: wpfb-ajax.php プロジェクト: parsonsc/dofe
     die('1');
 case 'set-user-setting':
     if (!current_user_can('manage_categories') || empty($_REQUEST['name'])) {
         die('0');
     }
     echo update_user_option(get_current_user_id(), 'wpfb_set_' . $_REQUEST['name'], stripslashes($_REQUEST['value']), true);
     exit;
 case 'get-user-setting':
     if (!current_user_can('manage_categories') || empty($_REQUEST['name'])) {
         die('-1');
     }
     wpfb_print_json(get_user_option('wpfb_set_' . $_REQUEST['name']));
     exit;
 case 'attach-file':
     wpfb_loadclass('File');
     if (!current_user_can('upload_files') || empty($_REQUEST['post_id']) || empty($_REQUEST['file_id']) || !($file = WPFB_File::GetFile($_REQUEST['file_id']))) {
         die('-1');
     }
     $file->SetPostId($_REQUEST['post_id']);
     die('1');
 case 'ftag_proposal':
     $tag = @$_REQUEST['tag'];
     $tags = (array) get_option(WPFB_OPT_NAME . '_ftags');
     // sorted!
     $props = array();
     if (($n = count($tags)) > 0) {
         $ks = array_keys($tags);
         for ($i = 0; $i < $n; $i++) {
             if (stripos($ks[$i], $tag) === 0) {
                 while ($i < $n && stripos($ks[$i], $tag) === 0) {
                     $props[] = array('t' => $ks[$i], 'n' => $tags[$ks[$i]]);
コード例 #19
0
<?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
コード例 #20
0
ファイル: Core.php プロジェクト: Seravo/WP-Filebase
 static function DownloadRedirect()
 {
     $file = null;
     if (!empty($_GET['wpfb_dl'])) {
         wpfb_loadclass('File');
         $file = WPFB_File::GetFile($_GET['wpfb_dl']);
         @ob_end_clean();
         // FIX: clean the OB so any output before the actual download is truncated (OB is started in wp-filebase.php)
     } else {
         if (!WPFB_Core::$settings->download_base || is_admin()) {
             return;
         }
         $dl_url_path = parse_url(home_url(WPFB_Core::$settings->download_base . '/'), PHP_URL_PATH);
         $pos = strpos($_SERVER['REQUEST_URI'], $dl_url_path);
         if ($pos === 0) {
             $filepath = trim(substr(stripslashes($_SERVER['REQUEST_URI']), strlen($dl_url_path)), '/');
             if (($qs = strpos($filepath, '?')) !== false) {
                 $filepath = substr($filepath, 0, $qs);
             }
             // remove query string
             if (!empty($filepath)) {
                 wpfb_loadclass('File', 'Category');
                 $file = is_null($file = WPFB_File::GetByPath($filepath)) ? WPFB_File::GetByPath(urldecode($filepath)) : $file;
             }
         }
     }
     if (!empty($file) && is_object($file) && !empty($file->is_file)) {
         $file->Download();
         exit;
     }
     /* else { // don't set coockies anymore
     		// no download, a normal request: set site visited coockie to disable referer check
     		if(empty($_COOKIE[WPFB_OPT_NAME])) {
     			@setcookie(WPFB_OPT_NAME, '1');
     			$_COOKIE[WPFB_OPT_NAME] = '1';
     		}
     	} */
 }
コード例 #21
0
ファイル: File.php プロジェクト: TishoTM/WP-Filebase
 static function GetAttachedFiles($post_id, $show_all = false)
 {
     $post_id = intval($post_id);
     return WPFB_File::GetFiles2(array('file_post_id' => $post_id), !$show_all && WPFB_Core::$settings->hide_inaccessible, WPFB_Core::GetSortSql(null, true));
 }
コード例 #22
0
ファイル: Setup.php プロジェクト: noxian/WP-Filebase
 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());
     }
 }
コード例 #23
0
ファイル: Admin.php プロジェクト: parsonsc/dofe
 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;
 }
コード例 #24
0
ファイル: editor-plugin.php プロジェクト: noxian/WP-Filebase
    if (isset($result['error']) && $result['error']) {
        ?>
<div id="message" class="updated fade"><p><?php 
        echo $result['error'];
        ?>
</p></div><?php 
        $file = new WPFB_File($_POST);
    } else {
        // success!!!!
        $file_id = $result['file_id'];
        if ($action != 'addfile') {
            $file = null;
        }
    }
}
$post_attachments = $post_id > 0 ? WPFB_File::GetAttachedFiles($post_id, true) : array();
if ($action != 'editfile' && (!empty($post_attachments) || $manage_attachments)) {
    ?>
	<form action="<?php 
    echo add_query_arg(array('action' => 'change-order'));
    ?>
" method="post">	
	<h3 class="media-title"><?php 
    echo $post_title ? sprintf(__('Files attached to <i>%s</i>', 'wp-filebase'), $post_title) : __('Files', 'wp-filebase');
    ?>
</h3>
	<div id="media-items">
	<?php 
    if (empty($post_attachments)) {
        echo "<div class='media-item'>", __('No items found.'), "</div>";
    } else {
コード例 #25
0
ファイル: GetID3.php プロジェクト: noxian/WP-Filebase
 /**
  * 
  * @global type $wpdb
  * @param WPFB_File $file
  * @param type $info
  * @return type
  */
 static function StoreFileInfo($file, $info)
 {
     global $wpdb;
     if (empty($file->file_thumbnail)) {
         if (!empty($info['comments']['picture'][0]['data'])) {
             $cover_img =& $info['comments']['picture'][0]['data'];
         } elseif (!empty($info['id3v2']['APIC'][0]['data'])) {
             $cover_img =& $info['id3v2']['APIC'][0]['data'];
         } else {
             $cover_img = null;
         }
         // TODO unset pic in info?
         if (!empty($cover_img)) {
             $cover = $file->GetLocalPath();
             $cover = substr($cover, 0, strrpos($cover, '.')) . '.jpg';
             file_put_contents($cover, $cover_img);
             $file->CreateThumbnail($cover, true);
             @unlink($cover);
             $cf_changed = true;
         }
     }
     self::cleanInfoByRef($info);
     // set encoding to utf8 (required for getKeywords)
     if (function_exists('mb_internal_encoding')) {
         $cur_enc = mb_internal_encoding();
         mb_internal_encoding('UTF-8');
     }
     $keywords = array();
     self::getKeywords($info, $keywords);
     $keywords = strip_tags(join(' ', $keywords));
     $keywords = str_replace(array('\\n', '&#10;'), '', $keywords);
     $keywords = preg_replace('/\\s\\s+/', ' ', $keywords);
     if (!function_exists('mb_detect_encoding') || mb_detect_encoding($keywords, "UTF-8") != "UTF-8") {
         $keywords = utf8_encode($keywords);
     }
     // restore prev encoding
     if (function_exists('mb_internal_encoding')) {
         mb_internal_encoding($cur_enc);
     }
     // don't store keywords 2 times:
     unset($info['keywords']);
     self::removeLongData($info, 8000);
     $data = empty($info) ? '0' : base64_encode(serialize($info));
     $res = $wpdb->replace($wpdb->wpfilebase_files_id3, array('file_id' => (int) $file->GetId(), 'analyzetime' => time(), 'value' => &$data, 'keywords' => &$keywords));
     unset($data, $keywords);
     $cf_changed = false;
     // TODO: move this cleanup into a callback / should NOT be HERE!
     if ($file->file_rescan_pending) {
         $file->file_rescan_pending = 0;
         $cf_changed = true;
     }
     // delete local temp file
     if ($file->IsRemote() && file_exists($file->GetLocalPath())) {
         @unlink($file->GetLocalPath());
     }
     // TODO END;
     if ($cf_changed && !$file->IsLocked()) {
         $file->DbSave(true);
     }
     return $res;
 }
コード例 #26
0
ファイル: AdminGuiFiles.php プロジェクト: noxian/WP-Filebase
    static function Display()
    {
        global $wpdb, $user_ID;
        wpfb_loadclass('File', 'Category', 'Admin', 'Output');
        $_POST = stripslashes_deep($_POST);
        $_GET = stripslashes_deep($_GET);
        $action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : '';
        $clean_uri = remove_query_arg(array('message', 'action', 'file_id', 'cat_id', 'deltpl', 'hash_sync'));
        // keep search keyword
        // nonce/referer check (security)
        if ($action == 'updatefile' || $action == 'addfile') {
            $nonce_action = WPFB . "-" . $action;
            if ($action == 'updatefile') {
                $nonce_action .= $_POST['file_id'];
            }
            if (!check_admin_referer($nonce_action, 'wpfb-file-nonce')) {
                wp_die(__('Cheatin&#8217; uh?'));
            }
        }
        // switch simple/extended form
        if (isset($_GET['exform'])) {
            $exform = !empty($_GET['exform']) && $_GET['exform'] == 1;
            update_user_option($user_ID, WPFB_OPT_NAME . '_exform', $exform, true);
        } else {
            $exform = (bool) get_user_option(WPFB_OPT_NAME . '_exform');
        }
        ?>
	<div class="wrap">
	<?php 
        switch ($action) {
            case 'editfile':
                if (!current_user_can('upload_files')) {
                    wp_die(__('Cheatin&#8217; uh?'));
                }
                if (!empty($_POST['files'])) {
                    if (!is_array($_POST['files'])) {
                        $_POST['files'] = explode(',', $_POST['files']);
                    }
                    $files = array();
                    foreach ($_POST['files'] as $file_id) {
                        $file = WPFB_File::GetFile($file_id);
                        if (!is_null($file) && $file->CurUserCanEdit()) {
                            $files[] = $file;
                        }
                    }
                    if (count($files) > 0) {
                        WPFB_Admin::PrintForm('file', $files, array('multi_edit' => true));
                    } else {
                        wp_die('No files to edit.');
                    }
                } else {
                    $file = WPFB_File::GetFile($_GET['file_id']);
                    if (is_null($file) || !$file->CurUserCanEdit()) {
                        wp_die(__('You do not have the permission to edit this file!', 'wp-filebase'));
                    }
                    WPFB_Admin::PrintForm('file', $file);
                }
                break;
            case 'updatefile':
                $file_id = (int) $_POST['file_id'];
                $update = true;
                $file = WPFB_File::GetFile($file_id);
                if (is_null($file) || !$file->CurUserCanEdit()) {
                    wp_die(__('Cheatin&#8217; uh?'));
                }
            case 'addfile':
                $update = !empty($update);
                if (!WPFB_Core::CurUserCanUpload()) {
                    wp_die(__('Cheatin&#8217; uh?'));
                }
                extract($_POST);
                if (isset($jj) && isset($ss)) {
                    $jj = $jj > 31 ? 31 : $jj;
                    $hh = $hh > 23 ? $hh - 24 : $hh;
                    $mn = $mn > 59 ? $mn - 60 : $mn;
                    $ss = $ss > 59 ? $ss - 60 : $ss;
                    $_POST['file_date'] = sprintf("%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss);
                }
                $result = WPFB_Admin::InsertFile(stripslashes_deep(array_merge($_POST, $_FILES)), true);
                if (isset($result['error']) && $result['error']) {
                    $message = $result['error'] . '<br /><a href="javascript:history.back()">' . __("Go back") . '</a>';
                } else {
                    $message = $update ? __('File updated.', 'wp-filebase') : __('File added.', 'wp-filebase');
                }
            default:
                if (!current_user_can('upload_files')) {
                    wp_die(__('Cheatin&#8217; uh?'));
                }
                if (!empty($_REQUEST['redirect']) && !empty($_REQUEST['redirect_to'])) {
                    WPFB_AdminLite::JsRedirect($_REQUEST['redirect_to']);
                    exit;
                }
                if (!empty($_POST['deleteit'])) {
                    foreach ((array) $_POST['delete'] as $file_id) {
                        if (is_object($file = WPFB_File::GetFile($file_id)) && $file->CurUserCanDelete()) {
                            $file->Remove(true);
                        }
                    }
                    WPFB_File::UpdateTags();
                }
                ?>
	<h2><?php 
                echo str_replace(array('(<', '>)'), array('<', '>'), sprintf(__('Manage Files (<a href="%s">add new</a>)', 'wp-filebase'), '#addfile" class="add-new-h2'));
                echo '<a href="' . admin_url('admin.php?page=wpfilebase_manage&amp;action=batch-upload') . '" class="add-new-h2">' . __('Batch Upload', 'wp-filebase') . '</a>';
                if (isset($_GET['s']) && $_GET['s']) {
                    printf('<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', esc_html(stripslashes($_GET['s'])));
                }
                ?>
</h2>
	<?php 
                if (!empty($message)) {
                    ?>
<div id="message" class="updated fade"><p><?php 
                    echo $message;
                    ?>
</p></div><?php 
                }
                if (WPFB_Core::CurUserCanUpload() && ($action == 'addfile' || $action == 'updatefile')) {
                    unset($file);
                    WPFB_Admin::PrintForm('file', null, array('exform' => $exform, 'item' => new WPFB_File(isset($result['error']) && $result['error'] ? $_POST : null)));
                }
                wpfb_loadclass('FileListTable');
                $file_table = new WPFB_FileListTable();
                $file_table->prepare_items();
                ?>
	
<form class="search-form topmargin" action="" method="get">
	<input type="hidden" value="<?php 
                echo esc_attr($_GET['page']);
                ?>
" name="page" />
	<input type="hidden" value="<?php 
                echo empty($_GET['view']) ? '' : esc_attr(@$_GET['view']);
                ?>
" name="view" />
<?php 
                $file_table->search_box(__('Search Files', 'wp-filebase'), 's');
                ?>
</form>	
 
<?php 
                $file_table->views();
                ?>
 <form id="posts-filter" action="" method="post">
 <input type="hidden" name="page" value="<?php 
                echo $_REQUEST['page'];
                ?>
" />
 <?php 
                $file_table->display();
                ?>
 </form>
 <br class="clear" />

<?php 
                if ($action != 'addfile' && $action != 'updatefile' && WPFB_Core::CurUserCanUpload()) {
                    unset($file);
                    WPFB_Admin::PrintForm('file', null, array('exform' => $exform));
                }
                break;
                // default
        }
        /*
        $file_list_table = new WPFB_File_List_Table();
        	$pagenum = $file_list_table->get_pagenum();
        	$doaction = $file_list_table->current_action();
        $file_list_table->prepare_items();
        $file_list_table->views();
        	$file_list_table->search_box( "asdf", 'post' );
        $file_list_table->display();
        */
        ?>
	
	
	
	
</div> <!-- wrap -->
<?php 
    }
コード例 #27
0
ファイル: AdminGuiManage.php プロジェクト: Seravo/WP-Filebase
 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
 }