Example #1
0
 static function PostsSearch($sql)
 {
     global $wp_query, $wpdb;
     if (empty($sql)) {
         return $sql;
     }
     wpfb_loadclass('File');
     $is_wp_search = !empty($_GET['s']) && empty($_GET['wpfb_s']);
     $search_id3 = WPFB_Core::$settings->search_id3;
     $no_matches = false;
     $where = self::SearchWhereSql($search_id3);
     $where = "({$where} AND (" . WPFB_File::GetReadPermsWhere() . "))";
     // check if there are matching files, if there are, include the filebrowser page/post in the resulst!
     // if we have file pages, only include the file browser if file search widget was used!
     $file_browser_id = intval(WPFB_Core::$settings->file_browser_post_id);
     if ($file_browser_id > 0 && WPFB_File::GetNumFiles2($where, true) > 0) {
         $where = "({$where} OR ({$wpdb->posts}.ID = {$file_browser_id}))";
         // TODO!
         wpfb_loadclass('Output');
         WPFB_Core::$file_browser_search = true;
     }
     // OR' the $where to existing search conditions
     $p = strpos($sql, "(");
     $sql = substr($sql, 0, $p) . "( " . substr($sql, $p);
     $p = strrpos($sql, ")))");
     $sql = substr($sql, 0, $p + 3) . " OR {$where})" . substr($sql, $p + 3);
     //echo "<br>".$sql;
     return $sql;
 }
Example #2
0
 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)));
 }
Example #3
0
 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;
 }
Example #4
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 
    }