Ejemplo n.º 1
0
function fileDownloadFetchInfo($where)
{
    $rs = safe_row('id, filename, category, description, downloads', 'txp_file', $where);
    if ($rs) {
        return file_download_format_info($rs);
    }
    return false;
}
Ejemplo n.º 2
0
/**
 * Gets a file download as an array.
 *
 * @param   string     $where SQL where clause
 * @return  array|bool An array of files, or FALSE on failure
 * @package File
 * @example
 * if ($file = fileDownloadFetchInfo('id = 1'))
 * {
 *     print_r($file);
 * }
 */
function fileDownloadFetchInfo($where)
{
    $rs = safe_row('*', 'txp_file', $where);
    if ($rs) {
        return file_download_format_info($rs);
    }
    return false;
}
Ejemplo n.º 3
0
function file_download_list($atts, $thing = null)
{
    global $s, $c, $context, $thisfile, $thispage, $pretext;
    extract(lAtts(array('break' => br, 'category' => '', 'author' => '', 'realname' => '', 'auto_detect' => 'category, author', 'class' => __FUNCTION__, 'form' => 'files', 'id' => '', 'label' => '', 'labeltag' => '', 'pageby' => '', 'limit' => 10, 'offset' => 0, 'sort' => 'filename asc', 'wraptag' => '', 'status' => STATUS_LIVE), $atts));
    if (!is_numeric($status)) {
        $status = getStatusNum($status);
    }
    // Note: status treated slightly differently.
    $where = $statwhere = array();
    $filters = isset($atts['id']) || isset($atts['category']) || isset($atts['author']) || isset($atts['realname']) || isset($atts['status']);
    $context_list = empty($auto_detect) || $filters ? array() : do_list($auto_detect);
    $pageby = $pageby == 'limit' ? $limit : $pageby;
    if ($category) {
        $where[] = "category IN ('" . join("','", doSlash(do_list($category))) . "')";
    }
    $ids = array_map('intval', do_list($id));
    if ($id) {
        $where[] = "id IN ('" . join("','", $ids) . "')";
    }
    if ($status) {
        $statwhere[] = "status = '" . doSlash($status) . "'";
    }
    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 no files are selected, try...
    if (!$where && !$filters) {
        foreach ($context_list as $ctxt) {
            switch ($ctxt) {
                case 'category':
                    // ...the global category in the URL.
                    if ($context == 'file' && !empty($c)) {
                        $where[] = "category = '" . doSlash($c) . "'";
                    }
                    break;
                case 'author':
                    // ...the global author in the URL.
                    if ($context == 'file' && !empty($pretext['author'])) {
                        $where[] = "author = '" . doSlash($pretext['author']) . "'";
                    }
                    break;
            }
            // Only one context can be processed.
            if ($where) {
                break;
            }
        }
    }
    if (!$where && !$statwhere && $filters) {
        // If nothing matches, output nothing.
        return '';
    }
    if (!$where) {
        // If nothing matches, start with all files.
        $where[] = "1=1";
    }
    $where = join(' AND ', array_merge($where, $statwhere));
    // Set up paging if required.
    if ($limit && $pageby) {
        $grand_total = safe_count('txp_file', $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'] = 'file';
        $pageout['grand_total'] = $grand_total;
        $pageout['total'] = $total;
        if (empty($thispage)) {
            $thispage = $pageout;
        }
    } else {
        $pgoffset = $offset;
    }
    // Preserve order of custom file ids unless 'sort' attribute is set.
    if (!empty($atts['id']) && empty($atts['sort'])) {
        $safe_sort = 'field(id, ' . join(',', $ids) . ')';
    } else {
        $safe_sort = doSlash($sort);
    }
    $qparts = array('order by ' . $safe_sort, $limit ? 'limit ' . intval($pgoffset) . ', ' . intval($limit) : '');
    $rs = safe_rows_start('*', 'txp_file', $where . ' ' . join(' ', $qparts));
    if ($rs) {
        $count = 0;
        $last = numRows($rs);
        $out = array();
        while ($a = nextRow($rs)) {
            ++$count;
            $thisfile = file_download_format_info($a);
            $thisfile['is_first'] = $count == 1;
            $thisfile['is_last'] = $count == $last;
            $out[] = $thing ? parse($thing) : parse_form($form);
            $thisfile = '';
        }
        if ($out) {
            return doLabel($label, $labeltag) . doWrap($out, $wraptag, $break, $class);
        }
    }
    return '';
}