Example #1
0
function nm_home_tabs($cats, $width = 463, $height = 210)
{
    $cats = explode(',', $cats);
    $cat = get_category_by_slug($cats[0]);
    $cat = get_category($cat->category_parent);
    echo '<div id="tab-instance-' . $cat->slug . '" class="tabs" style="width: ' . $width . 'px;"><ul class="tabs-nav">';
    $class = ' class="tabs-nav-active"';
    //Generate the nav from the cats
    foreach ($cats as $cat) {
        $cat = get_category_by_slug($cat);
        echo '<li><a id="a-' . $cat->slug . '"' . $class . ' href="javascript:show_home_tab(\'a-' . $cat->slug . '\')">' . $cat->name . '</a></li>';
        $class = '';
    }
    echo '</ul><div class="tabs-content" style="height: ' . $height . 'px;">';
    foreach ($cats as $cat) {
        echo '<ul id="ul-' . $cat . '" class="tabs-content-ul">';
        //Check if is older then 3 days, if is then order by rand
        $orderby = '';
        query_posts('showposts=1&category_name=' . $cat);
        if (have_posts()) {
            while (have_posts()) {
                the_post();
                $older = date('YMD');
                $days_since = floor((date('U') - get_the_time('U')) / 86400);
                if ($days_since >= 4) {
                    $orderby = '&orderby=rand';
                }
            }
        }
        query_posts('showposts=5&category_name=' . $cat . $orderby);
        if (have_posts()) {
            while (have_posts()) {
                the_post();
                global $post;
                echo '<li class="tabs-content-item">
					<h4><a href="' . get_permalink() . '">' . $post->post_title . '</a></h4>' . '<a href="' . get_permalink() . '">' . article_image($post->ID, 'small', true) . '</a>';
                echo '<p>';
                wswwpx_content_extract('', '15', '15', 2, '', '', TRUE, FALSE);
                echo '</p>';
                echo '<p class="tabs-content-meta">';
                echo '<a href="' . get_permalink() . '">';
                comments_number('No Comments', '1 Comment', '% Comments');
                echo '</a> | Posted: ';
                the_time('l, F jS, Y');
                echo ' | By: <a href="' . getProfileLink($post->post_author) . '">';
                the_author();
                echo '</a>';
                echo '</p>';
                echo '</li>';
            }
        }
        echo '</ul>';
    }
    echo '</div>
		</div>';
}
Example #2
0
function images($atts, $thing = NULL)
{
    global $s, $c, $context, $p, $path_to_site, $thisimage, $thisarticle, $thispage, $pretext;
    extract(lAtts(array('name' => '', 'id' => '', 'category' => '', 'author' => '', 'realname' => '', 'extension' => '', 'thumbnail' => '', 'auto_detect' => 'article, category, author', 'label' => '', 'break' => br, 'wraptag' => '', 'class' => __FUNCTION__, 'html_id' => '', 'labeltag' => '', 'form' => '', 'pageby' => '', 'limit' => 0, 'offset' => 0, 'sort' => 'name ASC'), $atts));
    $safe_sort = doSlash($sort);
    $where = array();
    $has_content = $thing || $form;
    $filters = isset($atts['id']) || isset($atts['name']) || isset($atts['category']) || isset($atts['author']) || isset($atts['realname']) || isset($atts['extension']) || $thumbnail === '1' || $thumbnail === '0';
    $context_list = empty($auto_detect) || $filters ? array() : do_list($auto_detect);
    $pageby = $pageby == 'limit' ? $limit : $pageby;
    if ($name) {
        $where[] = "name IN ('" . join("','", doSlash(do_list($name))) . "')";
    }
    if ($category) {
        $where[] = "category IN ('" . join("','", doSlash(do_list($category))) . "')";
    }
    if ($id) {
        $where[] = "id IN ('" . join("','", doSlash(do_list($id))) . "')";
    }
    if ($author) {
        $where[] = "author IN ('" . join("','", doSlash(do_list($author))) . "')";
    }
    if ($realname) {
        $authorlist = safe_column('name', 'txp_users', "RealName IN ('" . join("','", doArray(doSlash(do_list($realname)), 'urldecode')) . "')");
        $where[] = "author IN ('" . join("','", doSlash($authorlist)) . "')";
    }
    if ($extension) {
        $where[] = "ext IN ('" . join("','", doSlash(do_list($extension))) . "')";
    }
    if ($thumbnail === '0' || $thumbnail === '1') {
        $where[] = "thumbnail = {$thumbnail}";
    }
    // If no images are selected, try...
    if (!$where && !$filters) {
        foreach ($context_list as $ctxt) {
            switch ($ctxt) {
                case 'article':
                    // ...the article image field
                    if ($thisarticle && !empty($thisarticle['article_image'])) {
                        $items = do_list($thisarticle['article_image']);
                        $i = 0;
                        // TODO: Indexed array access required for PHP 4 compat. Replace with &$item in TXP5? @see [r3435].
                        foreach ($items as $item) {
                            if (is_numeric($item)) {
                                $items[$i] = intval($item);
                            } else {
                                return article_image(compact('class', 'html_id', 'wraptag'));
                            }
                            $i++;
                        }
                        $items = join(",", $items);
                        // NB: This clause will squash duplicate ids
                        $where[] = "id IN ({$items})";
                        // order of ids in article image field overrides default 'sort' attribute
                        if (empty($atts['sort'])) {
                            $safe_sort = "field(id, {$items})";
                        }
                    }
                    break;
                case 'category':
                    // ... the global category in the URL
                    if ($context == 'image' && !empty($c)) {
                        $where[] = "category = '" . doSlash($c) . "'";
                    }
                    break;
                case 'author':
                    // ... the global author in the URL
                    if ($context == 'image' && !empty($pretext['author'])) {
                        $where[] = "author = '" . doSlash($pretext['author']) . "'";
                    }
                    break;
            }
            // Only one context can be processed
            if ($where) {
                break;
            }
        }
    }
    // order of ids in 'id' attribute overrides default 'sort' attribute
    if (empty($atts['sort']) && $id !== '') {
        $safe_sort = 'field(id, ' . join(',', doSlash(do_list($id))) . ')';
    }
    if (!$where && $filters) {
        return '';
        // If nothing matches, output nothing
    }
    if (!$where) {
        $where[] = "1=1";
        // If nothing matches, start with all images
    }
    $where = join(' AND ', $where);
    // Set up paging if required
    if ($limit && $pageby) {
        $grand_total = safe_count('txp_image', $where);
        $total = $grand_total - $offset;
        $numPages = $pageby > 0 ? ceil($total / $pageby) : 1;
        $pg = !$pretext['pg'] ? 1 : $pretext['pg'];
        $pgoffset = $offset + ($pg - 1) * $pageby;
        // send paging info to txp:newer and txp:older
        $pageout['pg'] = $pg;
        $pageout['numPages'] = $numPages;
        $pageout['s'] = $s;
        $pageout['c'] = $c;
        $pageout['context'] = 'image';
        $pageout['grand_total'] = $grand_total;
        $pageout['total'] = $total;
        if (empty($thispage)) {
            $thispage = $pageout;
        }
    } else {
        $pgoffset = $offset;
    }
    $qparts = array($where, 'order by ' . $safe_sort, $limit ? 'limit ' . intval($pgoffset) . ', ' . intval($limit) : '');
    $rs = safe_rows_start('*', 'txp_image', join(' ', $qparts));
    if ($rs) {
        $out = array();
        if (isset($thisimage)) {
            $old_image = $thisimage;
        }
        while ($a = nextRow($rs)) {
            $thisimage = image_format_info($a);
            if (!$has_content) {
                $url = pagelinkurl(array('c' => $thisimage['category'], 'context' => 'image', 's' => $s, 'p' => $thisimage['id']));
                $src = image_url(array('thumbnail' => '1'));
                $thing = '<a href="' . $url . '">' . '<img src="' . $src . '" alt="' . txpspecialchars($thisimage['alt']) . '" />' . '</a>' . n;
            }
            $out[] = $thing ? parse($thing) : parse_form($form);
        }
        $thisimage = isset($old_image) ? $old_image : NULL;
        if ($out) {
            return doLabel($label, $labeltag) . doWrap($out, $wraptag, $break, $class, '', '', '', $html_id);
        }
    }
    return '';
}