Example #1
0
function file_download_list($atts)
{
    global $thisfile;
    extract(lAtts(array('break' => br, 'category' => '', 'class' => __FUNCTION__, 'form' => 'files', 'label' => '', 'labeltag' => '', 'limit' => '10', 'offset' => '0', 'sort' => 'filename asc', 'wraptag' => '', 'status' => '4'), $atts));
    if (!is_numeric($status)) {
        $status = getStatusNum($status);
    }
    $where = array('1=1');
    if ($category) {
        $where[] = "category IN ('" . join("','", doSlash(do_list($category))) . "')";
    }
    if ($status) {
        $where[] = "status = '" . doSlash($status) . "'";
    }
    $qparts = array('order by ' . doSlash($sort), $limit ? 'limit ' . intval($offset) . ', ' . intval($limit) : '');
    $rs = safe_rows_start('*, unix_timestamp(created) as created, unix_timestamp(modified) as modified', 'txp_file', join(' and ', $where) . ' ' . join(' ', $qparts));
    if ($rs) {
        $out = array();
        while ($thisfile = nextRow($rs)) {
            $out[] = parse_form($form);
            $thisfile = '';
        }
        if ($out) {
            if ($wraptag == 'ul' or $wraptag == 'ol') {
                return doLabel($label, $labeltag) . doWrap($out, $wraptag, $break, $class);
            }
            return $wraptag ? tag(join($break, $out), $wraptag) : join(n, $out);
        }
    }
    return '';
}
Example #2
0
 function row($row)
 {
     $tr = array();
     foreach ($row as $v) {
         $tr[] = $v;
     }
     if ($this->edit_actions and isset($row['id'])) {
         $tr[] = fInput('checkbox', 'selected[]', $row['id']);
     }
     return doWrap($tr, 'tr', 'td', 'row-' . (++$this->count % 2 ? 'odd' : 'even'));
 }
Example #3
0
 /**
  * Generates a list of authors.
  *
  * @param  array  $atts
  * @param  string $thing
  * @return string
  */
 public static function renderAuthors($atts, $thing = null)
 {
     global $thisauthor, $txp_groups;
     extract(lAtts(array('break' => '', 'class' => '', 'form' => '', 'group' => '', 'label' => '', 'labeltag' => '', 'limit' => '', 'name' => '', 'offset' => '', 'sort' => 'name ASC', 'wraptag' => ''), $atts));
     $sql = array('1 = 1');
     $sql_limit = '';
     $sql_sort = " ORDER BY " . doSlash($sort);
     if ($name) {
         $sql[] = "name IN (" . join(', ', quote_list(do_list($name))) . ")";
     }
     if ($group !== '') {
         $privs = do_list($group);
         $groups = array_flip($txp_groups);
         foreach ($privs as &$priv) {
             if (isset($groups[$priv])) {
                 $priv = $groups[$priv];
             }
         }
         $sql[] = 'convert(privs, char) in (' . join(', ', quote_list($privs)) . ')';
     }
     if ($limit !== '' || $offset) {
         $sql_limit = " LIMIT " . intval($offset) . ", " . ($limit === '' ? PHP_INT_MAX : intval($limit));
     }
     $rs = safe_rows_start("user_id as id, name, RealName as realname, email, privs, last_access", 'txp_users', join(" AND ", $sql) . " {$sql_sort} {$sql_limit}");
     if ($rs && numRows($rs)) {
         $out = array();
         if ($thing === null && $form !== '') {
             $thing = fetch_form($form);
         }
         while ($a = nextRow($rs)) {
             $oldauthor = $thisauthor;
             $thisauthor = $a;
             $out[] = parse($thing);
             $thisauthor = $oldauthor;
         }
         unset($thisauthor);
         return doLabel($label, $labeltag) . doWrap($out, $wraptag, $break, $class);
     }
     return '';
 }
Example #4
0
 function row($row)
 {
     global $prefs;
     extract($prefs);
     if (!$this->controller) {
         return;
     }
     extract($this->controller->context);
     extract($row);
     $event = $this->controller->event;
     $edit_url = "?event={$event}" . a . 'step=edit' . a . 'id=' . $id . a . 'sort=' . $sort . a . 'dir=' . $dir . a . 'page=' . $page . a . 'search_method=' . $search_method . a . 'crit=' . $crit;
     $name = empty($name) ? gTxt('unnamed') : htmlspecialchars($name);
     if ($thumbnail) {
         if ($ext != '.swf') {
             $thumbnail = '<img src="' . hu . $img_dir . '/' . $id . 't' . $ext . '" alt="" />';
         } else {
             $thumbnail = '';
         }
     }
     if ($ext != '.swf') {
         $tag_url = '?event=tag' . a . 'tag_name=image' . a . 'id=' . $id . a . 'ext=' . $ext . a . 'w=' . $w . a . 'h=' . $h . a . 'alt=' . urlencode($alt) . a . 'caption=' . urlencode($caption);
         $tagbuilder = '<ul>' . '<li><a target="_blank" href="' . $tag_url . a . 'type=textile" onclick="popWin(this.href); return false;">Textile</a></li>' . '<li><a target="_blank" href="' . $tag_url . a . 'type=textpattern" onclick="popWin(this.href); return false;">Textpattern</a></li>' . '<li><a target="_blank" href="' . $tag_url . a . 'type=xhtml" onclick="popWin(this.href); return false;">XHTML</a></li>' . '</ul>';
     } else {
         $tagbuilder = sp;
     }
     $category = $category ? '<span title="' . htmlspecialchars(fetch_category_title($category, 'image')) . '">' . $category . '</span>' : '';
     $tr = array();
     $tr[] = $id;
     $tr[] = n . '<ul>' . n . t . '<li>' . href(gTxt('edit'), $edit_url) . '</li>' . n . t . '<li><a href="' . hu . $img_dir . '/' . $id . $ext . '">' . gTxt('view') . '</a></li>' . n . '</ul>';
     $tr[] = gTime($uDate);
     $tr[] = href($name, $edit_url);
     $tr[] = $thumbnail;
     $tr[] = $tagbuilder;
     $tr[] = $category;
     $tr[] = '<span title="' . htmlspecialchars(get_author_name($author)) . '">' . $author . '</span>';
     $tr[] = dLink($this->controller->event, 'delete', 'id', $id, '', '', '', false, array($page, $sort, $dir, $crit, $search_method));
     if ($this->edit_actions and isset($row['id'])) {
         $tr[] = fInput('checkbox', 'selected[]', $row['id']);
     }
     return doWrap($tr, 'tr', 'td', 'row-' . (++$this->count % 2 ? 'odd' : 'even'));
 }
