예제 #1
0
function wpdm_embed_category($params = array('id' => '', 'items_per_page' => 10, 'title' => false, 'desc' => false, 'order_field' => 'create_date', 'order' => 'desc', 'paging' => false, 'toolbar' => 1, 'template' => '', 'cols' => 3, 'colspad' => 2, 'colsphone' => 1))
{
    extract($params);
    if (!isset($id)) {
        return;
    }
    if (!isset($items_per_page)) {
        $items_per_page = 10;
    }
    if (!isset($template)) {
        $template = 'link-template-panel';
    }
    if (!isset($cols)) {
        $cols = 3;
    }
    if (!isset($colspad)) {
        $colspad = 2;
    }
    if (!isset($colsphone)) {
        $colsphone = 1;
    }
    if (!isset($toolbar)) {
        $toolbar = 1;
    }
    $taxo = 'wpdmcategory';
    if (isset($tag) && $tag == 1) {
        $taxo = 'post_tag';
    }
    $cwd_class = "col-md-" . (int) (12 / $cols);
    $cwdsm_class = "col-sm-" . (int) (12 / $colspad);
    $cwdxs_class = "col-xs-" . (int) (12 / $colsphone);
    $id = trim($id, ", ");
    $cids = explode(",", $id);
    global $wpdb, $current_user, $post, $wp_query;
    $order_field = isset($order_field) ? $order_field : 'publish_date';
    $order_field = isset($_GET['orderby']) ? $_GET['orderby'] : $order_field;
    $order = isset($order) ? $order : 'desc';
    $order = isset($_GET['order']) ? $_GET['order'] : $order;
    $cp = wpdm_query_var('cp', 'num');
    if (!$cp) {
        $cp = 1;
    }
    $params = array('post_type' => 'wpdmpro', 'paged' => $cp, 'posts_per_page' => $items_per_page, 'include_children' => false, 'tax_query' => array(array('taxonomy' => $taxo, 'field' => 'slug', 'terms' => $cids)));
    if (get_option('_wpdm_hide_all', 0) == 1) {
        $params['meta_query'] = array(array('key' => '__wpdm_access', 'value' => 'guest', 'compare' => 'LIKE'));
        if (is_user_logged_in()) {
            global $current_user;
            $params['meta_query'][] = array('key' => '__wpdm_access', 'value' => $current_user->roles[0], 'compare' => 'LIKE');
            $params['meta_query']['relation'] = 'OR';
        }
    }
    $params['orderby'] = $order_field;
    $params['order'] = $order;
    $params = apply_filters("wpdm_embed_category_query_params", $params);
    $packs = new WP_Query($params);
    $total = $packs->found_posts;
    $pages = ceil($total / $items_per_page);
    $page = isset($_GET['cp']) ? $_GET['cp'] : 1;
    $start = ($page - 1) * $items_per_page;
    if (!isset($paging) || $paging == 1) {
        $pag = new wpdm_pagination();
        $pag->items($total);
        $pag->nextLabel(' ► ');
        $pag->prevLabel(' ◄ ');
        $pag->limit($items_per_page);
        $pag->currentPage($page);
    }
    $burl = get_permalink();
    $url = $_SERVER['REQUEST_URI'];
    //get_permalink();
    $url = strpos($url, '?') ? $url . '&' : $url . '?';
    $url = preg_replace("/[\\&]*cp=[0-9]+[\\&]*/", "", $url);
    $url = strpos($url, '?') ? $url . '&' : $url . '?';
    if (!isset($paging) || $paging == 1) {
        $pag->urlTemplate($url . "cp=[%PAGENO%]");
    }
    $html = '';
    $templates = maybe_unserialize(get_option("_fm_link_templates", true));
    if (isset($templates[$template])) {
        $template = $templates[$template]['content'];
    }
    //if (file_exists(WPDM_BASE_DIR . '/templates/' . $category['link_template'])) $category['link_template'] = @file_get_contents(WPDM_BASE_DIR . '/templates/' . $category['link_template']);
    //else $category['link_template'] = $templates[$category['link_template']]['content'];
    //$link_temnplate = $category['link_template'] == '' ? $category['template_repeater'] : $category['link_template'];
    //if (isset($template) && $template) $link_temnplate = $template;
    //if (isset($template) && $templates[$template]['content'] != '') $link_temnplate = $templates[$template]['content'];
    global $post;
    while ($packs->have_posts()) {
        $packs->the_post();
        $pack = (array) $post;
        $repeater = "<div class='{$cwd_class} {$cwdsm_class} {$cwdxs_class}'>" . FetchTemplate($template, $pack) . "</div>";
        $html .= $repeater;
    }
    wp_reset_query();
    $html = "<div class='row'>{$html}</div>";
    $cname = array();
    foreach ($cids as $cid) {
        $cat = get_term_by('slug', $cid, $taxo);
        $cname[] = $cat->name;
    }
    $cats = implode(", ", $cname);
    //$category['title'] = stripcslashes($category['title']);
    //$category['content'] = stripcslashes($category['content']);
    $cimg = '';
    $desc = '';
    //if ($title == 1 && count($cids) == 1) $title = "<h3 style='margin:0px;font-size:11pt;line-height:normal'>$category[title]</h3>";
    //if (get_option('__wpdm_cat_img', 0) == 1) $cimg = "<img src='{$category[icon]}' />";
    //if ($desc == 1 && count($cids) == 1 || get_option('__wpdm_cat_desc', 0) == 1) $desc = wpautop($category['content']);
    $subcats = '';
    if (function_exists('wpdm_ap_categories') && $subcats == 1) {
        $schtml = wpdm_ap_categories(array('parent' => $id));
        if ($schtml != '') {
            $subcats = "<fieldset class='cat-page-tilte'><legend>" . __('Sub-Categories', 'wpdmpro') . "</legend>" . $schtml . "<div style='clear:both'></div></fieldset>" . "<fieldset class='cat-page-tilte'><legend>" . __('Downloads', 'wpdmpro') . "</legend>";
            $efs = '</fieldset>';
        }
    }
    if (!isset($paging) || $paging == 1) {
        $pgn = "<div style='clear:both'></div>" . $pag->show() . "<div style='clear:both'></div>";
    } else {
        $pgn = "";
    }
    global $post;
    $sap = get_option('permalink_structure') ? '?' : '&';
    $burl = $burl . $sap;
    if (isset($_GET['p']) && $_GET['p'] != '') {
        $burl .= 'p=' . $_GET['p'] . '&';
    }
    if (isset($_GET['src']) && $_GET['src'] != '') {
        $burl .= 'src=' . $_GET['src'] . '&';
    }
    $orderby = isset($_GET['orderby']) ? $_GET['orderby'] : 'create_date';
    $order = ucfirst($order);
    $order_field = " " . __(ucwords(str_replace("_", " ", $order_field)), "wpdmpro");
    $ttitle = __('Title', 'wpdmpro');
    $tdls = __('Downloads', 'wpdmpro');
    $tcdate = __('Publish Date', 'wpdmpro');
    $tudate = __('Update Date', 'wpdmpro');
    $tasc = __('Asc', 'wpdmpro');
    $tdsc = __('Desc', 'wpdmpro');
    $tsrc = __('Search', 'wpdmpro');
    $order_by_label = __('Order By', 'wpdmpro');
    if ($toolbar || get_option('__wpdm_cat_tb') == 1) {
        $toolbar = <<<TBR

                 <div class="navbar navbar-default" role="navigation">
  <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="#">{$cats}</a>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">

      <ul class="nav navbar-nav navbar-right">
       <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">{$order_by_label} {$order_field} <b class="caret"></b></a>
                        <ul class="dropdown-menu">
                         <li><a href="{$burl}orderby=title&order=asc">{$ttitle}</a></li>
                         <!-- li><a href="{$burl}orderby=download_count&order=desc">{$tdls}</a></li -->
                         <li><a href="{$burl}orderby=publish_date&order=desc">{$tcdate}</a></li>
                        </ul>
                     </li>
                     <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">{$order} <b class="caret"></b></a>
                        <ul class="dropdown-menu">
                         <li><a href="{$burl}orderby={$orderby}&order=asc">{$tasc}</a></li>
                         <li><a href="{$burl}orderby={$orderby}&order=desc">{$tdsc}</a></li>
                        </ul>
                     </li>
      </ul>
    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</div>
TBR;
    } else {
        $toolbar = '';
    }
    return "<div class='w3eden'>" . $cimg . $desc . $toolbar . $subcats . $html . $pgn . "<div style='clear:both'></div></div>";
}
예제 #2
0
파일: functions.php 프로젝트: antoninab/t2c
function wpdm_embed_category($params = array('id' => '', 'items_per_page' => 10, 'title' => false, 'desc' => false, 'order_field' => 'create_date', 'order' => 'desc', 'paging' => false, 'toolbar' => 1, 'template' => ''))
{
    extract($params);
    if (!isset($id)) {
        return;
    }
    if (!isset($items_per_page)) {
        $items_per_page = 10;
    }
    if (!isset($template)) {
        $template = 'link-template-panel.php';
    }
    $cols = 1;
    if (!isset($toolbar)) {
        $toolbar = 1;
    }
    $cwd_class = "col-md-" . (int) (12 / $cols);
    $id = trim($id, ", ");
    $cids = explode(",", $id);
    global $wpdb, $current_user, $post, $wp_query;
    $order_field = isset($order_field) ? $order_field : 'publish_date';
    $order_field = isset($_GET['orderby']) ? $_GET['orderby'] : $order_field;
    $order = isset($order) ? $order : 'desc';
    $order = isset($_GET['order']) ? $_GET['order'] : $order;
    $params = array('post_type' => 'wpdmpro', 'posts_per_page' => $items_per_page, 'tax_query' => array(array('taxonomy' => 'wpdmcategory', 'field' => 'slug', 'terms' => $cids)));
    $params['orderby'] = $order_field;
    $params['order'] = $order;
    $page = isset($_GET['cp']) ? $_GET['cp'] : 1;
    if (intval($page) > 1) {
        $params['paged'] = $page;
    }
    $packs = new WP_Query($params);
    $total = $packs->found_posts;
    $pages = ceil($total / $items_per_page);
    $start = ($page - 1) * $items_per_page;
    if (!isset($paging) || $paging == 1) {
        $pag = new wpdm_pagination();
        $pag->items($total);
        $pag->nextLabel(' &#9658; ');
        $pag->prevLabel(' &#9668; ');
        $pag->limit($items_per_page);
        $pag->currentPage($page);
    }
    $burl = get_permalink();
    $url = get_permalink();
    $url = strpos($url, '?') ? $url . '&' : $url . '?';
    $url = preg_replace("/[\\&]*cp=[0-9]+[\\&]*/", "", $url);
    $url = strpos($url, '?') ? $url . '&' : $url . '?';
    if (!isset($paging) || $paging == 1) {
        $pag->urlTemplate($url . "cp=[%PAGENO%]");
    }
    $html = '';
    //$template = "<div class='media'><div class='pull-left'>[icon]</div><div class='media-body'><b>[title]</b><br/>[download_link]</div></div>";
    if (isset($template) && in_array($template, array('link-template-default', 'link-template-default-wdc', 'link-template-default-ext', 'link-template-button'))) {
        $template = "{$template}.php";
    } else {
        $template = "link-template-default.php";
    }
    global $post;
    while ($packs->have_posts()) {
        $packs->the_post();
        $pack = (array) $post;
        $repeater = "<div class='{$cwd_class}'>" . FetchTemplate($template, $pack) . "</div>";
        $html .= $repeater;
    }
    $html = "<div class='row'>{$html}</div>";
    $cname = array();
    foreach ($cids as $cid) {
        $cat = get_term_by('slug', $cid, 'wpdmcategory');
        if (is_object($cat)) {
            $cname[] = $cat->name;
        }
    }
    $cats = implode(", ", $cname);
    //$category['title'] = stripcslashes($category['title']);
    //$category['content'] = stripcslashes($category['content']);
    $cimg = '';
    $desc = '';
    //if ($title == 1 && count($cids) == 1) $title = "<h3 style='margin:0px;font-size:11pt;line-height:normal'>$category[title]</h3>";
    //if (get_option('__wpdm_cat_img', 0) == 1) $cimg = "<img src='{$category[icon]}' />";
    //if ($desc == 1 && count($cids) == 1 || get_option('__wpdm_cat_desc', 0) == 1) $desc = wpautop($category['content']);
    $subcats = '';
    if (function_exists('wpdm_ap_categories') && $subcats == 1) {
        $schtml = wpdm_ap_categories(array('parent' => $id));
        if ($schtml != '') {
            $subcats = "<fieldset class='cat-page-tilte'><legend>" . __('Sub-Categories', 'wpdmpro') . "</legend>" . $schtml . "<div style='clear:both'></div></fieldset>" . "<fieldset class='cat-page-tilte'><legend>" . __('Downloads', 'wpdmpro') . "</legend>";
            $efs = '</fieldset>';
        }
    }
    if (!isset($paging) || $paging == 1) {
        $pgn = "<div style='clear:both'></div>" . $pag->show() . "<div style='clear:both'></div>";
    } else {
        $pgn = "";
    }
    global $post;
    $sap = get_option('permalink_structure') ? '?' : '&';
    $burl = $burl . $sap;
    if (isset($_GET['p']) && $_GET['p'] != '') {
        $burl .= 'p=' . $_GET['p'] . '&';
    }
    if (isset($_GET['src']) && $_GET['src'] != '') {
        $burl .= 'src=' . $_GET['src'] . '&';
    }
    $orderby = isset($_GET['orderby']) ? $_GET['orderby'] : 'create_date';
    $order = ucfirst($order);
    $order_field = " " . ucwords(str_replace("_", " ", $order_field));
    $ttitle = __('Title', 'wpdmpro');
    $tdls = __('Downloads', 'wpdmpro');
    $tcdate = __('Publish Date', 'wpdmpro');
    $tudate = __('Update Date', 'wpdmpro');
    $tasc = __('Asc', 'wpdmpro');
    $tdsc = __('Desc', 'wpdmpro');
    $tsrc = __('Search', 'wpdmpro');
    if ($toolbar || get_option('__wpdm_cat_tb') == 1) {
        $toolbar = <<<TBR
                  <br/>
                  <div class="row">
                  <div class="col-md-6">
                    <span class="label label-success" style="font-size:14pt;font-weight:700">{$cats}</span>
                  </div>
                  <div class="col-md-6">
                 <ul class="nav nav-pills pull-right">
                     <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">Order By {$order_field} <b class="caret"></b></a>
                        <ul class="dropdown-menu">
                         <li><a href="{$burl}orderby=title&order=asc">{$ttitle}</a></li>
                         <!-- li><a href="{$burl}orderby=download_count&order=desc">{$tdls}</a></li -->
                         <li><a href="{$burl}orderby=publish_date&order=desc">{$tcdate}</a></li>
                        </ul>
                     </li>
                     <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">{$order} <b class="caret"></b></a>
                        <ul class="dropdown-menu">
                         <li><a href="{$burl}orderby={$orderby}&order=asc">{$tasc}</a></li>
                         <li><a href="{$burl}orderby={$orderby}&order=desc">{$tdsc}</a></li>
                        </ul>
                     </li>

                 </ul>

                 </div>
                 </div><br/>
TBR;
    } else {
        $toolbar = '';
    }
    wp_reset_query();
    return "<div class='w3eden'><div class='wpdm-category'>" . $cimg . $desc . $toolbar . $subcats . $html . $pgn . "<div style='clear:both'></div></div></div>";
}