Example #1
0
 function get_file_where_cond($view = 'all')
 {
     global $wpdb, $current_user;
     wpfb_loadclass('Search');
     $where = WPFB_Search::SearchWhereSql(true);
     if (!empty($_REQUEST['file_category'])) {
         $where = (empty($where) ? '' : "({$where}) AND ") . "file_category = " . intval($_REQUEST['file_category']);
     }
     if (!empty($view) && $view != 'all') {
         $view_cond = "1=1";
         switch ($view) {
             case 'own':
                 $view_cond = "file_added_by = " . (int) $current_user->ID;
                 break;
             case 'offline':
                 $view_cond = "file_offline = '1'";
                 break;
             case 'notattached':
                 $view_cond = "file_post_id = 0";
                 break;
             case 'local':
                 $view_cond = "file_remote_uri = ''";
                 break;
             case 'cloud':
                 $view_cond = "file_remote_uri <> ''";
                 break;
         }
         $where = (empty($where) ? '' : "({$where}) AND ") . $view_cond;
     }
     return $where;
 }
Example #2
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 #3
0
 static function ContentFilter($content)
 {
     global $id, $wpfb_fb, $post;
     if (!WPFB_Core::$settings->parse_tags_rss && is_feed()) {
         return $content;
     }
     if (is_object($post) && !post_password_required()) {
         // TODO: file resulst are generated twice, 2nd time in the_excerpt filter (SearchExcerptFilter)
         // some themes do not use excerpts in search resulsts!!
         // replace file browser post content with search results
         if (WPFB_Core::$file_browser_search && $id == WPFB_Core::$settings->file_browser_post_id) {
             wpfb_loadclass('Search', 'File', 'Category');
             $content = '';
             WPFB_Search::FileSearchContent($content);
         } else {
             // do not hanlde attachments when searching
             $single = is_single() || is_page();
             if ($single && $post->ID == WPFB_Core::$settings->file_browser_post_id) {
                 $wpfb_fb = true;
                 wpfb_loadclass('Output', 'File', 'Category');
                 WPFB_Output::FileBrowser($content, 0, empty($_GET['wpfb_cat']) ? 0 : intval($_GET['wpfb_cat']));
             }
             if (self::GetOpt('auto_attach_files') && ($single || self::GetOpt('attach_loop'))) {
                 wpfb_loadclass('Output');
                 if (WPFB_Core::$settings->attach_pos == 0) {
                     $content = WPFB_Output::PostAttachments(true) . $content;
                 } else {
                     $content .= WPFB_Output::PostAttachments(true);
                 }
             }
         }
     }
     return $content;
 }