Example #5
0
function adi_menu($atts)
{
    global $s, $out, $sort, $menu_id, $parent_class, $active_class, $exclude, $sections, $default_title, $default_first, $clone_title, $include_default, $class, $link_span, $list_id, $list_id_prefix, $active_li_class;
    extract(lAtts(array('active_class' => 'active_class', 'active_li_class' => '', 'class' => 'section_list', 'include_default' => '1', 'default_title' => 'Home', 'exclude' => '', 'sections' => '', 'sort' => 'NULL', 'menu_id' => 'mainmenu', 'parent_class' => 'menuparent', 'default_first' => '1', 'clone_title' => 'Summary', 'link_span' => '0', 'list_id' => '0', 'list_id_prefix' => 'menu_', 'debug' => '0'), $atts));
    $default_title = trim($default_title);
    $clone_title = trim($clone_title);
    if (empty($clone_title)) {
        // don't want it to be empty
        $clone_title = 'Summary';
    }
    $sections = trim($sections);
    // menu not output if sections = " "
    $sort = trim($sort);
    // MySQL error if sort = " "
    // set sort to database order by default
    empty($sort) ? $sort = 'NULL' : ($sort = doSlash($sort));
    /* adi_menu - main procedure */
    $section_list = adi_menu_section_list(FALSE);
    $hierarchy = adi_menu_hierarchy($section_list, '', 0);
    if ($debug) {
        echo "SECTION LIST<br/>";
        dmp($section_list);
        echo "HIERARCHY<br/>";
        dmp($hierarchy);
    }
    $out = adi_menu_markup($hierarchy, 0);
    return doWrap($out, '', '');
}
Example #6
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' => '4'), $atts));
    if (!is_numeric($status)) {
        $status = getStatusNum($status);
    }
    // N.B. 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) {
        return '';
        // If nothing matches, output nothing
    }
    if (!$where) {
        $where[] = "1=1";
        // If nothing matches, start with all files
    }
    $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) {
        $out = array();
        while ($a = nextRow($rs)) {
            $thisfile = file_download_format_info($a);
            $out[] = $thing ? parse($thing) : parse_form($form);
            $thisfile = '';
        }
        if ($out) {
            return doLabel($label, $labeltag) . doWrap($out, $wraptag, $break, $class);
        }
    }
    return '';
}
Example #7
0
function doHomeArticles($atts, $thing = NULL)
{
    global $pretext, $prefs;
    extract($pretext);
    extract($prefs);
    $customFields = getCustomFields();
    $customlAtts = array_null(array_flip($customFields));
    //getting attributes
    $theAtts = lAtts(array('form' => 'default', 'listform' => '', 'searchform' => '', 'limit' => 10, 'category' => '', 'section' => '', 'excerpted' => '', 'author' => '', 'sort' => '', 'month' => '', 'keywords' => '', 'frontpage' => '', 'time' => 'past', 'pgonly' => 0, 'searchall' => 1, 'allowoverride' => true, 'offset' => 0, 'wraptag' => '', 'break' => '', 'label' => '', 'labeltag' => '', 'class' => '') + $customlAtts, $atts);
    $theAtts['category'] = $c ? $c : '';
    $theAtts['section'] = $s && $s != 'default' && $s != 'home' ? $s : '';
    $theAtts['author'] = !empty($author) ? $author : '';
    $theAtts['month'] = !empty($month) ? $month : '';
    $theAtts['frontpage'] = $s && $s == 'home' ? true : false;
    $theAtts['excerpted'] = '';
    extract($theAtts);
    // if a listform is specified, $thing is for doArticle() - hence ignore here.
    if (!empty($listform)) {
        $thing = '';
    }
    $pageby = empty($pageby) ? $limit : $pageby;
    $match = $search = '';
    if (!$sort) {
        $sort = 'Posted desc';
    }
    //Building query parts
    $frontpage = filterFrontPage();
    $category = join("','", doSlash(do_list($category)));
    $category = !$category ? '' : " and (Category1 IN ('" . $category . "') or Category2 IN ('" . $category . "'))";
    $section = !$section ? '' : " and Section IN ('" . join("','", doSlash(do_list($section))) . "')";
    $excerpted = $excerpted == 'y' ? " and Excerpt !=''" : '';
    $author = !$author ? '' : " and AuthorID IN ('" . join("','", doSlash(do_list($author))) . "')";
    $month = !$month ? '' : " and Posted like '" . doSlash($month) . "%'";
    $id = !$id ? '' : " and ID IN (" . join(',', array_map('intval', do_list($id))) . ")";
    switch ($time) {
        case 'any':
            $time = "";
            break;
        case 'future':
            $time = " and Posted > now()";
            break;
        default:
            $time = " and Posted <= now()";
    }
    if (!$publish_expired_articles) {
        $time .= " and (now() <= Expires or Expires = " . NULLDATETIME . ")";
    }
    $custom = '';
    if ($customFields) {
        foreach ($customFields as $cField) {
            if (isset($atts[$cField])) {
                $customPairs[$cField] = $atts[$cField];
            }
        }
        if (!empty($customPairs)) {
            $custom = buildCustomSql($customFields, $customPairs);
        }
    }
    $statusq = ' and Status = 5';
    $where = "1=1" . $statusq . $time . $search . $category . $section . $excerpted . $month . $author . $keywords . $custom . $frontpage;
    $rs = safe_rows_start("*, unix_timestamp(Posted) as uPosted, unix_timestamp(Expires) as uExpires, unix_timestamp(LastMod) as uLastMod" . $match, 'textpattern', $where . ' order by ' . doSlash($sort) . ' limit 0' . intval($limit));
    // get the form name
    $fname = $listform ? $listform : $form;
    if ($rs) {
        $count = 0;
        $last = numRows($rs);
        $articles = array();
        while ($a = nextRow($rs)) {
            ++$count;
            populateArticleData($a);
            global $thisarticle, $uPosted, $limit;
            $thisarticle['is_first'] = $count == 1;
            $thisarticle['is_last'] = $count == $last;
            if (@constant('txpinterface') === 'admin' and gps('Form')) {
                $articles[] = parse(gps('Form'));
            } elseif ($allowoverride and $a['override_form']) {
                $articles[] = parse_form($a['override_form']);
            } else {
                $articles[] = $thing ? parse($thing) : parse_form($fname);
            }
            // sending these to paging_link(); Required?
            $uPosted = $a['uPosted'];
            unset($GLOBALS['thisarticle']);
        }
        return doLabel($label, $labeltag) . doWrap($articles, $wraptag, $break, $class);
    }
}
function sed_comments($atts)
{
    global $thisarticle, $prefs, $comment_preview, $pretext;
    extract($prefs);
    extract(lAtts(array('id' => @$pretext['id'], 'form' => 'comments', 'wraptag' => $comments_are_ol ? 'ol' : '', 'break' => $comments_are_ol ? 'li' : 'div', 'class' => __FUNCTION__, 'breakclass' => '', 'sort' => 'posted ASC'), $atts));
    assert_article();
    if (is_array($thisarticle)) {
        extract($thisarticle);
    }
    if (@$thisid) {
        $id = $thisid;
    }
    #
    #	Extract the sed article overrides...
    #	Access the custom field that houses the vars and explode the string on ';' boundaries.
    #
    $sed_vars = _sed_cp_get_sed_vars(@$thisarticle['sed per-article vars']);
    $sed_vars = lAtts(array('sed_delay' => '0', 'sed_ttl' => '', 'sed_on_cull' => 'hide', 'sed_ttl_grace' => ''), $sed_vars);
    extract($sed_vars);
    if (!empty($comment_preview)) {
        $preview = psas(array('name', 'email', 'web', 'message', 'parentid', 'remember'));
        $preview['time'] = time();
        $preview['discussid'] = 0;
        $preview['message'] = markup_comment($preview['message']);
        $GLOBALS['thiscomment'] = $preview;
        $comments[] = parse_form($form) . n;
        unset($GLOBALS['thiscomment']);
        $out = doWrap($comments, $wraptag, $break, $class, $breakclass);
    } else {
        $rs = safe_rows_start("*, unix_timestamp(posted) as time", "txp_discuss", 'parentid=' . intval($id) . ' and visible=' . VISIBLE . ' order by ' . doSlash($sort));
        $out = '';
        if ($rs) {
            $comments = array();
            $culled_comments = array();
            while ($vars = nextRow($rs)) {
                $culled = false;
                $show = true;
                $extra = '';
                $now = time();
                $remaining = '';
                #
                #	If the comment is in a deleting page then check if it is to be culled...
                #
                if (!empty($sed_ttl)) {
                    $do_cull_check = true;
                    #
                    #	Are we in any grace period???
                    #
                    if (!empty($sed_ttl_grace) && 0 != $sed_ttl_grace) {
                        $do_cull_check = _sed_cp_if_outside_period($thisarticle['posted'], $sed_ttl_grace, $vars['time'], $remaining);
                    }
                    #
                    #	If not then do the cull checking...
                    #
                    if ($do_cull_check) {
                        $culled = _sed_cp_if_outside_period($vars['time'], $sed_ttl, $now, $remaining);
                    }
                    #
                    #	Display how long to go before culling.
                    #
                    if ($do_cull_check && !$culled) {
                        $vars['message'] .= "<br/><br/><strong>[MARKED FOR DELETION IN {$remaining}.]</strong>";
                    }
                }
                if ($culled) {
                    $extra .= ' culled';
                    $culled_comments[] = $vars;
                    $vars['time'] = $now;
                    $vars['message'] .= "<br/><br/><strong>[DELETED.]</strong>";
                } else {
                    #
                    #	See if the comment is in its "hidden" period.
                    #	This is to try and discourage spam-robots that immediately see if their posts appear live.
                    #
                    if (!empty($sed_delay) && $sed_delay > '0') {
                        $show = _sed_cp_if_outside_period($vars['time'], $sed_delay, $now, $remaining);
                    }
                    #
                    #	Still hidden so show a place-holder comment instead.
                    #
                    if (!$show) {
                        $extra .= ' delay_queue';
                        $vars['name'] = "[DELAYED]";
                        $vars['time'] = $now;
                        $vars['message'] = "A comment has been recorded and is in the delay queue.";
                        $vars['message'] .= "<br/><br/><strong>[REVEALED IN {$remaining}.]</strong>";
                    }
                }
                #
                #	Save the additional css class markup for this comment in the vars before parsing the comment form.
                #
                $vars['sed_class_extra'] = $extra;
                $GLOBALS['thiscomment'] = $vars;
                $comments[] = parse_form($form) . n;
                unset($GLOBALS['thiscomment']);
            }
            $out .= doWrap($comments, $wraptag, $break, $class, $breakclass);
            #
            #	Process the culled list...
            #
            if (!empty($culled_comments)) {
                foreach ($culled_comments as $comment) {
                    if ('delete' == $sed_on_cull) {
                        _sed_cp_delete_comment($comment);
                    } else {
                        _sed_cp_update_comment($comment, $sed_on_cull);
                    }
                }
                update_comments_count($id);
            }
        }
    }
    return $out;
}
Example #9
0
function zem_event_search_input($atts)
{
    global $pretext, $zem_event_has_js;
    extract(lAtts(array('class' => __FUNCTION__, 'break' => 'br', 'wraptag' => 'div', 'class' => __FUNCTION__, 'breakclass' => '', 'sep' => '&nbsp;', 'method' => 'post', 'section' => @$pretext['s']), $atts));
    $out[] = '<label for="date_from">From:</label>' . $sep . '<input type="text" name="date_from" id="date_from" class="zem_date_select" value="' . htmlspecialchars(gps('date_from')) . '" />';
    $out[] = '<label for="date_to">To:</label>' . $sep . '<input type="text" name="date_to" id="date_to" class="zem_date_select" value="' . htmlspecialchars(gps('date_to')) . '" />';
    $out[] = '<label for="q">Search:</label>' . $sep . '<input type="text" name="q" id="q" value="' . htmlspecialchars(gps('q')) . '" />';
    $cats = getTree('root', 'event');
    $fs_c = '<legend>Category</legend>';
    $fs_c .= '<input type="checkbox" name="all_categories" id="all_categories" value="1"' . (gps('all_categories') ? ' checked="checked"' : '') . ' />' . $sep . '<label for="all_categories">All Categories</label>' . br . n;
    $gps_c = gps('c') ? gps('c') : array();
    foreach ($cats as $c) {
        $fs_c .= '<input type="checkbox" name="c[' . $c['name'] . ']" id="c[' . $c['name'] . ']" value="' . $c['name'] . '"' . (in_array($c['name'], $gps_c) ? ' checked="checked"' : '') . ' />' . $sep . '<label for="c[' . $c['name'] . ']">' . htmlspecialchars($c['title']) . '</label>' . br . n;
    }
    $out[] = '<fieldset id="category">' . $fs_c . '</fieldset>';
    $locs = safe_column('distinct location as l', 'zem_event_calendar', '1=1 order by location asc');
    $fs_l = '<legend>Location</legend>';
    $fs_l .= '<input type="checkbox" name="all_locations" id="all_locations" value="1"' . (gps('all_locations') ? ' checked="checked"' : '') . ' />' . $sep . '<label for="all_locations">All Locations</label>' . br . n;
    $gps_l = gps('location') ? gps('location') : array();
    foreach ($locs as $l) {
        $fs_l .= '<input type="checkbox" name="location[' . $l . ']" id="location[' . $l . ']" value="' . $l . '"' . (in_array($l, $gps_l) ? ' checked="checked"' : '') . ' />' . $sep . '<label for="location[' . $l . ']">' . htmlspecialchars($l) . '</label>' . br . n;
    }
    $out[] = '<fieldset id="location">' . $fs_l . '</fieldset>';
    $out[] = '<input type="submit" name="search" value="Search" />';
    $js = '';
    if ($zem_event_has_js) {
        if (zem_event_date_format() == 'MM/dd/yyyy') {
            $format = 'mdy';
            $ds = '/';
        } else {
            $format = 'ymd';
            $ds = '-';
        }
        $js = script_js('$.datePicker.setDateFormat(\'' . $format . '\',\'' . $ds . '\');
	$(\'input.zem_date_select\').datePicker();');
    }
    $url = pagelinkurl(array('s' => $section));
    return '<form action="' . $url . '" method="post">' . doWrap($out, $wraptag, $break, $class, $breakclass) . '</form>' . n . $js;
}
Example #10
0
function doArticles($atts, $iscustom, $thing = null)
{
    global $pretext, $prefs;
    extract($pretext);
    extract($prefs);
    $customFields = getCustomFields();
    $customlAtts = array_null(array_flip($customFields));
    if ($iscustom) {
        $extralAtts = array('category' => '', 'section' => '', 'excerpted' => '', 'author' => '', 'month' => '', 'expired' => $publish_expired_articles, 'id' => '', 'exclude' => '');
    } else {
        $extralAtts = array('listform' => '', 'searchform' => '', 'searchall' => 1, 'searchsticky' => 0, 'pageby' => '', 'pgonly' => 0);
    }
    // Getting attributes.
    $theAtts = lAtts(array('form' => 'default', 'limit' => 10, 'sort' => '', 'sortby' => '', 'sortdir' => '', 'keywords' => '', 'time' => 'past', 'status' => STATUS_LIVE, 'allowoverride' => !$q and !$iscustom, 'offset' => 0, 'wraptag' => '', 'break' => '', 'label' => '', 'labeltag' => '', 'class' => '') + $customlAtts + $extralAtts, $atts);
    // For the txp:article tag, some attributes are taken from globals;
    // override them, then stash all filter attributes.
    if (!$iscustom) {
        $theAtts['category'] = $c ? $c : '';
        $theAtts['section'] = $s && $s != 'default' ? $s : '';
        $theAtts['author'] = !empty($author) ? $author : '';
        $theAtts['month'] = !empty($month) ? $month : '';
        $theAtts['frontpage'] = $s && $s == 'default' ? true : false;
        $theAtts['excerpted'] = 0;
        $theAtts['exclude'] = 0;
        $theAtts['expired'] = $publish_expired_articles;
        filterAtts($theAtts);
    } else {
        $theAtts['frontpage'] = false;
    }
    extract($theAtts);
    // If a listform is specified, $thing is for doArticle() - hence ignore here.
    if (!empty($listform)) {
        $thing = '';
    }
    $pageby = empty($pageby) ? $limit : $pageby;
    // Treat sticky articles differently wrt search filtering, etc.
    $status = in_array(strtolower($status), array('sticky', STATUS_STICKY)) ? STATUS_STICKY : STATUS_LIVE;
    $issticky = $status == STATUS_STICKY;
    // Give control to search, if necessary.
    if ($q && !$iscustom && !$issticky) {
        include_once txpath . '/publish/search.php';
        $s_filter = $searchall ? filterSearch() : '';
        $q = trim($q);
        $quoted = $q[0] === '"' && $q[strlen($q) - 1] === '"';
        $q = doSlash($quoted ? trim(trim($q, '"')) : $q);
        // Searchable article fields are limited to the columns of the
        // textpattern table and a matching fulltext index must exist.
        $cols = do_list_unique($searchable_article_fields);
        if (empty($cols) or $cols[0] == '') {
            $cols = array('Title', 'Body');
        }
        $match = ", MATCH (`" . join("`, `", $cols) . "`) AGAINST ('{$q}') AS score";
        $search_terms = preg_replace('/\\s+/', ' ', str_replace(array('\\', '%', '_', '\''), array('\\\\', '\\%', '\\_', '\\\''), $q));
        if ($quoted || empty($m) || $m === 'exact') {
            for ($i = 0; $i < count($cols); $i++) {
                $cols[$i] = "`{$cols[$i]}` LIKE '%{$search_terms}%'";
            }
        } else {
            $colJoin = $m === 'any' ? "OR" : "AND";
            $search_terms = explode(' ', $search_terms);
            for ($i = 0; $i < count($cols); $i++) {
                $like = array();
                foreach ($search_terms as $search_term) {
                    $like[] = "`{$cols[$i]}` LIKE '%{$search_term}%'";
                }
                $cols[$i] = "(" . join(" {$colJoin} ", $like) . ")";
            }
        }
        $cols = join(" OR ", $cols);
        $search = " AND ({$cols}) {$s_filter}";
        // searchall=0 can be used to show search results for the current
        // section only.
        if ($searchall) {
            $section = '';
        }
        if (!$sort) {
            $sort = "score DESC";
        }
    } else {
        $match = $search = '';
        if (!$sort) {
            $sort = "Posted DESC";
        }
    }
    // For backwards compatibility. sortby and sortdir are deprecated.
    if ($sortby) {
        trigger_error(gTxt('deprecated_attribute', array('{name}' => 'sortby')), E_USER_NOTICE);
        if (!$sortdir) {
            $sortdir = "DESC";
        } else {
            trigger_error(gTxt('deprecated_attribute', array('{name}' => 'sortdir')), E_USER_NOTICE);
        }
        $sort = "{$sortby} {$sortdir}";
    } elseif ($sortdir) {
        trigger_error(gTxt('deprecated_attribute', array('{name}' => 'sortdir')), E_USER_NOTICE);
        $sort = "Posted {$sortdir}";
    }
    // Building query parts.
    $frontpage = ($frontpage and (!$q or $issticky)) ? filterFrontPage() : '';
    $category = join("','", doSlash(do_list_unique($category)));
    $category = !$category ? '' : " AND (Category1 IN ('" . $category . "') OR Category2 IN ('" . $category . "'))";
    $section = !$section ? '' : " AND Section IN ('" . join("','", doSlash(do_list_unique($section))) . "')";
    $excerpted = !$excerpted ? '' : " AND Excerpt !=''";
    $author = !$author ? '' : " AND AuthorID IN ('" . join("','", doSlash(do_list_unique($author))) . "')";
    $month = !$month ? '' : " AND Posted LIKE '" . doSlash($month) . "%'";
    $ids = $id ? array_map('intval', do_list_unique($id)) : array();
    $exclude = $exclude ? array_map('intval', do_list_unique($exclude)) : array();
    $id = (!$id ? '' : " AND ID IN (" . join(',', $ids) . ")") . (!$exclude ? '' : " AND ID NOT IN (" . join(',', $exclude) . ")");
    switch ($time) {
        case 'any':
            $time = "";
            break;
        case 'future':
            $time = " AND Posted > " . now('posted');
            break;
        default:
            $time = " AND Posted <= " . now('posted');
    }
    if (!$expired) {
        $time .= " AND (" . now('expires') . " <= Expires OR Expires = " . NULLDATETIME . ")";
    }
    $custom = '';
    if ($customFields) {
        foreach ($customFields as $cField) {
            if (isset($atts[$cField])) {
                $customPairs[$cField] = $atts[$cField];
            }
        }
        if (!empty($customPairs)) {
            $custom = buildCustomSql($customFields, $customPairs);
        }
    }
    // Allow keywords for no-custom articles. That tagging mode, you know.
    if ($keywords) {
        $keys = doSlash(do_list_unique($keywords));
        foreach ($keys as $key) {
            $keyparts[] = "FIND_IN_SET('" . $key . "', Keywords)";
        }
        $keywords = " AND (" . join(' or ', $keyparts) . ")";
    }
    if ($q and $searchsticky) {
        $statusq = " AND Status >= " . STATUS_LIVE;
    } elseif ($id) {
        $statusq = " AND Status >= " . STATUS_LIVE;
    } else {
        $statusq = " AND Status = " . intval($status);
    }
    $where = "1 = 1" . $statusq . $time . $search . $id . $category . $section . $excerpted . $month . $author . $keywords . $custom . $frontpage;
    // Do not paginate if we are on a custom list.
    if (!$iscustom and !$issticky) {
        $grand_total = safe_count('textpattern', $where);
        $total = $grand_total - $offset;
        $numPages = ceil($total / $pageby);
        $pg = !$pg ? 1 : $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'] = 'article';
        $pageout['grand_total'] = $grand_total;
        $pageout['total'] = $total;
        global $thispage;
        if (empty($thispage)) {
            $thispage = $pageout;
        }
        if ($pgonly) {
            return;
        }
    } else {
        $pgoffset = $offset;
    }
    // Preserve order of custom article ids unless 'sort' attribute is set.
    if (!empty($atts['id']) && empty($atts['sort'])) {
        $safe_sort = "FIELD(id, " . join(',', $ids) . ")";
    } else {
        $safe_sort = doSlash($sort);
    }
    $rs = safe_rows_start("*, UNIX_TIMESTAMP(Posted) AS uPosted, UNIX_TIMESTAMP(Expires) AS uExpires, UNIX_TIMESTAMP(LastMod) AS uLastMod" . $match, 'textpattern', "{$where} ORDER BY {$safe_sort} LIMIT " . intval($pgoffset) . ", " . intval($limit));
    // Get the form name.
    if ($q and !$iscustom and !$issticky) {
        $fname = $searchform ? $searchform : 'search_results';
    } else {
        $fname = !empty($listform) ? $listform : $form;
    }
    if ($rs) {
        $count = 0;
        $last = numRows($rs);
        $articles = array();
        while ($a = nextRow($rs)) {
            ++$count;
            populateArticleData($a);
            global $thisarticle, $uPosted, $limit;
            $thisarticle['is_first'] = $count == 1;
            $thisarticle['is_last'] = $count == $last;
            // Article form preview.
            if (txpinterface === 'admin' && ps('Form')) {
                doAuth();
                if (!has_privs('form')) {
                    txp_status_header('401 Unauthorized');
                    exit(hed('401 Unauthorized', 1) . graf(gTxt('restricted_area')));
                }
                $articles[] = parse(gps('Form'));
            } elseif ($allowoverride and $a['override_form']) {
                $articles[] = parse_form($a['override_form']);
            } else {
                $articles[] = $thing ? parse($thing) : parse_form($fname);
            }
            // Sending these to paging_link(); Required?
            $uPosted = $a['uPosted'];
            unset($GLOBALS['thisarticle']);
        }
        return doLabel($label, $labeltag) . doWrap($articles, $wraptag, $break, $class);
    }
}
Example #11
0
function sed_pcf_for_each_value($atts, $thing)
{
    global $thisarticle;
    assert_article();
    $def_custom_name = 'custom1';
    extract($merged = lAtts(array('debug' => 0, 'name' => $def_custom_name, 'id' => '', 'form' => '', 'label' => '', 'labeltag' => '', 'wraptag' => 'ul', 'break' => 'li', 'class' => ''), $atts));
    if ($debug) {
        echo dmp($merged);
    }
    $field = @$thisarticle[$name];
    if (empty($field)) {
        if ($debug) {
            echo "Returning early - nothing to do in CF[{$name}].";
        }
        return '';
    }
    if (empty($class)) {
        $class = $name;
    }
    if (!empty($form)) {
        # grab the form (if any)
        $thing = fetch_form($form);
    }
    if (empty($thing)) {
        # if no form, and no enclosed thing, use built-in formula...
        $thing = '{value}';
    }
    $out = array();
    $field = do_list($field);
    foreach ($field as $value) {
        $out[] = parse(str_replace('{value}', $value, $thing));
    }
    return doLabel($label, $labeltag) . doWrap($out, $wraptag, $break, $class, '', '', '', $id);
}
Example #12
0
function file_download_list($atts, $thing = NULL)
{
    global $thisfile;
    extract(lAtts(array('break' => br, 'category' => '', 'class' => __FUNCTION__, 'form' => 'files', 'label' => '', 'labeltag' => '', 'limit' => 10, 'offset' => 0, 'sort' => 'filename asc', 'wraptag' => '', 'status' => '4'), $atts));
    if (!is_numeric($status)) {
        $status = getStatusNum($status);
    }
    $where = array('1=1');
    if ($category) {
        $where[] = "category IN ('" . join("','", doSlash(do_list($category))) . "')";
    }
    if ($status) {
        $where[] = "status = '" . doSlash($status) . "'";
    }
    $qparts = array('order by ' . doSlash($sort), $limit ? 'limit ' . intval($offset) . ', ' . intval($limit) : '');
    $rs = safe_rows_start('*', 'txp_file', join(' and ', $where) . ' ' . join(' ', $qparts));
    if ($rs) {
        $out = array();
        while ($a = nextRow($rs)) {
            $thisfile = file_download_format_info($a);
            $out[] = $thing ? parse($thing) : parse_form($form);
            $thisfile = '';
        }
        if ($out) {
            return doLabel($label, $labeltag) . doWrap($out, $wraptag, $break, $class);
        }
    }
    return '';
}
    function mem_self_register_install()
    {
        global $mem_self;
        extract(doSlash(gpsa(array('admin_email', 'admin_name', 'new_user_priv', 'use_ign_db', 'add_address', 'add_phone'))));
        if (!isset($new_user_priv) || empty($new_user_priv)) {
            $new_user_priv = '0';
        }
        $log = array();
        if (!($rs = safe_field('val,html', 'txp_prefs', "name='mem_self_use_ign_db'"))) {
            if (set_pref('mem_self_use_ign_db', $use_ign_db, 'self_reg', 1, 0, 'yesnoradio')) {
                $log[] = mem_self_gTxt('log_added_pref', array('{name}' => 'mem_self_use_ign_db'));
            } else {
                $log[] = mem_self_gTxt('log_pref_failed', array('{name}' => 'mem_self_use_ign_db', '{error}' => mysql_error()));
            }
        } else {
            if ($rs['html'] != 'yesnoradio') {
                safe_update('txp_prefs', "html='yesnoradio'", "name='mem_self_use_ign_db'");
            }
            $log[] = mem_self_gTxt('log_pref_exists', array('{name}' => 'mem_self_use_ign_db', '{value}' => $rs));
        }
        $user_table = mem_get_user_table_name();
        $xtra_columns = mem_get_extra_user_columns();
        if ($add_address) {
            if (!in_array('address', $xtra_columns)) {
                if (safe_alter($user_table, "ADD `address` VARCHAR( 128 )")) {
                    $log[] = mem_self_gTxt('log_col_added', array('{name}' => 'address', '{table}' => $user_table));
                } else {
                    $log[] = mem_self_gTxt('log_col_failed', array('{name}' => 'address', '{table}' => $user_table, '{error}' => mysql_error()));
                }
            } else {
                $log[] = mem_self_gTxt('log_col_exists', array('{name}' => 'address', '{table}' => $user_table));
            }
        }
        if ($add_phone) {
            if (!in_array('phone', $xtra_columns)) {
                if (safe_alter($user_table, "ADD `phone` VARCHAR( 32 )")) {
                    $log[] = mem_self_gTxt('log_col_added', array('{name}' => 'phone', '{table}' => $user_table));
                } else {
                    $log[] = mem_self_gTxt('log_col_failed', array('{name}' => 'phone', '{table}' => $user_table, '{error}' => mysql_error()));
                }
            } else {
                $log[] = mem_self_gTxt('log_col_exists', array('{name}' => 'phone', '{table}' => $user_table));
            }
        }
        if (!($rs = safe_field('val', 'txp_prefs', "name='mem_self_admin_email'"))) {
            if (set_pref('mem_self_admin_email', $admin_email, 'self_reg', 1)) {
                $log[] = mem_self_gTxt('log_added_pref', array('{name}' => 'mem_self_admin_email'));
            } else {
                $log[] = mem_self_gTxt('log_pref_failed', array('{name}' => 'mem_self_admin_email', '{error}' => mysql_error()));
            }
        } else {
            $log[] = mem_self_gTxt('log_pref_exists', array('{name}' => 'mem_self_admin_email', '{value}' => $rs));
        }
        if (!($rs = safe_field('val', 'txp_prefs', "name='mem_self_admin_name'"))) {
            if (set_pref('mem_self_admin_name', $admin_name, 'self_reg', 1)) {
                $log[] = mem_self_gTxt('log_added_pref', array('{name}' => 'mem_self_admin_name'));
            } else {
                $log[] = mem_self_gTxt('log_pref_failed', array('{name}' => 'mem_self_admin_name', '{error}' => mysql_error()));
            }
        } else {
            $log[] = mem_self_gTxt('log_pref_exists', array('{name}' => 'mem_self_admin_name', '{value}' => $rs));
        }
        if (!($rs = safe_row('val,html', 'txp_prefs', "name='mem_self_new_user_priv'"))) {
            if (set_pref('mem_self_new_user_priv', $new_user_priv, 'self_reg', 1, 0, 'priv_levels')) {
                $log[] = mem_self_gTxt('log_added_pref', array('{name}' => 'mem_self_new_user_priv'));
                $mem_self['new_user_priv'] = $new_user_priv;
            } else {
                $log[] = mem_self_gTxt('log_pref_failed', array('{name}' => 'mem_self_newuser_priv', '{error}' => mysql_error()));
            }
        } else {
            safe_update('txp_prefs', "html='priv_levels'", "name='mem_self_new_user_priv'");
            $log[] = mem_self_gTxt('log_pref_exists', array('{name}' => 'mem_self_new_user_priv', '{value}' => $rs));
        }
        // create default registration form
        $form_html = <<<EOF
\t<fieldset>
\t<legend>Register</legend>
\t\t<txp:mem_form_text name="RealName" label="Full Name" /><br />
\t\t<br />
\t\t
\t\t<txp:mem_form_text name="name" label="Username" /><br />
\t\t<br />
\t\t
\t\t<txp:mem_form_email name="email" label="E-Mail" /><br />
\t\t<br />

\t\t<txp:mem_form_submit />
\t</fieldset>
EOF;
        $form = fetch('Form', 'txp_form', 'name', 'self_register_form');
        if (!$form) {
            if (safe_insert('txp_form', "name='self_register_form',type='misc',Form='{$form_html}'")) {
                $log[] = mem_self_gTxt('log_form_added', array('{name}' => 'self_register_form'));
            } else {
                $log[] = mem_self_gTxt('log_form_failed', array('{name}' => 'self_register_form', '{error}' => mysql_error())) . br . '<textpattern style="width:300px;height:150px;">' . htmlspecialchars($form_html) . '</textarea>';
            }
        } else {
            $log[] = mem_self_gTxt('log_form_found', array('{name}' => 'self_register_form'));
        }
        // create default successful registration form to show the user
        $form_html = <<<EOF
<h3>Account Created</h3>
<p>An email containing your password has been sent to <txp:mem_profile var="email" />.</p>
EOF;
        $form = fetch('Form', 'txp_form', 'name', 'self_register_success');
        if (!$form) {
            if (safe_insert('txp_form', "name='self_register_success',type='misc',Form='{$form_html}'")) {
                $log[] = mem_self_gTxt('log_form_added', array('{name}' => 'self_register_success'));
            } else {
                $log[] = mem_self_gTxt('log_form_failed', array('{name}' => 'self_register_success', '{error}' => mysql_error())) . br . '<textpattern style="width:300px;height:150px;">' . htmlspecialchars($form_html) . '</textarea>';
            }
        } else {
            $log[] = mem_self_gTxt('log_form_found', array('{name}' => 'self_register_success'));
        }
        // create default successful registration email form
        $form_html = <<<EOF
Dear <txp:mem_name />, 

Thank you for registering at <txp:mem_siteurl />. 

Your login name: <txp:mem_username />
Your password: <txp:mem_password />

If you have any questions please reply to this email address.

Sincerely,
<txp:mem_admin_name />
<txp:mem_admin_email />
EOF;
        $form = fetch('Form', 'txp_form', 'name', 'self_register_email');
        if (!$form) {
            if (safe_insert('txp_form', "name='self_register_email',type='misc',Form='{$form_html}'")) {
                $log[] = mem_self_gTxt('log_form_added', array('{name}' => 'self_register_email'));
            } else {
                $log[] = mem_self_gTxt('log_form_failed', array('{name}' => 'self_register_email', '{error}' => mysql_error())) . br . '<textpattern style="width:300px;height:150px;">' . htmlspecialchars($form_html) . '</textarea>';
            }
        } else {
            $log[] = mem_self_gTxt('log_form_found', array('{name}' => 'self_register_email'));
        }
        $tag_help = '<txp:mem_self_register_form form="self_register_form" />';
        $log[] = mem_self_gTxt('log_xmpl_tag') . br . '<textarea style="width:400px;height:40px;">' . htmlspecialchars($tag_help) . '</textarea>';
        return doWrap($log, 'ul', 'li');
    }
Example #14
0
function image_index($atts)
{
    global $s, $c, $p, $img_dir, $path_to_site;
    extract(lAtts(array('label' => '', 'break' => br, 'wraptag' => '', 'class' => __FUNCTION__, 'labeltag' => '', 'c' => $c, 'limit' => 0, 'offset' => 0, 'sort' => 'name ASC'), $atts));
    $qparts = array("category = '" . doSlash($c) . "' and thumbnail = 1", 'order by ' . doSlash($sort), $limit ? 'limit ' . intval($offset) . ', ' . intval($limit) : '');
    $rs = safe_rows_start('*', 'txp_image', join(' ', $qparts));
    if ($rs) {
        $out = array();
        while ($a = nextRow($rs)) {
            extract($a);
            $impath = $img_dir . '/' . $id . 't' . $ext;
            $imginfo = getimagesize($path_to_site . '/' . $impath);
            $dims = !empty($imginfo[3]) ? ' ' . $imginfo[3] : '';
            $url = pagelinkurl(array('c' => $c, 's' => $s, 'p' => $id));
            $out[] = '<a href="' . $url . '">' . '<img src="' . hu . $impath . '"' . $dims . ' alt="' . $alt . '" />' . '</a>';
        }
        if (count($out)) {
            return doLabel($label, $labeltag) . doWrap($out, $wraptag, $break, $class);
        }
    }
    return '';
}
function peg_comments($atts)
{
    global $thisarticle, $thiscomment, $prefs;
    extract(lAtts(array('form' => 'comments', 'wraptag' => $prefs['comments_are_ol'] ? 'ol' : '', 'break' => $prefs['comments_are_ol'] ? 'li' : 'div', 'class' => 'comments', 'breakclass' => '', 'limit' => 0, 'offset' => 0, 'sort' => 'posted ASC'), $atts));
    assert_article();
    // extract($thisarticle);
    if (!$thisarticle['comments_count']) {
        return '';
    }
    $thisid = intval($thisarticle['thisid']);
    // $txp_discuss = safe_pfx('txp_discuss');
    // $peg_discuss = safe_pfx('peg_discuss');
    if (!empty($thiscomment)) {
        $peg_children = $thiscomment['peg_children'];
    } else {
        // safe_query("CREATE TEMPORARY TABLE $peg_discuss (SELECT * FROM $txp_discuss WHERE parentid=$thisid AND visible=".VISIBLE.")");
        $rs = safe_rows('discussid, peg_children', 'txp_discuss', "parentid={$thisid} AND visible=" . VISIBLE);
        $peg_children = $rows = array();
        foreach ($rs as $vars) {
            $rows[] = $vars['discussid'];
            if ($vars['peg_children']) {
                $peg_children = array_merge($peg_children, explode(',', $vars['peg_children']));
            }
        }
        $peg_children = implode(',', $peg_children ? array_diff($rows, $peg_children) : $rows);
    }
    if (empty($peg_children)) {
        return '';
    }
    $qparts = "discussid IN({$peg_children}) AND parentid={$thisid} AND visible=" . VISIBLE . ($sort ? " ORDER BY {$sort}" : '') . ($limit || $offset ? ' LIMIT ' . intval($offset) . ', ' . intval($limit) : '');
    $rs = safe_rows('*, unix_timestamp(posted) as time', 'txp_discuss', $qparts);
    $out = '';
    if ($rs) {
        foreach ($rs as $vars) {
            $GLOBALS['thiscomment'] = $vars;
            $comments[] = peg_parse_form_recursively($form) . n;
            unset($GLOBALS['thiscomment']);
        }
        $out .= doWrap($comments, $wraptag, $break, $class, $breakclass);
    }
    return $out;
}
Example #16
0
function doArticles($atts, $iscustom, $thing = NULL)
{
    global $pretext, $prefs;
    extract($pretext);
    extract($prefs);
    $customFields = getCustomFields();
    $customlAtts = array_null(array_flip($customFields));
    //getting attributes
    $theAtts = lAtts(array('form' => 'default', 'listform' => '', 'searchform' => '', 'limit' => 10, 'pageby' => '', 'category' => '', 'section' => '', 'excerpted' => '', 'author' => '', 'sort' => '', 'sortby' => '', 'sortdir' => '', 'month' => '', 'keywords' => '', 'frontpage' => '', 'id' => '', 'time' => 'past', 'status' => '4', 'pgonly' => 0, 'searchall' => 1, 'searchsticky' => 0, 'allowoverride' => !$q and !$iscustom, 'offset' => 0, 'wraptag' => '', 'break' => '', 'label' => '', 'labeltag' => '', 'class' => '') + $customlAtts, $atts);
    // if an article ID is specified, treat it as a custom list
    $iscustom = !empty($theAtts['id']) ? true : $iscustom;
    //for the txp:article tag, some attributes are taken from globals;
    //override them before extract
    if (!$iscustom) {
        $theAtts['category'] = $c ? $c : '';
        $theAtts['section'] = $s && $s != 'default' ? $s : '';
        $theAtts['author'] = !empty($author) ? $author : '';
        $theAtts['month'] = !empty($month) ? $month : '';
        $theAtts['frontpage'] = $s && $s == 'default' ? true : false;
        $theAtts['excerpted'] = '';
    }
    extract($theAtts);
    // if a listform is specified, $thing is for doArticle() - hence ignore here.
    if (!empty($listform)) {
        $thing = '';
    }
    $pageby = empty($pageby) ? $limit : $pageby;
    // treat sticky articles differently wrt search filtering, etc
    $status = in_array(strtolower($status), array('sticky', '5')) ? 5 : 4;
    $issticky = $status == 5;
    // give control to search, if necessary
    if ($q && !$iscustom && !$issticky) {
        include_once txpath . '/publish/search.php';
        $s_filter = $searchall ? filterSearch() : '';
        $q = doSlash($q);
        // searchable article fields are limited to the columns of
        // the textpattern table and a matching fulltext index must exist.
        $cols = do_list($searchable_article_fields);
        if (empty($cols) or $cols[0] == '') {
            $cols = array('Title', 'Body');
        }
        $match = ', match (`' . join('`, `', $cols) . "`) against ('{$q}') as score";
        for ($i = 0; $i < count($cols); $i++) {
            $cols[$i] = "`{$cols[$i]}` rlike '{$q}'";
        }
        $cols = join(" or ", $cols);
        $search = " and ({$cols}) {$s_filter}";
        // searchall=0 can be used to show search results for the current section only
        if ($searchall) {
            $section = '';
        }
        if (!$sort) {
            $sort = 'score desc';
        }
    } else {
        $match = $search = '';
        if (!$sort) {
            $sort = 'Posted desc';
        }
    }
    // for backwards compatibility
    // sortby and sortdir are deprecated
    if ($sortby) {
        if (!$sortdir) {
            $sortdir = 'desc';
        }
        $sort = "{$sortby} {$sortdir}";
    } elseif ($sortdir) {
        $sort = "Posted {$sortdir}";
    }
    //Building query parts
    $frontpage = ($frontpage and (!$q or $issticky)) ? filterFrontPage() : '';
    $category = join("','", doSlash(do_list($category)));
    $category = !$category ? '' : " and (Category1 IN ('" . $category . "') or Category2 IN ('" . $category . "'))";
    $section = !$section ? '' : " and Section IN ('" . join("','", doSlash(do_list($section))) . "')";
    $excerpted = $excerpted == 'y' ? " and Excerpt !=''" : '';
    $author = !$author ? '' : " and AuthorID IN ('" . join("','", doSlash(do_list($author))) . "')";
    $month = !$month ? '' : " and Posted like '" . doSlash($month) . "%'";
    $id = !$id ? '' : " and ID IN (" . join(',', array_map('intval', do_list($id))) . ")";
    switch ($time) {
        case 'any':
            $time = "";
            break;
        case 'future':
            $time = " and Posted > now()";
            break;
        default:
            $time = " and Posted <= now()";
    }
    if (!$publish_expired_articles) {
        $time .= " and (now() <= Expires or Expires = " . NULLDATETIME . ")";
    }
    $custom = '';
    if ($customFields) {
        foreach ($customFields as $cField) {
            if (isset($atts[$cField])) {
                $customPairs[$cField] = $atts[$cField];
            }
        }
        if (!empty($customPairs)) {
            $custom = buildCustomSql($customFields, $customPairs);
        }
    }
    //Allow keywords for no-custom articles. That tagging mode, you know
    if ($keywords) {
        $keys = doSlash(do_list($keywords));
        foreach ($keys as $key) {
            $keyparts[] = "FIND_IN_SET('" . $key . "',Keywords)";
        }
        $keywords = " and (" . join(' or ', $keyparts) . ")";
    }
    if ($q and $searchsticky) {
        $statusq = ' and Status >= 4';
    } elseif ($id) {
        $statusq = ' and Status >= 4';
    } else {
        $statusq = ' and Status = ' . intval($status);
    }
    $where = "1=1" . $statusq . $time . $search . $id . $category . $section . $excerpted . $month . $author . $keywords . $custom . $frontpage;
    //do not paginate if we are on a custom list
    if (!$iscustom and !$issticky) {
        $grand_total = safe_count('textpattern', $where);
        $total = $grand_total - $offset;
        $numPages = ceil($total / $pageby);
        $pg = !$pg ? 1 : $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['grand_total'] = $grand_total;
        $pageout['total'] = $total;
        global $thispage;
        if (empty($thispage)) {
            $thispage = $pageout;
        }
        if ($pgonly) {
            return;
        }
    } else {
        $pgoffset = $offset;
    }
    $rs = safe_rows_start("*, unix_timestamp(Posted) as uPosted, unix_timestamp(Expires) as uExpires, unix_timestamp(LastMod) as uLastMod" . $match, 'textpattern', $where . ' order by ' . doSlash($sort) . ' limit ' . intval($pgoffset) . ', ' . intval($limit));
    // get the form name
    if ($q and !$iscustom and !$issticky) {
        $fname = $searchform ? $searchform : 'search_results';
    } else {
        $fname = $listform ? $listform : $form;
    }
    if ($rs) {
        $count = 0;
        $last = numRows($rs);
        $articles = array();
        while ($a = nextRow($rs)) {
            ++$count;
            populateArticleData($a);
            global $thisarticle, $uPosted, $limit;
            $thisarticle['is_first'] = $count == 1;
            $thisarticle['is_last'] = $count == $last;
            if (@constant('txpinterface') === 'admin' and gps('Form')) {
                $articles[] = parse(gps('Form'));
            } elseif ($allowoverride and $a['override_form']) {
                $articles[] = parse_form($a['override_form']);
            } else {
                $articles[] = $thing ? parse($thing) : parse_form($fname);
            }
            // sending these to paging_link(); Required?
            $uPosted = $a['uPosted'];
            unset($GLOBALS['thisarticle']);
        }
        return doLabel($label, $labeltag) . doWrap($articles, $wraptag, $break, $class);
    }
}
Example #17
0
function file_download_list($atts)
{
    global $thisfile;
    extract(lAtts(array('form' => 'files', 'sort' => 'filename', 'label' => '', 'break' => br, 'limit' => '10', 'wraptag' => '', 'category' => '', 'class' => __FUNCTION__), $atts));
    $qparts = array($category ? "category='{$category}'" : '1', "order by", $sort, $limit ? "limit {$limit}" : '');
    $rs = safe_rows_start("*", "txp_file", join(' ', $qparts));
    if ($rs) {
        if ($label) {
            $outlist[] = $label;
        }
        while ($a = nextRow($rs)) {
            $thisfile = fileDownloadFetchInfo("id='{$a['id']}'");
            $outlist[] = file_download(array('id' => $a['id'], 'filename' => $a['filename'], 'form' => $form));
        }
        if (!empty($outlist)) {
            if ($wraptag == 'ul' or $wraptag == 'ol') {
                return doWrap($outlist, $wraptag, $break, $class);
            }
            return $wraptag ? tag(join($break, $outlist), $wraptag) : join(n, $outlist);
        }
    }
    return '';
}
Example #18
0
function file_download_list($atts)
{
    global $thisfile;
    extract(lAtts(array('break' => br, 'category' => '', 'class' => __FUNCTION__, 'form' => 'files', 'label' => '', 'labeltag' => '', 'limit' => '10', 'offset' => '0', 'sort' => 'filename asc', 'wraptag' => ''), $atts));
    $qparts = array($category ? "category = '" . doSlash($category) . "'" : '1', 'order by ' . doSlash($sort), $limit ? 'limit ' . intval($offset) . ', ' . intval($limit) : '');
    $rs = safe_rows_start('id, filename, category, description, downloads', 'txp_file', join(' ', $qparts));
    if ($rs) {
        $form = fetch_form($form);
        $out = array();
        while ($a = nextRow($rs)) {
            $GLOBALS['thisfile'] = file_download_format_info($a);
            $out[] = parse($form);
            $GLOBALS['thisfile'] = '';
        }
        if ($out) {
            if ($wraptag == 'ul' or $wraptag == 'ol') {
                return doLabel($label, $labeltag) . doWrap($out, $wraptag, $break, $class);
            }
            return $wraptag ? tag(join($break, $out), $wraptag) : join(n, $out);
        }
    }
    return '';
}
function ign_active_users($atts, $thing = '')
{
    global $ign_user_db;
    extract(lAtts(array('privs' => '', 'display' => 'name', 'wraptag' => 'p', 'break' => 'br', 'class' => ''), $atts, 0));
    $match = array('/[^0-9\\,]/', '/\\,\\,/', '/\\,$/');
    $replacement = array('', ',');
    $privs = preg_replace($match, $replacement, $privs);
    if (strtolower($display) != 'realname') {
        $display = 'name';
    }
    $sql = '';
    if (!empty($privs)) {
        $sql .= "privs in ({$privs}) and ";
    }
    $sql .= "last_access > date_add(now(), interval -2 minute)";
    $r = safe_rows($display, $ign_user_db, $sql);
    if (count($r) < 1) {
        return false;
    } else {
        foreach ($r as $user) {
            $users[] = $user[$display];
        }
        $out = !empty($thing) ? $thing : '';
        return $out . n . doWrap($users, $wraptag, $break, $class) . n;
    }
}
Example #20
0
 function row($row)
 {
     if (!$this->controller) {
         return;
     }
     extract($this->controller->context);
     extract($row);
     $event = $this->controller->event;
     $tr = array();
     $tr[] = $id;
     $tr[] = fInput('text', 'name', $name, '', '', '', 20);
     $tr[] = fInput('text', 'title', $title, '', '', '', 20);
     $tr[] = selectInput('page', $this->pages, $page);
     //.sp.popHelp('section_uses_page');
     $tr[] = selectInput('css', $this->styles, $css);
     //.sp.popHelp('section_uses_css');
     $tr[] = SectionController::adopters_dropdown($id, $parent);
     //.sp.popHelp('section_parent_section');
     $tr[] = yesnoradio('is_default', $is_default, '', $name);
     //.sp.popHelp('section_is_default');
     $tr[] = yesnoradio('on_frontpage', $on_frontpage, '', $name);
     //.sp.popHelp('section_on_frontpage');
     $tr[] = yesnoradio('in_rss', $in_rss, '', $name);
     //.sp.popHelp('section_syndicate');
     $tr[] = yesnoradio('searchable', $searchable, '', $name);
     //.sp.popHelp('section_searchable');
     $tr[] = fInput('submit', '', gTxt('save_button'), 'smallerbox') . eInput('section') . sInput('save') . hInput('old_name', $name);
     $tr = doWrap($tr, 'tr', 'td', 'row-' . (++$this->count % 2 ? 'odd' : 'even'));
     #echo "<pre>".htmlspecialchars($tr)."</pre><br />===<br />";
     $tr = preg_replace('/<tr.*>/', '\\0' . start_form(), $tr);
     $tr = preg_replace('/<\\/tr>/', end_form() . '</tr>', $tr);
     return $tr;
 }