本文整理汇总了PHP中WPFB_Core::GetSortSql方法的典型用法代码示例。如果您正苦于以下问题:PHP WPFB_Core::GetSortSql方法的具体用法?PHP WPFB_Core::GetSortSql怎么用?PHP WPFB_Core::GetSortSql使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WPFB_Core
的用法示例。
在下文中一共展示了WPFB_Core::GetSortSql方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: GenerateList
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++) {
//.........这里部分代码省略.........
示例2: GetTreeItems
static function GetTreeItems($parent_id, $args = array())
{
/* $args = array(
* sort_cats
* sort_files
* cats_only
* exclude_attached
* priv
* idp =>
* onselect
* );
*/
$parent_id = is_object($parent_id) ? $parent_id->cat_id : intval($parent_id);
$args = self::fileBrowserArgs($args);
$type = $args['type'];
$browser = $type === 'browser';
$filesel = $type === 'fileselect';
$catsel = $type === 'catselect';
$args['idp'] = wp_strip_all_tags($args['idp']);
$idp_cat = $args['idp'] . 'cat-';
$idp_file = $args['idp'] . 'file-';
$file_tpl = $cat_tpl = !empty($args['tpl']) ? $args['tpl'] : (($is_admin = !empty($args['is_admin'])) ? 'filebrowser_admin' : 'filebrowser');
if ($parent_id > 0 && (is_null($cat = WPFB_Category::GetCat($parent_id)) || !$cat->CurUserCanAccess())) {
return array((object) array('id' => 0, 'text' => WPFB_Core::$settings->cat_inaccessible_msg));
}
$sql_sort_files = $browser ? WPFB_Core::GetSortSql((WPFB_Core::$settings->file_browser_file_sort_dir ? '>' : '<') . WPFB_Core::$settings->file_browser_file_sort_by) : 'file_display_name';
$sql_sort_cats = $browser ? WPFB_Core::GetSortSql((WPFB_Core::$settings->file_browser_cat_sort_dir ? '>' : '<') . WPFB_Core::$settings->file_browser_cat_sort_by, false, true) : 'cat_name';
$files_before_cats = $browser && WPFB_Core::$settings->file_browser_fbc;
$inline_add_cat = WPFB_Core::CurUserCanCreateCat();
$where = " cat_parent = {$parent_id} ";
if ($browser) {
$where .= " AND cat_exclude_browser <> '1' ";
}
$cats = WPFB_Category::GetCats("WHERE {$where} ORDER BY {$sql_sort_cats}");
$cat_items = array();
$i = 0;
$folder_class = $filesel || $catsel ? 'folder' : '';
foreach ($cats as $c) {
if ($c->CurUserCanAccess(true)) {
$cat_items[$i++] = (object) array('id' => $idp_cat . $c->cat_id, 'cat_id' => $c->cat_id, 'text' => self::fileBrowserCatItemText($catsel, $filesel, $c, $args['onselect'], $cat_tpl), 'hasChildren' => $inline_add_cat || $c->HasChildren($catsel), 'classes' => $folder_class);
}
}
if ($inline_add_cat) {
$is = WPFB_Core::$settings->small_icon_size > 0 ? WPFB_Core::$settings->small_icon_size : 32;
$cat_items[$i++] = (object) array('id' => $idp_cat . '0', 'cat_id' => 0, 'text' => '<form action="" style="display:none;"><input type="text" placeholder="' . __('Category Name', WPFB) . '" name="cat_name" /></form> ' . '<a href="#" style="text-decoration:none;" onclick=\'return wpfb_newCatInput(this,' . $parent_id . ');\'><span style="' . ($browser ? 'font-size:' . $is . 'px;width:' . $is . 'px' : 'font-size:200%') . ';line-height:0;vertical-align:sub;display:inline-block;text-align:center;">+</span>' . __('Add Category', WPFB) . '</a>' . '<span style="font-size: 200%;vertical-align: sub;line-height: 0;font-weight: lighter;"> / </span>' . '<a href="#" style="text-decoration:none;" class="add-file"><span style="' . ($browser ? 'font-size:' . $is . 'px;width:' . $is . 'px' : 'font-size:200%') . ';line-height:0;vertical-align:sub;display:inline-block;text-align:center;">+</span>' . __('Add File', WPFB) . '</a>', 'hasChildren' => false, 'classes' => 'add-item');
} elseif ($parent_id == 0 && $catsel && $i == 0) {
return array((object) array('id' => $idp_cat . '0', 'text' => sprintf(__('You did not create a category. <a href="%s" target="_parent">Click here to create one.</a>', WPFB), admin_url('admin.php?page=wpfilebase_cats#addcat')), 'hasChildren' => false));
}
$file_items = array();
$i = 0;
if (empty($args['cats_only']) && !$catsel) {
$where = WPFB_File::GetSqlCatWhereStr($parent_id);
if (!empty($args['exclude_attached'])) {
$where .= " AND `file_post_id` = 0";
}
// $files = WPFB_File::GetFiles2(WPFB_File::GetSqlCatWhereStr($root_id), WPFB_Core::$settings->hide_inaccessible, $sql_file_order);
//$files = WPFB_File::GetFiles2(WPFB_File::GetSqlCatWhereStr($root_id), WPFB_Core::$settings->hide_inaccessible, $sql_file_order);
$files = WPFB_File::GetFiles2($where, WPFB_Core::$settings->hide_inaccessible && !($filesel && wpfb_call('Core', 'CurUserCanUpload')), $sql_sort_files);
foreach ($files as $f) {
$file_items[$i++] = (object) array('id' => $idp_file . $f->file_id, 'text' => $filesel ? '<a href="javascript:;" onclick="' . sprintf($args['onselect'], $f->file_id) . '">' . esc_html($f->GetTitle(24)) . '</a> <span style="font-size:75%;vertical-align:top;">' . esc_html($f->file_name) . '</span>' : $f->GenTpl2($file_tpl, false), 'classes' => $filesel ? 'file' : null, 'hasChildren' => false);
}
}
return $files_before_cats ? array_merge($file_items, $cat_items) : array_merge($cat_items, $file_items);
}
示例3: GetAttachedFiles
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));
}
示例4: GetTreeItems
static function GetTreeItems($parent_id, $type = 'browser', $args = array())
{
/* $args = array(
* sort_cats
* sort_files
* cats_only
* exclude_attached
* priv
* cat_id_fmt =>
* file_id_fmt =>
* onselect
* );
*/
$parent_id = is_object($parent_id) ? $parent_id->cat_id : intval($parent_id);
$browser = $type === 'browser';
$filesel = $type === 'fileselect';
$catsel = $type === 'catselect';
if ($parent_id > 0 && (is_null($cat = WPFB_Category::GetCat($parent_id)) || !$cat->CurUserCanAccess())) {
return array((object) array('id' => 0, 'text' => WPFB_Core::$settings->cat_inaccessible_msg));
}
$sql_sort_files = $browser ? WPFB_Core::GetSortSql((WPFB_Core::$settings->file_browser_file_sort_dir ? '>' : '<') . WPFB_Core::$settings->file_browser_file_sort_by) : 'file_display_name';
$sql_sort_cats = $browser ? WPFB_Core::GetSortSql((WPFB_Core::$settings->file_browser_cat_sort_dir ? '>' : '<') . WPFB_Core::$settings->file_browser_cat_sort_by, false, true) : 'cat_name';
$cat_id_format = empty($args['cat_id_fmt']) ? 'wpfb-cat-%d' : $args['cat_id_fmt'];
$file_id_format = empty($args['file_id_fmt']) ? 'wpfb-file-%d' : $args['file_id_fmt'];
if ($filesel || $catsel) {
$onselect = $args['onselect'];
}
$files_before_cats = $browser && WPFB_Core::$settings->file_browser_fbc;
$where = " cat_parent = {$parent_id} ";
if ($browser) {
$where .= " AND cat_exclude_browser <> '1' ";
}
$cats = WPFB_Category::GetCats("WHERE {$where} ORDER BY {$sql_sort_cats}");
$cat_items = array();
$i = 0;
foreach ($cats as $c) {
if ($c->CurUserCanAccess(true)) {
$cat_items[$i++] = (object) array('id' => sprintf($cat_id_format, $c->cat_id), 'cat_id' => $c->cat_id, 'text' => $catsel ? '<a href="javascript:' . sprintf($onselect, $c->cat_id, str_replace('\'', '\\\'', htmlspecialchars(stripslashes($c->cat_name)))) . '">' . esc_html($c->GetTitle(24)) . '</a>' : ($filesel ? esc_html($c->cat_name) . " ({$c->cat_num_files} / {$c->cat_num_files_total})" : $c->GenTpl2('filebrowser', false)), 'hasChildren' => $c->HasChildren($catsel), 'classes' => $filesel || $catsel ? 'folder' : null);
}
}
if ($parent_id == 0 && $catsel && $i == 0) {
return array((object) array('id' => sprintf($cat_id_format, 0), 'text' => sprintf(__('You did not create a category. <a href="%s" target="_parent">Click here to create one.</a>', WPFB), admin_url('admin.php?page=wpfilebase_cats#addcat')), 'hasChildren' => false));
}
$file_items = array();
$i = 0;
if (empty($args['cats_only']) && !$catsel) {
$where = WPFB_File::GetSqlCatWhereStr($parent_id);
if (!empty($args['exclude_attached'])) {
$where .= " AND `file_post_id` = 0";
}
// $files = WPFB_File::GetFiles2(WPFB_File::GetSqlCatWhereStr($root_id), WPFB_Core::$settings->hide_inaccessible, $sql_file_order);
//$files = WPFB_File::GetFiles2(WPFB_File::GetSqlCatWhereStr($root_id), WPFB_Core::$settings->hide_inaccessible, $sql_file_order);
$files = WPFB_File::GetFiles2($where, WPFB_Core::$settings->hide_inaccessible && !($filesel && wpfb_call('Admin', 'CurUserCanUpload')), $sql_sort_files);
foreach ($files as $f) {
$file_items[$i++] = (object) array('id' => sprintf($file_id_format, $f->file_id), 'text' => $filesel ? '<a href="javascript:' . sprintf($onselect, $f->file_id, str_replace('\'', '\\\'', htmlspecialchars(stripslashes($f->file_display_name)))) . '">' . esc_html($f->GetTitle(24)) . '</a> <span style="font-size:75%;vertical-align:top;">' . esc_html($f->file_name) . '</span>' : $f->GenTpl2('filebrowser', false), 'classes' => $filesel ? 'file' : null, 'hasChildren' => false);
}
}
return $files_before_cats ? array_merge($file_items, $cat_items) : array_merge($cat_items, $file_items);
}