Пример #1
0
/**
 * Gets an image as an array.
 *
 * @param   string     $where SQL where clause
 * @return  array|bool An image data, or FALSE on failure
 * @package Image
 * @example
 * if ($image = fileDownloadFetchInfo('id = 1'))
 * {
 *     print_r($image);
 * }
 */
function imageFetchInfo($where)
{
    $rs = safe_row('*', 'txp_image', $where);
    if ($rs) {
        return image_format_info($rs);
    }
    return false;
}
Пример #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 '';
}