Example #1
0
function image_list($message = '')
{
    global $txpcfg, $extensions, $img_dir, $file_max_upload_size, $image_list_pageby, $txp_user, $event;
    pagetop(gTxt('tab_image'), $message);
    extract($txpcfg);
    extract(gpsa(array('page', 'sort', 'dir', 'crit', 'search_method')));
    if ($sort === '') {
        $sort = get_pref('image_sort_column', 'id');
    }
    if ($dir === '') {
        $dir = get_pref('image_sort_dir', 'desc');
    }
    $dir = $dir == 'asc' ? 'asc' : 'desc';
    echo hed(gTxt('tab_image'), 1, array('class' => 'txp-heading'));
    echo n . '<div id="' . $event . '_control" class="txp-control-panel">';
    if (!is_dir(IMPATH) or !is_writeable(IMPATH)) {
        echo graf(span(null, array('class' => 'ui-icon ui-icon-alert')) . ' ' . gTxt('img_dir_not_writeable', array('{imgdir}' => IMPATH)), array('class' => 'alert-block warning'));
    } elseif (has_privs('image.edit.own')) {
        echo upload_form(gTxt('upload_image'), 'upload_image', 'image_insert', 'image', '', $file_max_upload_size);
    }
    switch ($sort) {
        case 'name':
            $sort_sql = 'name ' . $dir;
            break;
        case 'thumbnail':
            $sort_sql = 'thumbnail ' . $dir . ', id asc';
            break;
        case 'category':
            $sort_sql = 'category ' . $dir . ', id asc';
            break;
        case 'date':
            $sort_sql = 'date ' . $dir . ', id asc';
            break;
        case 'author':
            $sort_sql = 'author ' . $dir . ', id asc';
            break;
        default:
            $sort = 'id';
            $sort_sql = 'id ' . $dir;
            break;
    }
    set_pref('image_sort_column', $sort, 'image', 2, '', 0, PREF_PRIVATE);
    set_pref('image_sort_dir', $dir, 'image', 2, '', 0, PREF_PRIVATE);
    $switch_dir = $dir == 'desc' ? 'asc' : 'desc';
    $criteria = 1;
    if ($search_method and $crit != '') {
        $verbatim = preg_match('/^"(.*)"$/', $crit, $m);
        $crit_escaped = $verbatim ? doSlash($m[1]) : doLike($crit);
        $critsql = $verbatim ? array('id' => "ID in ('" . join("','", do_list($crit_escaped)) . "')", 'name' => "name = '{$crit_escaped}'", 'category' => "category = '{$crit_escaped}'", 'author' => "author = '{$crit_escaped}'", 'alt' => "alt = '{$crit_escaped}'", 'caption' => "caption = '{$crit_escaped}'") : array('id' => "ID in ('" . join("','", do_list($crit_escaped)) . "')", 'name' => "name like '%{$crit_escaped}%'", 'category' => "category like '%{$crit_escaped}%'", 'author' => "author like '%{$crit_escaped}%'", 'alt' => "alt like '%{$crit_escaped}%'", 'caption' => "caption like '%{$crit_escaped}%'");
        if (array_key_exists($search_method, $critsql)) {
            $criteria = $critsql[$search_method];
            $limit = 500;
        } else {
            $search_method = '';
            $crit = '';
        }
    } else {
        $search_method = '';
        $crit = '';
    }
    $criteria .= callback_event('admin_criteria', 'image_list', 0, $criteria);
    $total = safe_count('txp_image', "{$criteria}");
    if ($total < 1) {
        if ($criteria != 1) {
            echo n . image_search_form($crit, $search_method) . graf(gTxt('no_results_found'), ' class="indicator"') . '</div>';
        } else {
            echo graf(gTxt('no_images_recorded'), ' class="indicator"') . '</div>';
        }
        return;
    }
    $limit = max($image_list_pageby, 15);
    list($page, $offset, $numPages) = pager($total, $limit, $page);
    echo image_search_form($crit, $search_method);
    $rs = safe_rows_start('*, unix_timestamp(date) as uDate', 'txp_image', "{$criteria} order by {$sort_sql} limit {$offset}, {$limit}\n    ");
    echo pluggable_ui('image_ui', 'extend_controls', '', $rs);
    echo '</div>';
    // End txp-control-panel.
    if ($rs) {
        $show_authors = !has_single_author('txp_image');
        echo n . tag_start('div', array('id' => $event . '_container', 'class' => 'txp-container')) . n . tag_start('form', array('action' => 'index.php', 'id' => 'images_form', 'class' => 'multi_edit_form', 'method' => 'post', 'name' => 'longform')) . n . tag_start('div', array('class' => 'txp-listtables')) . n . tag_start('table', array('class' => 'txp-list')) . n . tag_start('thead') . tr(hCell(fInput('checkbox', 'select_all', 0, '', '', '', '', '', 'select_all'), '', ' scope="col" title="' . gTxt('toggle_all_selected') . '" class="txp-list-col-multi-edit"') . column_head('ID', 'id', 'image', true, $switch_dir, $crit, $search_method, ('id' == $sort ? "{$dir} " : '') . 'txp-list-col-id') . column_head('name', 'name', 'image', true, $switch_dir, $crit, $search_method, ('name' == $sort ? "{$dir} " : '') . 'txp-list-col-name') . column_head('date', 'date', 'image', true, $switch_dir, $crit, $search_method, ('date' == $sort ? "{$dir} " : '') . 'txp-list-col-created date images_detail') . column_head('thumbnail', 'thumbnail', 'image', true, $switch_dir, $crit, $search_method, ('thumbnail' == $sort ? "{$dir} " : '') . 'txp-list-col-thumbnail') . hCell(gTxt('tags'), '', ' scope="col" class="txp-list-col-tag-build images_detail"') . column_head('image_category', 'category', 'image', true, $switch_dir, $crit, $search_method, ('category' == $sort ? "{$dir} " : '') . 'txp-list-col-category category') . ($show_authors ? column_head('author', 'author', 'image', true, $switch_dir, $crit, $search_method, ('author' == $sort ? "{$dir} " : '') . 'txp-list-col-author name') : '')) . n . tag_end('thead') . n . tag_start('tbody');
        $validator = new Validator();
        while ($a = nextRow($rs)) {
            extract($a);
            $edit_url = array('event' => 'image', 'step' => 'image_edit', 'id' => $id, 'sort' => $sort, 'dir' => $dir, 'page' => $page, 'search_method' => $search_method, 'crit' => $crit);
            $name = empty($name) ? gTxt('unnamed') : txpspecialchars($name);
            if ($thumbnail) {
                if ($ext != '.swf') {
                    $thumbnail = '<img class="content-image" src="' . imagesrcurl($id, $ext, true) . "?{$uDate}" . '" alt="" ' . "title='{$id}{$ext} ({$w} &#215; {$h})'" . ($thumb_w ? " width='{$thumb_w}' height='{$thumb_h}'" : '') . ' />';
                } else {
                    $thumbnail = '';
                }
            } else {
                $thumbnail = gTxt('no');
            }
            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 = href('Textile', $tag_url . a . 'type=textile', ' target="_blank" onclick="popWin(this.href); return false;"') . sp . span('&#124;', array('role' => 'separator')) . sp . href('Textpattern', $tag_url . a . 'type=textpattern', ' target="_blank" onclick="popWin(this.href); return false;"') . sp . span('&#124;', array('role' => 'separator')) . sp . href('HTML', $tag_url . a . 'type=html', ' target="_blank" onclick="popWin(this.href); return false;"');
            } else {
                $tagbuilder = sp;
            }
            $validator->setConstraints(array(new CategoryConstraint($category, array('type' => 'image'))));
            $vc = $validator->validate() ? '' : ' error';
            $category = $category ? span($category, array('title' => fetch_category_title($category, 'image'))) : '';
            $can_edit = has_privs('image.edit') || $author === $txp_user && has_privs('image.edit.own');
            echo tr(td($can_edit ? fInput('checkbox', 'selected[]', $id) : '&#160;', '', 'txp-list-col-multi-edit') . hCell(($can_edit ? href($id, $edit_url, array('title' => gTxt('edit'))) : $id) . sp . span(span('[', array('aria-hidden' => 'true')) . href(gTxt('view'), imagesrcurl($id, $ext)) . span(']', array('aria-hidden' => 'true')), array('class' => 'images_detail')), '', ' scope="row" class="txp-list-col-id"') . td($can_edit ? href($name, $edit_url, ' title="' . gTxt('edit') . '"') : $name, '', 'txp-list-col-name') . td(gTime($uDate), '', 'txp-list-col-created date images_detail') . td(pluggable_ui('image_ui', 'thumbnail', $can_edit ? href($thumbnail, $edit_url) : $thumbnail, $a), '', 'txp-list-col-thumbnail') . td($tagbuilder, '', 'txp-list-col-tag-build images_detail') . td($category, '', 'txp-list-col-category category' . $vc) . ($show_authors ? td(span(txpspecialchars($author), array('title' => get_author_name($author))), '', 'txp-list-col-author name') : ''));
        }
        echo n . tag_end('tbody') . n . tag_end('table') . n . tag_end('div') . image_multiedit_form($page, $sort, $dir, $crit, $search_method) . tInput() . n . tag_end('form') . graf(toggle_box('images_detail'), array('class' => 'detail-toggle')) . n . tag_start('div', array('id' => $event . '_navigation', 'class' => 'txp-navigation')) . pageby_form('image', $image_list_pageby) . nav_form('image', $page, $numPages, $sort, $dir, $crit, $search_method, $total, $limit) . n . tag_end('div') . n . tag_end('div');
    }
}
Example #2
0
/**
 * Outputs the main panel listing all articles.
 *
 * @param  string|array $message The activity message
 * @param  string       $post    Not used
 */
function list_list($message = '', $post = '')
{
    global $statuses, $use_comments, $comments_disabled_after, $step, $txp_user, $article_list_pageby, $event;
    pagetop(gTxt('tab_list'), $message);
    extract(gpsa(array('page', 'sort', 'dir', 'crit', 'search_method')));
    if ($sort === '') {
        $sort = get_pref('article_sort_column', 'posted');
    }
    if ($dir === '') {
        $dir = get_pref('article_sort_dir', 'desc');
    }
    $dir = $dir == 'asc' ? 'asc' : 'desc';
    $sesutats = array_flip($statuses);
    switch ($sort) {
        case 'id':
            $sort_sql = 'textpattern.ID ' . $dir;
            break;
        case 'title':
            $sort_sql = 'textpattern.Title ' . $dir . ', textpattern.Posted desc';
            break;
        case 'expires':
            $sort_sql = 'textpattern.Expires ' . $dir;
            break;
        case 'section':
            $sort_sql = 'section.title ' . $dir . ', textpattern.Posted desc';
            break;
        case 'category1':
            $sort_sql = 'category1.title ' . $dir . ', textpattern.Posted desc';
            break;
        case 'category2':
            $sort_sql = 'category2.title ' . $dir . ', textpattern.Posted desc';
            break;
        case 'status':
            $sort_sql = 'textpattern.Status ' . $dir . ', textpattern.Posted desc';
            break;
        case 'author':
            $sort_sql = 'user.RealName ' . $dir . ', textpattern.Posted desc';
            break;
        case 'comments':
            $sort_sql = 'textpattern.comments_count ' . $dir . ', textpattern.Posted desc';
            break;
        case 'lastmod':
            $sort_sql = 'textpattern.LastMod ' . $dir . ', textpattern.Posted desc';
            break;
        default:
            $sort = 'posted';
            $sort_sql = 'textpattern.Posted ' . $dir;
            break;
    }
    set_pref('article_sort_column', $sort, 'list', 2, '', 0, PREF_PRIVATE);
    set_pref('article_sort_dir', $dir, 'list', 2, '', 0, PREF_PRIVATE);
    $switch_dir = $dir == 'desc' ? 'asc' : 'desc';
    $criteria = 1;
    if ($search_method and $crit != '') {
        $verbatim = preg_match('/^"(.*)"$/', $crit, $m);
        $crit_escaped = $verbatim ? doSlash($m[1]) : doLike($crit);
        $critsql = $verbatim ? array('id' => "textpattern.ID in ('" . join("','", do_list($crit_escaped)) . "')", 'title_body_excerpt' => "textpattern.Title = '{$crit_escaped}' or textpattern.Body = '{$crit_escaped}' or textpattern.Excerpt = '{$crit_escaped}'", 'section' => "textpattern.Section = '{$crit_escaped}' or section.title = '{$crit_escaped}'", 'keywords' => "FIND_IN_SET('" . $crit_escaped . "',textpattern.Keywords)", 'categories' => "textpattern.Category1 = '{$crit_escaped}' or textpattern.Category2 = '{$crit_escaped}' or category1.title = '{$crit_escaped}' or category2.title = '{$crit_escaped}'", 'status' => "textpattern.Status = '" . @$sesutats[gTxt($crit_escaped)] . "'", 'author' => "textpattern.AuthorID = '{$crit_escaped}' or user.RealName = '{$crit_escaped}'", 'article_image' => "textpattern.Image in ('" . join("','", do_list($crit_escaped)) . "')", 'posted' => "textpattern.Posted = '{$crit_escaped}'", 'lastmod' => "textpattern.LastMod = '{$crit_escaped}'") : array('id' => "textpattern.ID in ('" . join("','", do_list($crit_escaped)) . "')", 'title_body_excerpt' => "textpattern.Title like '%{$crit_escaped}%' or textpattern.Body like '%{$crit_escaped}%' or textpattern.Excerpt like '%{$crit_escaped}%'", 'section' => "textpattern.Section like '%{$crit_escaped}%' or section.title like '%{$crit_escaped}%'", 'keywords' => "FIND_IN_SET('" . $crit_escaped . "',textpattern.Keywords)", 'categories' => "textpattern.Category1 like '%{$crit_escaped}%' or textpattern.Category2 like '%{$crit_escaped}%' or category1.title like '%{$crit_escaped}%' or category2.title like '%{$crit_escaped}%'", 'status' => "textpattern.Status = '" . @$sesutats[gTxt($crit_escaped)] . "'", 'author' => "textpattern.AuthorID like '%{$crit_escaped}%' or user.RealName like '%{$crit_escaped}%'", 'article_image' => "textpattern.Image in ('" . join("','", do_list($crit_escaped)) . "')", 'posted' => "textpattern.Posted like '{$crit_escaped}%'", 'lastmod' => "textpattern.LastMod like '{$crit_escaped}%'");
        if (array_key_exists($search_method, $critsql)) {
            $criteria = $critsql[$search_method];
            $limit = 500;
        } else {
            $search_method = '';
            $crit = '';
        }
    } else {
        $search_method = '';
        $crit = '';
    }
    $criteria .= callback_event('admin_criteria', 'list_list', 0, $criteria);
    $sql_from = safe_pfx('textpattern') . " textpattern\n        left join " . safe_pfx('txp_category') . " category1 on category1.name = textpattern.Category1 and category1.type = 'article'\n        left join " . safe_pfx('txp_category') . " category2 on category2.name = textpattern.Category2 and category2.type = 'article'\n        left join " . safe_pfx('txp_section') . " section on section.name = textpattern.Section\n        left join " . safe_pfx('txp_users') . " user on user.name = textpattern.AuthorID";
    if ($criteria === 1) {
        $total = safe_count('textpattern', $criteria);
    } else {
        $total = getThing('select count(*) from ' . $sql_from . ' where ' . $criteria);
    }
    echo hed(gTxt('tab_list'), 1, array('class' => 'txp-heading'));
    echo n . '<div id="' . $event . '_control" class="txp-control-panel">';
    if ($total < 1) {
        if ($criteria != 1) {
            echo list_search_form($crit, $search_method) . graf(gTxt('no_results_found'), ' class="indicator"') . '</div>';
        } else {
            echo graf(gTxt('no_articles_recorded'), ' class="indicator"') . '</div>';
        }
        return;
    }
    $limit = max($article_list_pageby, 15);
    list($page, $offset, $numPages) = pager($total, $limit, $page);
    echo list_search_form($crit, $search_method) . '</div>';
    $rs = safe_query("select\n            textpattern.ID, textpattern.Title, textpattern.url_title, textpattern.Section,\n            textpattern.Category1, textpattern.Category2,\n            textpattern.Status, textpattern.Annotate, textpattern.AuthorID,\n            unix_timestamp(textpattern.Posted) as posted,\n            unix_timestamp(textpattern.LastMod) as lastmod,\n            unix_timestamp(textpattern.Expires) as expires,\n            category1.title as category1_title,\n            category2.title as category2_title,\n            section.title as section_title,\n            user.RealName as RealName,\n            (select count(*) from " . safe_pfx('txp_discuss') . " where parentid = textpattern.ID) as total_comments\n        from {$sql_from} where {$criteria} order by {$sort_sql} limit {$offset}, {$limit}");
    if ($rs) {
        $show_authors = !has_single_author('textpattern', 'AuthorID');
        echo n . tag_start('div', array('id' => $event . '_container', 'class' => 'txp-container')) . n . tag_start('form', array('action' => 'index.php', 'id' => 'articles_form', 'class' => 'multi_edit_form', 'method' => 'post', 'name' => 'longform')) . n . tag_start('div', array('class' => 'txp-listtables')) . n . tag_start('table', array('class' => 'txp-list')) . n . tag_start('thead') . tr(hCell(fInput('checkbox', 'select_all', 0, '', '', '', '', '', 'select_all'), '', ' scope="col" title="' . gTxt('toggle_all_selected') . '" class="txp-list-col-multi-edit"') . column_head('ID', 'id', 'list', true, $switch_dir, $crit, $search_method, ('id' == $sort ? "{$dir} " : '') . 'txp-list-col-id') . column_head('title', 'title', 'list', true, $switch_dir, $crit, $search_method, ('title' == $sort ? "{$dir} " : '') . 'txp-list-col-title') . column_head('posted', 'posted', 'list', true, $switch_dir, $crit, $search_method, ('posted' == $sort ? "{$dir} " : '') . 'txp-list-col-created date') . column_head('article_modified', 'lastmod', 'list', true, $switch_dir, $crit, $search_method, ('lastmod' == $sort ? "{$dir} " : '') . 'txp-list-col-lastmod date articles_detail') . column_head('expires', 'expires', 'list', true, $switch_dir, $crit, $search_method, ('expires' == $sort ? "{$dir} " : '') . 'txp-list-col-expires date articles_detail') . column_head('section', 'section', 'list', true, $switch_dir, $crit, $search_method, ('section' == $sort ? "{$dir} " : '') . 'txp-list-col-section') . column_head('category1', 'category1', 'list', true, $switch_dir, $crit, $search_method, ('category1' == $sort ? "{$dir} " : '') . 'txp-list-col-category1 category articles_detail') . column_head('category2', 'category2', 'list', true, $switch_dir, $crit, $search_method, ('category2' == $sort ? "{$dir} " : '') . 'txp-list-col-category2 category articles_detail') . column_head('status', 'status', 'list', true, $switch_dir, $crit, $search_method, ('status' == $sort ? "{$dir} " : '') . 'txp-list-col-status') . ($show_authors ? column_head('author', 'author', 'list', true, $switch_dir, $crit, $search_method, ('author' == $sort ? "{$dir} " : '') . 'txp-list-col-author name') : '') . ($use_comments == 1 ? column_head('comments', 'comments', 'list', true, $switch_dir, $crit, $search_method, ('comments' == $sort ? "{$dir} " : '') . 'txp-list-col-comments articles_detail') : '')) . n . tag_end('thead');
        include_once txpath . '/publish/taghandlers.php';
        echo n . tag_start('tbody');
        $validator = new Validator();
        while ($a = nextRow($rs)) {
            extract($a);
            if ($Title === '') {
                $Title = '<em>' . eLink('article', 'edit', 'ID', $ID, gTxt('untitled')) . '</em>';
            } else {
                $Title = eLink('article', 'edit', 'ID', $ID, $Title);
            }
            // Valid section and categories?
            $validator->setConstraints(array(new SectionConstraint($Section)));
            $vs = $validator->validate() ? '' : ' error';
            $validator->setConstraints(array(new CategoryConstraint($Category1, array('type' => 'article'))));
            $vc[1] = $validator->validate() ? '' : ' error';
            $validator->setConstraints(array(new CategoryConstraint($Category2, array('type' => 'article'))));
            $vc[2] = $validator->validate() ? '' : ' error';
            $Category1 = $Category1 ? span(txpspecialchars($category1_title), array('title' => $Category1)) : '';
            $Category2 = $Category2 ? span(txpspecialchars($category2_title), array('title' => $Category2)) : '';
            if ($Status != STATUS_LIVE and $Status != STATUS_STICKY) {
                $view_url = '?txpreview=' . intval($ID) . '.' . time();
            } else {
                $view_url = permlinkurl($a);
            }
            if (isset($statuses[$Status])) {
                $Status = $statuses[$Status];
            }
            $comments = '(' . $total_comments . ')';
            if ($total_comments) {
                $comments = href($comments, array('event' => 'discuss', 'step' => 'list', 'search_method' => 'parent', 'crit' => $ID), array('title' => gTxt('manage')));
            }
            $comment_status = $Annotate ? gTxt('on') : gTxt('off');
            if ($comments_disabled_after) {
                $lifespan = $comments_disabled_after * 86400;
                $time_since = time() - $posted;
                if ($time_since > $lifespan) {
                    $comment_status = gTxt('expired');
                }
            }
            $comments = tag($comment_status, 'span', array('class' => 'comments-status')) . ' ' . tag($comments, 'span', array('class' => 'comments-manage'));
            echo tr(td(($a['Status'] >= STATUS_LIVE and has_privs('article.edit.published') or $a['Status'] >= STATUS_LIVE and $AuthorID === $txp_user and has_privs('article.edit.own.published') or $a['Status'] < STATUS_LIVE and has_privs('article.edit') or $a['Status'] < STATUS_LIVE and $AuthorID === $txp_user and has_privs('article.edit.own')) ? fInput('checkbox', 'selected[]', $ID, 'checkbox') : '', '', 'txp-list-col-multi-edit') . hCell(eLink('article', 'edit', 'ID', $ID, $ID) . tag(sp . tag('[', 'span', array('aria-hidden' => 'true')) . href(gTxt('view'), $view_url) . tag(']', 'span', array('aria-hidden' => 'true')), 'span', array('class' => 'articles_detail')), '', ' scope="row" class="txp-list-col-id"') . td($Title, '', 'txp-list-col-title') . td(gTime($posted), '', 'txp-list-col-created date' . ($posted < time() ? '' : ' unpublished')) . td(gTime($lastmod), '', 'txp-list-col-lastmod date articles_detail' . ($posted === $lastmod ? ' not-modified' : '')) . td($expires ? gTime($expires) : '', '', 'txp-list-col-expires date articles_detail') . td(span(txpspecialchars($section_title), array('title' => $Section)), '', 'txp-list-col-section' . $vs) . td($Category1, '', 'txp-list-col-category1 category articles_detail' . $vc[1]) . td($Category2, '', 'txp-list-col-category2 category articles_detail' . $vc[2]) . td(href($Status, $view_url, join_atts(array('title' => gTxt('view')))), '', 'txp-list-col-status') . ($show_authors ? td(span(txpspecialchars($RealName), array('title' => $AuthorID)), '', 'txp-list-col-author name') : '') . ($use_comments ? td($comments, '', 'txp-list-col-comments articles_detail') : ''));
        }
        echo n . tag_end('tbody') . n . tag_end('table') . n . tag_end('div') . list_multiedit_form($page, $sort, $dir, $crit, $search_method) . tInput() . n . tag_end('form') . graf(toggle_box('articles_detail'), array('class' => 'detail-toggle')) . n . tag_start('div', array('id' => $event . '_navigation', 'class' => 'txp-navigation')) . pageby_form('list', $article_list_pageby) . nav_form('list', $page, $numPages, $sort, $dir, $crit, $search_method, $total, $limit) . n . tag_end('div') . n . tag_end('div');
    }
}
Example #3
0
function discuss_list($message = '')
{
    global $comment_list_pageby;
    pagetop(gTxt('list_discussions'), $message);
    echo graf('<a href="index.php?event=discuss' . a . 'step=ipban_list">' . gTxt('list_banned_ips') . '</a>', ' style="text-align: center;"');
    extract(gpsa(array('sort', 'dir', 'page', 'crit', 'search_method')));
    $dir = $dir == 'asc' ? 'asc' : 'desc';
    switch ($sort) {
        case 'id':
            $sort_sql = 'discussid ' . $dir;
            break;
        case 'ip':
            $sort_sql = 'ip ' . $dir;
            break;
        case 'name':
            $sort_sql = 'name ' . $dir;
            break;
        case 'email':
            $sort_sql = 'email ' . $dir;
            break;
        case 'website':
            $sort_sql = 'web ' . $dir;
            break;
        case 'message':
            $sort_sql = 'message ' . $dir;
            break;
        case 'status':
            $sort_sql = 'visible ' . $dir;
            break;
        case 'parent':
            $sort_sql = 'parentid ' . $dir;
            break;
        default:
            $sort = 'date';
            $sort_sql = 'txp_discuss.posted ' . $dir;
            break;
    }
    if ($sort != 'date') {
        $sort_sql .= ', txp_discuss.posted asc';
    }
    $switch_dir = $dir == 'desc' ? 'asc' : 'desc';
    $criteria = 1;
    if ($search_method and $crit) {
        $crit_escaped = doSlash($crit);
        $critsql = array('id' => "discussid = '{$crit_escaped}'", 'parent' => "parentid = '{$crit_escaped}'" . (intval($crit_escaped) ? '' : " OR title like '%{$crit_escaped}%'"), 'name' => "name like '%{$crit_escaped}%'", 'message' => "message like '%{$crit_escaped}%'", 'email' => "email like '%{$crit_escaped}%'", 'website' => "web like '%{$crit_escaped}%'", 'ip' => "ip like '%{$crit_escaped}%'");
        if (array_key_exists($search_method, $critsql)) {
            $criteria = $critsql[$search_method];
            $limit = 500;
        } else {
            $search_method = '';
            $crit = '';
        }
    } else {
        $search_method = '';
        $crit = '';
    }
    $counts = getRows('SELECT visible, COUNT(*) AS c' . ' FROM ' . safe_pfx_j('txp_discuss') . ' LEFT JOIN ' . safe_pfx_j('textpattern') . ' ON txp_discuss.parentid = textpattern.ID' . ' WHERE ' . $criteria . ' GROUP BY visible');
    $count[SPAM] = $count[MODERATE] = $count[VISIBLE] = 0;
    if ($counts) {
        foreach ($counts as $c) {
            $count[$c['visible']] = $c['c'];
        }
    }
    // grand total comment count
    $total = $count[SPAM] + $count[MODERATE] + $count[VISIBLE];
    if ($total < 1) {
        if ($criteria != 1) {
            echo n . discuss_search_form($crit, $search_method) . n . graf(gTxt('no_results_found'), ' class="indicator"');
        } else {
            echo graf(gTxt('no_comments_recorded'), ' class="indicator"');
        }
        return;
    }
    // paging through displayed comments
    $total = (cs('toggle_show_spam') ? $count[SPAM] : 0) + $count[MODERATE] + $count[VISIBLE];
    $limit = max($comment_list_pageby, 15);
    list($page, $offset, $numPages) = pager($total, $limit, $page);
    echo discuss_search_form($crit, $search_method);
    $spamq = cs('toggle_show_spam') ? '1=1' : 'visible != ' . intval(SPAM);
    $rs = safe_query('SELECT txp_discuss.*, unix_timestamp(txp_discuss.posted) as uPosted, ID as thisid, Section as section, url_title, Title as title, Status, unix_timestamp(textpattern.Posted) as posted' . ' FROM ' . safe_pfx_j('txp_discuss') . ' LEFT JOIN ' . safe_pfx_j('textpattern') . ' ON txp_discuss.parentid = textpattern.ID' . ' WHERE ' . $spamq . ' AND ' . $criteria . ' ORDER BY ' . $sort_sql . ' LIMIT ' . $offset . ', ' . $limit);
    if ($rs) {
        echo n . n . '<form name="longform" method="post" action="index.php" onsubmit="return verify(\'' . gTxt('are_you_sure') . '\')">' . n . startTable('list', '', '', '', '90%') . n . n . tr(column_head('ID', 'id', 'discuss', true, $switch_dir, $crit, $search_method, 'id' == $sort ? $dir : '') . column_head('date', 'date', 'discuss', true, $switch_dir, $crit, $search_method, 'date' == $sort ? $dir : '') . column_head('name', 'name', 'discuss', true, $switch_dir, $crit, $search_method, 'name' == $sort ? $dir : '') . column_head('message', 'message', 'discuss', true, $switch_dir, $crit, $search_method, 'message' == $sort ? $dir : '') . column_head('email', 'email', 'discuss', true, $switch_dir, $crit, $search_method, ('email' == $sort ? "{$dir} " : '') . 'discuss_detail') . column_head('website', 'website', 'discuss', true, $switch_dir, $crit, $search_method, ('website' == $sort ? "{$dir} " : '') . 'discuss_detail') . column_head('IP', 'ip', 'discuss', true, $switch_dir, $crit, $search_method, ('ip' == $sort ? "{$dir} " : '') . 'discuss_detail') . column_head('status', 'status', 'discuss', true, $switch_dir, $crit, $search_method, ('status' == $sort ? "{$dir} " : '') . 'discuss_detail') . column_head('parent', 'parent', 'discuss', true, $switch_dir, $crit, $search_method, 'parent' == $sort ? $dir : '') . hCell());
        include_once txpath . '/publish/taghandlers.php';
        while ($a = nextRow($rs)) {
            extract($a);
            $parentid = assert_int($parentid);
            $edit_url = '?event=discuss' . a . 'step=discuss_edit' . a . 'discussid=' . $discussid . a . 'sort=' . $sort . a . 'dir=' . $dir . a . 'page=' . $page . a . 'search_method=' . $search_method . a . 'crit=' . $crit;
            $dmessage = $visible == SPAM ? short_preview($message) : $message;
            switch ($visible) {
                case VISIBLE:
                    $comment_status = gTxt('visible');
                    $row_class = 'visible';
                    break;
                case SPAM:
                    $comment_status = gTxt('spam');
                    $row_class = 'spam';
                    break;
                case MODERATE:
                    $comment_status = gTxt('unmoderated');
                    $row_class = 'moderate';
                    break;
                default:
                    break;
            }
            if (empty($thisid)) {
                $parent = gTxt('article_deleted') . ' (' . $parentid . ')';
                $view = '';
            } else {
                $parent_title = empty($title) ? '<em>' . gTxt('untitled') . '</em>' : escape_title($title);
                $parent = href($parent_title, '?event=article' . a . 'step=edit' . a . 'ID=' . $parentid);
                $view = '';
                if ($visible == VISIBLE and in_array($Status, array(4, 5))) {
                    $view = n . t . '<li><a href="' . permlinkurl($a) . '#c' . $discussid . '">' . gTxt('view') . '</a></li>';
                }
            }
            echo n . n . tr(n . td('<a href="' . $edit_url . '">' . $discussid . '</a>' . n . '<ul class="discuss_detail">' . n . t . '<li><a href="' . $edit_url . '">' . gTxt('edit') . '</a></li>' . $view . n . '</ul>', 50) . td(gTime($uPosted)) . td(htmlspecialchars(soft_wrap($name, 15))) . td(short_preview($dmessage)) . td(htmlspecialchars(soft_wrap($email, 15)), '', 'discuss_detail') . td(htmlspecialchars(soft_wrap($web, 15)), '', 'discuss_detail') . td($ip, '', 'discuss_detail') . td($comment_status, '', 'discuss_detail') . td($parent) . td(fInput('checkbox', 'selected[]', $discussid)), ' class="' . $row_class . '"');
        }
        if (empty($message)) {
            echo tr(tda(gTxt('just_spam_results_found'), ' colspan="9" style="text-align: left; border: none;"'));
        }
        echo tr(tda(toggle_box('discuss_detail'), ' colspan="2" style="text-align: left; border: none;"') . tda(select_buttons() . discuss_multiedit_form($page, $sort, $dir, $crit, $search_method), ' colspan="9" style="text-align: right; border: none;"')) . endTable() . '</form>' . n . cookie_box('show_spam') . nav_form('discuss', $page, $numPages, $sort, $dir, $crit, $search_method) . pageby_form('discuss', $comment_list_pageby);
    }
}
Example #4
0
function link_list($message = '')
{
    global $event, $step, $link_list_pageby, $txp_user;
    pagetop(gTxt('tab_link'), $message);
    extract(gpsa(array('page', 'sort', 'dir', 'crit', 'search_method')));
    if ($sort === '') {
        $sort = get_pref('link_sort_column', 'name');
    }
    if ($dir === '') {
        $dir = get_pref('link_sort_dir', 'asc');
    }
    $dir = $dir == 'desc' ? 'desc' : 'asc';
    switch ($sort) {
        case 'id':
            $sort_sql = 'id ' . $dir;
            break;
        case 'description':
            $sort_sql = 'description ' . $dir . ', id asc';
            break;
        case 'url':
            $sort_sql = 'url ' . $dir . ', id asc';
            break;
        case 'category':
            $sort_sql = 'category ' . $dir . ', id asc';
            break;
        case 'date':
            $sort_sql = 'date ' . $dir . ', id asc';
            break;
        case 'author':
            $sort_sql = 'author ' . $dir . ', id asc';
            break;
        default:
            $sort = 'name';
            $sort_sql = 'linksort ' . $dir . ', id asc';
            break;
    }
    set_pref('link_sort_column', $sort, 'link', 2, '', 0, PREF_PRIVATE);
    set_pref('link_sort_dir', $dir, 'link', 2, '', 0, PREF_PRIVATE);
    $switch_dir = $dir == 'desc' ? 'asc' : 'desc';
    $criteria = 1;
    if ($search_method and $crit != '') {
        $verbatim = preg_match('/^"(.*)"$/', $crit, $m);
        $crit_escaped = doSlash($verbatim ? $m[1] : str_replace(array('\\', '%', '_', '\''), array('\\\\', '\\%', '\\_', '\\\''), $crit));
        $critsql = $verbatim ? array('id' => "ID in ('" . join("','", do_list($crit_escaped)) . "')", 'name' => "linkname = '{$crit_escaped}'", 'description' => "description = '{$crit_escaped}'", 'url' => "url = '{$crit_escaped}'", 'category' => "category = '{$crit_escaped}'", 'author' => "author = '{$crit_escaped}'") : array('id' => "ID in ('" . join("','", do_list($crit_escaped)) . "')", 'name' => "linkname like '%{$crit_escaped}%'", 'description' => "description like '%{$crit_escaped}%'", 'url' => "url like '%{$crit_escaped}%'", 'category' => "category like '%{$crit_escaped}%'", 'author' => "author like '%{$crit_escaped}%'");
        if (array_key_exists($search_method, $critsql)) {
            $criteria = $critsql[$search_method];
        } else {
            $search_method = '';
            $crit = '';
        }
    } else {
        $search_method = '';
        $crit = '';
    }
    $criteria .= callback_event('admin_criteria', 'link_list', 0, $criteria);
    $total = getCount('txp_link', $criteria);
    echo '<h1 class="txp-heading">' . gTxt('tab_link') . '</h1>';
    echo '<div id="' . $event . '_control" class="txp-control-panel">';
    if (has_privs('link.edit')) {
        echo graf(sLink('link', 'link_edit', gTxt('add_new_link')), ' class="txp-buttons"');
    }
    if ($total < 1) {
        if ($criteria != 1) {
            echo n . link_search_form($crit, $search_method) . n . graf(gTxt('no_results_found'), ' class="indicator"') . '</div>';
        } else {
            echo n . graf(gTxt('no_links_recorded'), ' class="indicator"') . '</div>';
        }
        return;
    }
    $limit = max($link_list_pageby, 15);
    list($page, $offset, $numPages) = pager($total, $limit, $page);
    echo link_search_form($crit, $search_method) . '</div>';
    $rs = safe_rows_start('*, unix_timestamp(date) as uDate', 'txp_link', "{$criteria} order by {$sort_sql} limit {$offset}, {$limit}");
    if ($rs) {
        $show_authors = !has_single_author('txp_link');
        echo n . '<div id="' . $event . '_container" class="txp-container">';
        echo n . n . '<form action="index.php" id="links_form" class="multi_edit_form" method="post" name="longform">', n . '<div class="txp-listtables">' . n . startTable('', '', 'txp-list') . n . '<thead>' . n . tr(n . hCell(fInput('checkbox', 'select_all', 0, '', '', '', '', '', 'select_all'), '', ' title="' . gTxt('toggle_all_selected') . '" class="multi-edit"') . n . column_head('ID', 'id', 'link', true, $switch_dir, $crit, $search_method, ('id' == $sort ? "{$dir} " : '') . 'id') . n . column_head('link_name', 'name', 'link', true, $switch_dir, $crit, $search_method, ('name' == $sort ? "{$dir} " : '') . 'name') . n . column_head('description', 'description', 'link', true, $switch_dir, $crit, $search_method, ('description' == $sort ? "{$dir} " : '') . 'links_detail description') . n . column_head('link_category', 'category', 'link', true, $switch_dir, $crit, $search_method, ('category' == $sort ? "{$dir} " : '') . 'category') . n . column_head('url', 'url', 'link', true, $switch_dir, $crit, $search_method, ('url' == $sort ? "{$dir} " : '') . 'url') . n . column_head('date', 'date', 'link', true, $switch_dir, $crit, $search_method, ('date' == $sort ? "{$dir} " : '') . 'links_detail date created') . ($show_authors ? n . column_head('author', 'author', 'link', true, $switch_dir, $crit, $search_method, ('author' == $sort ? "{$dir} " : '') . 'author') : '')) . n . '</thead>';
        echo '<tbody>';
        $validator = new Validator();
        while ($a = nextRow($rs)) {
            extract($a, EXTR_PREFIX_ALL, 'link');
            $edit_url = '?event=link' . a . 'step=link_edit' . a . 'id=' . $link_id . a . 'sort=' . $sort . a . 'dir=' . $dir . a . 'page=' . $page . a . 'search_method=' . $search_method . a . 'crit=' . $crit;
            $validator->setConstraints(array(new CategoryConstraint($link_category, array('type' => 'link'))));
            $vc = $validator->validate() ? '' : ' error';
            $can_edit = has_privs('link.edit') || $link_author == $txp_user && has_privs('link.edit.own');
            $view_url = txpspecialchars($link_url);
            echo tr(n . td(fInput('checkbox', 'selected[]', $link_id), '', 'multi-edit') . n . td($can_edit ? href($link_id, $edit_url, ' title="' . gTxt('edit') . '"') : $link_id, '', 'id') . td($can_edit ? href(txpspecialchars($link_linkname), $edit_url, ' title="' . gTxt('edit') . '"') : txpspecialchars($link_linkname), '', 'name') . td(txpspecialchars($link_description), '', 'links_detail description') . td('<span title="' . txpspecialchars(fetch_category_title($link_category, 'link')) . '">' . $link_category . '</span>', '', 'category' . $vc) . td('<a rel="external" target="_blank" href="' . $view_url . '">' . $view_url . '</a>', '', 'url') . td(gTime($link_uDate), '', 'links_detail date created') . ($show_authors ? td('<span title="' . txpspecialchars(get_author_name($link_author)) . '">' . txpspecialchars($link_author) . '</span>', '', 'author') : ''));
        }
        echo '</tbody>', n, endTable(), n, '</div>', n, link_multiedit_form($page, $sort, $dir, $crit, $search_method), n, tInput(), n, '</form>', n, graf(toggle_box('links_detail'), ' class="detail-toggle"'), n, '<div id="' . $event . '_navigation" class="txp-navigation">', n, nav_form('link', $page, $numPages, $sort, $dir, $crit, $search_method, $total, $limit), n, pageby_form('link', $link_list_pageby), n, '</div>', n, '</div>';
    }
}
Example #5
0
/**
 * The main panel listing all log hits.
 *
 * @param string|array $message The activity message
 */
function log_list($message = '')
{
    global $event, $log_list_pageby, $expire_logs_after;
    pagetop(gTxt('tab_logs'), $message);
    extract(gpsa(array('page', 'sort', 'dir', 'crit', 'search_method')));
    if ($sort === '') {
        $sort = get_pref('log_sort_column', 'time');
    } else {
        if (!in_array($sort, array('ip', 'host', 'page', 'refer', 'method', 'status'))) {
            $sort = 'time';
        }
        set_pref('log_sort_column', $sort, 'log', 2, '', 0, PREF_PRIVATE);
    }
    if ($dir === '') {
        $dir = get_pref('log_sort_dir', 'desc');
    } else {
        $dir = $dir == 'asc' ? "asc" : "desc";
        set_pref('log_sort_dir', $dir, 'log', 2, '', 0, PREF_PRIVATE);
    }
    $expire_logs_after = assert_int($expire_logs_after);
    safe_delete('txp_log', "time < DATE_SUB(NOW(), INTERVAL {$expire_logs_after} DAY)");
    switch ($sort) {
        case 'ip':
            $sort_sql = "ip {$dir}";
            break;
        case 'host':
            $sort_sql = "host {$dir}";
            break;
        case 'page':
            $sort_sql = "page {$dir}";
            break;
        case 'refer':
            $sort_sql = "refer {$dir}";
            break;
        case 'method':
            $sort_sql = "method {$dir}";
            break;
        case 'status':
            $sort_sql = "status {$dir}";
            break;
        default:
            $sort = 'time';
            $sort_sql = "time {$dir}";
            break;
    }
    $switch_dir = $dir == 'desc' ? 'asc' : 'desc';
    $search = new Filter($event, array('ip' => array('column' => 'txp_log.ip', 'label' => gTxt('IP')), 'host' => array('column' => 'txp_log.host', 'label' => gTxt('host')), 'page' => array('column' => 'txp_log.page', 'label' => gTxt('page')), 'refer' => array('column' => 'txp_log.refer', 'label' => gTxt('referrer')), 'method' => array('column' => 'txp_log.method', 'label' => gTxt('method')), 'status' => array('column' => 'txp_log.status', 'label' => gTxt('status'), 'type' => 'integer')));
    list($criteria, $crit, $search_method) = $search->getFilter(array('status' => array('can_list' => true)));
    $search_render_options = array('placeholder' => 'search_logs');
    $total = safe_count('txp_log', "{$criteria}");
    echo n . tag(hed(gTxt('tab_logs'), 1, array('class' => 'txp-heading')), 'div', array('class' => 'txp-layout-2col-cell-1'));
    $searchBlock = n . tag($search->renderForm('log_list', $search_render_options), 'div', array('class' => 'txp-layout-2col-cell-2', 'id' => $event . '_control'));
    $contentBlockStart = n . tag_start('div', array('class' => 'txp-layout-1col', 'id' => $event . '_container'));
    if ($total < 1) {
        if ($criteria != 1) {
            echo $searchBlock . $contentBlockStart . graf(span(null, array('class' => 'ui-icon ui-icon-info')) . ' ' . gTxt('no_results_found'), array('class' => 'alert-block information'));
        } else {
            echo $contentBlockStart . graf(span(null, array('class' => 'ui-icon ui-icon-info')) . ' ' . gTxt('no_refers_recorded'), array('class' => 'alert-block information'));
        }
        echo n . tag_end('div');
        return;
    }
    $limit = max($log_list_pageby, 15);
    list($page, $offset, $numPages) = pager($total, $limit, $page);
    echo $searchBlock . $contentBlockStart;
    $rs = safe_rows_start("*, UNIX_TIMESTAMP(time) AS uTime", 'txp_log', "{$criteria} ORDER BY {$sort_sql} LIMIT {$offset}, {$limit}");
    if ($rs) {
        echo n . tag(toggle_box('log_detail'), 'div', array('class' => 'txp-list-options')) . n . tag_start('form', array('class' => 'multi_edit_form', 'id' => 'log_form', 'name' => 'longform', 'method' => 'post', 'action' => 'index.php')) . n . tag_start('div', array('class' => 'txp-listtables')) . n . tag_start('table', array('class' => 'txp-list')) . n . tag_start('thead') . tr(hCell(fInput('checkbox', 'select_all', 0, '', '', '', '', '', 'select_all'), '', ' class="txp-list-col-multi-edit" scope="col" title="' . gTxt('toggle_all_selected') . '"') . column_head('time', 'time', 'log', true, $switch_dir, $crit, $search_method, ('time' == $sort ? "{$dir} " : '') . 'txp-list-col-time') . column_head('IP', 'ip', 'log', true, $switch_dir, $crit, $search_method, ('ip' == $sort ? "{$dir} " : '') . 'txp-list-col-ip') . column_head('host', 'host', 'log', true, $switch_dir, $crit, $search_method, ('host' == $sort ? "{$dir} " : '') . 'txp-list-col-host log_detail') . column_head('page', 'page', 'log', true, $switch_dir, $crit, $search_method, ('page' == $sort ? "{$dir} " : '') . 'txp-list-col-page') . column_head('referrer', 'refer', 'log', true, $switch_dir, $crit, $search_method, ('refer' == $sort ? "{$dir} " : '') . 'txp-list-col-refer') . column_head('method', 'method', 'log', true, $switch_dir, $crit, $search_method, ('method' == $sort ? "{$dir} " : '') . 'txp-list-col-method log_detail') . column_head('status', 'status', 'log', true, $switch_dir, $crit, $search_method, ('status' == $sort ? "{$dir} " : '') . 'txp-list-col-status log_detail')) . n . tag_end('thead') . n . tag_start('tbody');
        while ($a = nextRow($rs)) {
            extract($a, EXTR_PREFIX_ALL, 'log');
            if ($log_refer) {
                $log_refer = href(txpspecialchars(soft_wrap(preg_replace('#^http://#', '', $log_refer), 30)), txpspecialchars($log_refer), ' target="_blank"');
            }
            if ($log_page) {
                $log_anchor = preg_replace('/\\/$/', '', $log_page);
                $log_anchor = soft_wrap(substr($log_anchor, 1), 30);
                $log_page = href(txpspecialchars($log_anchor), txpspecialchars($log_page), ' target="_blank"');
                if ($log_method == 'POST') {
                    $log_page = strong($log_page);
                }
            }
            echo tr(td(fInput('checkbox', 'selected[]', $log_id), '', 'txp-list-col-multi-edit') . hCell(gTime($log_uTime), '', ' class="txp-list-col-time" scope="row"') . td(href(txpspecialchars($log_ip), 'https://whois.domaintools.com/' . rawurlencode($log_ip), array('rel' => 'external', 'target' => '_blank')), '', 'txp-list-col-ip') . td(txpspecialchars($log_host), '', 'txp-list-col-host log_detail') . td($log_page, '', 'txp-list-col-page') . td($log_refer, '', 'txp-list-col-refer') . td(txpspecialchars($log_method), '', 'txp-list-col-method log_detail') . td($log_status, '', 'txp-list-col-status log_detail'));
        }
        echo n . tag_end('tbody') . n . tag_end('table') . n . tag_end('div') . log_multiedit_form($page, $sort, $dir, $crit, $search_method) . tInput() . n . tag_end('form') . n . tag_start('div', array('class' => 'txp-navigation', 'id' => $event . '_navigation')) . pageby_form('log', $log_list_pageby) . nav_form('log', $page, $numPages, $sort, $dir, $crit, $search_method, $total, $limit) . n . tag_end('div');
    }
    echo n . tag_end('div');
}
Example #6
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 #7
0
/**
 * The main panel listing all articles.
 *
 * @param  string|array $message The activity message
 * @param  string       $post    Not used
 */
function list_list($message = '', $post = '')
{
    global $statuses, $use_comments, $comments_disabled_after, $step, $txp_user, $article_list_pageby, $event;
    pagetop(gTxt('tab_list'), $message);
    extract(gpsa(array('page', 'sort', 'dir', 'crit', 'search_method')));
    if ($sort === '') {
        $sort = get_pref('article_sort_column', 'posted');
    } else {
        if (!in_array($sort, array('id', 'title', 'expires', 'section', 'category1', 'category2', 'status', 'author', 'comments', 'lastmod'))) {
            $sort = 'posted';
        }
        set_pref('article_sort_column', $sort, 'list', 2, '', 0, PREF_PRIVATE);
    }
    if ($dir === '') {
        $dir = get_pref('article_sort_dir', 'desc');
    } else {
        $dir = $dir == 'asc' ? "asc" : "desc";
        set_pref('article_sort_dir', $dir, 'list', 2, '', 0, PREF_PRIVATE);
    }
    $sesutats = array_flip($statuses);
    switch ($sort) {
        case 'id':
            $sort_sql = "textpattern.ID {$dir}";
            break;
        case 'title':
            $sort_sql = "textpattern.Title {$dir}, textpattern.Posted DESC";
            break;
        case 'expires':
            $sort_sql = "textpattern.Expires {$dir}";
            break;
        case 'section':
            $sort_sql = "section.title {$dir}, textpattern.Posted DESC";
            break;
        case 'category1':
            $sort_sql = "category1.title {$dir}, textpattern.Posted DESC";
            break;
        case 'category2':
            $sort_sql = "category2.title {$dir}, textpattern.Posted DESC";
            break;
        case 'status':
            $sort_sql = "textpattern.Status {$dir}, textpattern.Posted DESC";
            break;
        case 'author':
            $sort_sql = "user.RealName {$dir}, textpattern.Posted DESC";
            break;
        case 'comments':
            $sort_sql = "textpattern.comments_count {$dir}, textpattern.Posted DESC";
            break;
        case 'lastmod':
            $sort_sql = "textpattern.LastMod {$dir}, textpattern.Posted DESC";
            break;
        default:
            $sort = 'posted';
            $sort_sql = "textpattern.Posted {$dir}";
            break;
    }
    $switch_dir = $dir == 'desc' ? 'asc' : 'desc';
    $search = new Filter($event, array('id' => array('column' => 'textpattern.ID', 'label' => gTxt('ID'), 'type' => 'integer'), 'title_body_excerpt' => array('column' => array('textpattern.Title', 'textpattern.Body', 'textpattern.Excerpt'), 'label' => gTxt('title_body_excerpt')), 'section' => array('column' => array('textpattern.Section', 'section.title'), 'label' => gTxt('section')), 'keywords' => array('column' => 'textpattern.Keywords', 'label' => gTxt('keywords'), 'type' => 'find_in_set'), 'categories' => array('column' => array('textpattern.Category1', 'textpattern.Category2', 'category1.title', 'category2.title'), 'label' => gTxt('categories')), 'status' => array('column' => array('textpattern.Status'), 'label' => gTxt('status'), 'type' => 'boolean'), 'author' => array('column' => array('textpattern.AuthorID', 'user.RealName'), 'label' => gTxt('author')), 'article_image' => array('column' => array('textpattern.Image'), 'label' => gTxt('article_image'), 'type' => 'integer'), 'posted' => array('column' => array('textpattern.Posted'), 'label' => gTxt('posted')), 'lastmod' => array('column' => array('textpattern.LastMod'), 'label' => gTxt('article_modified'))));
    $search->setAliases('status', $statuses);
    list($criteria, $crit, $search_method) = $search->getFilter(array('id' => array('can_list' => true), 'article_image' => array('can_list' => true), 'title_body_excerpt' => array('always_like' => true)));
    $search_render_options = array('placeholder' => 'search_articles');
    $sql_from = safe_pfx('textpattern') . " textpattern\n        LEFT JOIN " . safe_pfx('txp_category') . " category1 ON category1.name = textpattern.Category1 AND category1.type = 'article'\n        LEFT JOIN " . safe_pfx('txp_category') . " category2 ON category2.name = textpattern.Category2 AND category2.type = 'article'\n        LEFT JOIN " . safe_pfx('txp_section') . " section ON section.name = textpattern.Section\n        LEFT JOIN " . safe_pfx('txp_users') . " user ON user.name = textpattern.AuthorID";
    if ($criteria === 1) {
        $total = safe_count('textpattern', $criteria);
    } else {
        $total = getThing("SELECT COUNT(*) FROM {$sql_from} WHERE {$criteria}");
    }
    echo n . tag(hed(gTxt('tab_list'), 1, array('class' => 'txp-heading')), 'div', array('class' => 'txp-layout-2col-cell-1'));
    $searchBlock = n . tag($search->renderForm('list', $search_render_options), 'div', array('class' => 'txp-layout-2col-cell-2', 'id' => $event . '_control'));
    $createBlock = array();
    if (has_privs('article.edit')) {
        $createBlock[] = n . tag(sLink('article', '', gTxt('add_new_article'), 'txp-button'), 'div', array('class' => 'txp-control-panel'));
    }
    $contentBlockStart = n . tag_start('div', array('class' => 'txp-layout-1col', 'id' => $event . '_container'));
    $createBlock = implode(n, $createBlock);
    if ($total < 1) {
        if ($criteria != 1) {
            echo $searchBlock . $contentBlockStart . $createBlock . graf(span(null, array('class' => 'ui-icon ui-icon-info')) . ' ' . gTxt('no_results_found'), array('class' => 'alert-block information'));
        } else {
            echo $contentBlockStart . $createBlock . graf(span(null, array('class' => 'ui-icon ui-icon-info')) . ' ' . gTxt('no_articles_recorded'), array('class' => 'alert-block information'));
        }
        echo n . tag_end('div');
        return;
    }
    $limit = max($article_list_pageby, 15);
    list($page, $offset, $numPages) = pager($total, $limit, $page);
    echo $searchBlock . $contentBlockStart . $createBlock;
    $rs = safe_query("SELECT\n            textpattern.ID, textpattern.Title, textpattern.url_title, textpattern.Section,\n            textpattern.Category1, textpattern.Category2,\n            textpattern.Status, textpattern.Annotate, textpattern.AuthorID,\n            UNIX_TIMESTAMP(textpattern.Posted) AS posted,\n            UNIX_TIMESTAMP(textpattern.LastMod) AS lastmod,\n            UNIX_TIMESTAMP(textpattern.Expires) AS expires,\n            category1.title AS category1_title,\n            category2.title AS category2_title,\n            section.title AS section_title,\n            user.RealName AS RealName,\n            (SELECT COUNT(*) FROM " . safe_pfx('txp_discuss') . " WHERE parentid = textpattern.ID) AS total_comments\n        FROM {$sql_from} WHERE {$criteria} ORDER BY {$sort_sql} LIMIT {$offset}, {$limit}");
    if ($rs) {
        $show_authors = !has_single_author('textpattern', 'AuthorID');
        echo n . tag(toggle_box('articles_detail'), 'div', array('class' => 'txp-list-options')) . n . tag_start('form', array('class' => 'multi_edit_form', 'id' => 'articles_form', 'name' => 'longform', 'method' => 'post', 'action' => 'index.php')) . n . tag_start('div', array('class' => 'txp-listtables')) . n . tag_start('table', array('class' => 'txp-list')) . n . tag_start('thead') . tr(hCell(fInput('checkbox', 'select_all', 0, '', '', '', '', '', 'select_all'), '', ' class="txp-list-col-multi-edit" scope="col" title="' . gTxt('toggle_all_selected') . '"') . column_head('ID', 'id', 'list', true, $switch_dir, $crit, $search_method, ('id' == $sort ? "{$dir} " : '') . 'txp-list-col-id') . column_head('title', 'title', 'list', true, $switch_dir, $crit, $search_method, ('title' == $sort ? "{$dir} " : '') . 'txp-list-col-title') . column_head('posted', 'posted', 'list', true, $switch_dir, $crit, $search_method, ('posted' == $sort ? "{$dir} " : '') . 'txp-list-col-created date') . column_head('article_modified', 'lastmod', 'list', true, $switch_dir, $crit, $search_method, ('lastmod' == $sort ? "{$dir} " : '') . 'txp-list-col-lastmod date articles_detail') . column_head('expires', 'expires', 'list', true, $switch_dir, $crit, $search_method, ('expires' == $sort ? "{$dir} " : '') . 'txp-list-col-expires date articles_detail') . column_head('section', 'section', 'list', true, $switch_dir, $crit, $search_method, ('section' == $sort ? "{$dir} " : '') . 'txp-list-col-section') . column_head('category1', 'category1', 'list', true, $switch_dir, $crit, $search_method, ('category1' == $sort ? "{$dir} " : '') . 'txp-list-col-category1 category articles_detail') . column_head('category2', 'category2', 'list', true, $switch_dir, $crit, $search_method, ('category2' == $sort ? "{$dir} " : '') . 'txp-list-col-category2 category articles_detail') . column_head('status', 'status', 'list', true, $switch_dir, $crit, $search_method, ('status' == $sort ? "{$dir} " : '') . 'txp-list-col-status') . ($show_authors ? column_head('author', 'author', 'list', true, $switch_dir, $crit, $search_method, ('author' == $sort ? "{$dir} " : '') . 'txp-list-col-author name') : '') . ($use_comments == 1 ? column_head('comments', 'comments', 'list', true, $switch_dir, $crit, $search_method, ('comments' == $sort ? "{$dir} " : '') . 'txp-list-col-comments articles_detail') : '')) . n . tag_end('thead');
        include_once txpath . '/publish/taghandlers.php';
        echo n . tag_start('tbody');
        $validator = new Validator();
        while ($a = nextRow($rs)) {
            extract($a);
            if ($Title === '') {
                $Title = '<em>' . eLink('article', 'edit', 'ID', $ID, gTxt('untitled')) . '</em>';
            } else {
                $Title = eLink('article', 'edit', 'ID', $ID, $Title);
            }
            // Valid section and categories?
            $validator->setConstraints(array(new SectionConstraint($Section)));
            $vs = $validator->validate() ? '' : ' error';
            $validator->setConstraints(array(new CategoryConstraint($Category1, array('type' => 'article'))));
            $vc[1] = $validator->validate() ? '' : ' error';
            $validator->setConstraints(array(new CategoryConstraint($Category2, array('type' => 'article'))));
            $vc[2] = $validator->validate() ? '' : ' error';
            $Category1 = $Category1 ? span(txpspecialchars($category1_title), array('title' => $Category1)) : '';
            $Category2 = $Category2 ? span(txpspecialchars($category2_title), array('title' => $Category2)) : '';
            if ($Status != STATUS_LIVE and $Status != STATUS_STICKY) {
                $view_url = '?txpreview=' . intval($ID) . '.' . time();
            } else {
                $view_url = permlinkurl($a);
            }
            if (isset($statuses[$Status])) {
                $Status = $statuses[$Status];
            }
            $comments = '(' . $total_comments . ')';
            if ($total_comments) {
                $comments = href($comments, array('event' => 'discuss', 'step' => 'list', 'search_method' => 'parent', 'crit' => $ID), array('title' => gTxt('manage')));
            }
            $comment_status = $Annotate ? gTxt('on') : gTxt('off');
            if ($comments_disabled_after) {
                $lifespan = $comments_disabled_after * 86400;
                $time_since = time() - $posted;
                if ($time_since > $lifespan) {
                    $comment_status = gTxt('expired');
                }
            }
            $comments = tag($comment_status, 'span', array('class' => 'comments-status')) . ' ' . tag($comments, 'span', array('class' => 'comments-manage'));
            echo tr(td(($a['Status'] >= STATUS_LIVE and has_privs('article.edit.published') or $a['Status'] >= STATUS_LIVE and $AuthorID === $txp_user and has_privs('article.edit.own.published') or $a['Status'] < STATUS_LIVE and has_privs('article.edit') or $a['Status'] < STATUS_LIVE and $AuthorID === $txp_user and has_privs('article.edit.own')) ? fInput('checkbox', 'selected[]', $ID, 'checkbox') : '', '', 'txp-list-col-multi-edit') . hCell(eLink('article', 'edit', 'ID', $ID, $ID) . sp . span(span('[', array('aria-hidden' => 'true')) . href(gTxt('view'), $view_url) . span(']', array('aria-hidden' => 'true')), array('class' => 'txp-option-link articles_detail')), '', ' class="txp-list-col-id" scope="row"') . td($Title, '', 'txp-list-col-title') . td(gTime($posted), '', 'txp-list-col-created date' . ($posted < time() ? '' : ' unpublished')) . td(gTime($lastmod), '', 'txp-list-col-lastmod date articles_detail' . ($posted === $lastmod ? ' not-modified' : '')) . td($expires ? gTime($expires) : '', '', 'txp-list-col-expires date articles_detail') . td(span(txpspecialchars($section_title), array('title' => $Section)), '', 'txp-list-col-section' . $vs) . td($Category1, '', 'txp-list-col-category1 category articles_detail' . $vc[1]) . td($Category2, '', 'txp-list-col-category2 category articles_detail' . $vc[2]) . td(href($Status, $view_url, join_atts(array('title' => gTxt('view')))), '', 'txp-list-col-status') . ($show_authors ? td(span(txpspecialchars($RealName), array('title' => $AuthorID)), '', 'txp-list-col-author name') : '') . ($use_comments ? td($comments, '', 'txp-list-col-comments articles_detail') : ''));
        }
        echo n . tag_end('tbody') . n . tag_end('table') . n . tag_end('div') . list_multiedit_form($page, $sort, $dir, $crit, $search_method) . tInput() . n . tag_end('form') . n . tag_start('div', array('class' => 'txp-navigation', 'id' => $event . '_navigation')) . pageby_form('list', $article_list_pageby) . nav_form('list', $page, $numPages, $sort, $dir, $crit, $search_method, $total, $limit) . n . tag_end('div');
    }
    echo n . tag_end('div');
}
Example #8
0
function link_list($message = '')
{
    global $event, $step, $link_list_pageby, $txp_user;
    pagetop(gTxt('tab_link'), $message);
    extract(gpsa(array('page', 'sort', 'dir', 'crit', 'search_method')));
    if ($sort === '') {
        $sort = get_pref('link_sort_column', 'name');
    }
    if ($dir === '') {
        $dir = get_pref('link_sort_dir', 'asc');
    }
    $dir = $dir == 'desc' ? 'desc' : 'asc';
    switch ($sort) {
        case 'id':
            $sort_sql = 'id ' . $dir;
            break;
        case 'description':
            $sort_sql = 'description ' . $dir . ', id asc';
            break;
        case 'url':
            $sort_sql = 'url ' . $dir . ', id asc';
            break;
        case 'category':
            $sort_sql = 'category ' . $dir . ', id asc';
            break;
        case 'date':
            $sort_sql = 'date ' . $dir . ', id asc';
            break;
        case 'author':
            $sort_sql = 'author ' . $dir . ', id asc';
            break;
        default:
            $sort = 'name';
            $sort_sql = 'linksort ' . $dir . ', id asc';
            break;
    }
    set_pref('link_sort_column', $sort, 'link', 2, '', 0, PREF_PRIVATE);
    set_pref('link_sort_dir', $dir, 'link', 2, '', 0, PREF_PRIVATE);
    $switch_dir = $dir == 'desc' ? 'asc' : 'desc';
    $criteria = 1;
    if ($search_method and $crit != '') {
        $verbatim = preg_match('/^"(.*)"$/', $crit, $m);
        $crit_escaped = $verbatim ? doSlash($m[1]) : doLike($crit);
        $critsql = $verbatim ? array('id' => "ID in ('" . join("','", do_list($crit_escaped)) . "')", 'name' => "linkname = '{$crit_escaped}'", 'description' => "description = '{$crit_escaped}'", 'url' => "url = '{$crit_escaped}'", 'category' => "category = '{$crit_escaped}'", 'author' => "author = '{$crit_escaped}'") : array('id' => "ID in ('" . join("','", do_list($crit_escaped)) . "')", 'name' => "linkname like '%{$crit_escaped}%'", 'description' => "description like '%{$crit_escaped}%'", 'url' => "url like '%{$crit_escaped}%'", 'category' => "category like '%{$crit_escaped}%'", 'author' => "author like '%{$crit_escaped}%'");
        if (array_key_exists($search_method, $critsql)) {
            $criteria = $critsql[$search_method];
        } else {
            $search_method = '';
            $crit = '';
        }
    } else {
        $search_method = '';
        $crit = '';
    }
    $criteria .= callback_event('admin_criteria', 'link_list', 0, $criteria);
    $total = getCount('txp_link', $criteria);
    echo hed(gTxt('tab_link'), 1, array('class' => 'txp-heading'));
    echo n . '<div id="' . $event . '_control" class="txp-control-panel">';
    if (has_privs('link.edit')) {
        echo graf(sLink('link', 'link_edit', gTxt('add_new_link')), ' class="txp-buttons"');
    }
    if ($total < 1) {
        if ($criteria != 1) {
            echo link_search_form($crit, $search_method) . graf(gTxt('no_results_found'), ' class="indicator"') . '</div>';
        } else {
            echo graf(gTxt('no_links_recorded'), ' class="indicator"') . '</div>';
        }
        return;
    }
    $limit = max($link_list_pageby, 15);
    list($page, $offset, $numPages) = pager($total, $limit, $page);
    echo link_search_form($crit, $search_method) . '</div>';
    $rs = safe_rows_start('*, unix_timestamp(date) as uDate', 'txp_link', "{$criteria} order by {$sort_sql} limit {$offset}, {$limit}");
    if ($rs) {
        $show_authors = !has_single_author('txp_link');
        echo n . tag_start('div', array('id' => $event . '_container', 'class' => 'txp-container')) . n . tag_start('form', array('action' => 'index.php', 'id' => 'links_form', 'class' => 'multi_edit_form', 'method' => 'post', 'name' => 'longform')) . n . tag_start('div', array('class' => 'txp-listtables')) . n . tag_start('table', array('class' => 'txp-list')) . n . tag_start('thead') . tr(hCell(fInput('checkbox', 'select_all', 0, '', '', '', '', '', 'select_all'), '', ' scope="col" title="' . gTxt('toggle_all_selected') . '" class="txp-list-col-multi-edit"') . column_head('ID', 'id', 'link', true, $switch_dir, $crit, $search_method, ('id' == $sort ? "{$dir} " : '') . 'txp-list-col-id') . column_head('link_name', 'name', 'link', true, $switch_dir, $crit, $search_method, ('name' == $sort ? "{$dir} " : '') . 'txp-list-col-name') . column_head('description', 'description', 'link', true, $switch_dir, $crit, $search_method, ('description' == $sort ? "{$dir} " : '') . 'txp-list-col-description links_detail') . column_head('link_category', 'category', 'link', true, $switch_dir, $crit, $search_method, ('category' == $sort ? "{$dir} " : '') . 'txp-list-col-category category') . column_head('url', 'url', 'link', true, $switch_dir, $crit, $search_method, ('url' == $sort ? "{$dir} " : '') . 'txp-list-col-url') . column_head('date', 'date', 'link', true, $switch_dir, $crit, $search_method, ('date' == $sort ? "{$dir} " : '') . 'txp-list-col-created date links_detail') . ($show_authors ? column_head('author', 'author', 'link', true, $switch_dir, $crit, $search_method, ('author' == $sort ? "{$dir} " : '') . 'txp-list-col-author name') : '')) . n . tag_end('thead') . n . tag_start('tbody');
        $validator = new Validator();
        while ($a = nextRow($rs)) {
            extract($a, EXTR_PREFIX_ALL, 'link');
            $edit_url = array('event' => 'link', 'step' => 'link_edit', 'id' => $link_id, 'sort' => $sort, 'dir' => $dir, 'page' => $page, 'search_method' => $search_method, 'crit' => $crit);
            $validator->setConstraints(array(new CategoryConstraint($link_category, array('type' => 'link'))));
            $vc = $validator->validate() ? '' : ' error';
            $can_edit = has_privs('link.edit') || $link_author === $txp_user && has_privs('link.edit.own');
            $view_url = txpspecialchars($link_url);
            echo tr(td(fInput('checkbox', 'selected[]', $link_id), '', 'txp-list-col-multi-edit') . hCell($can_edit ? href($link_id, $edit_url, ' title="' . gTxt('edit') . '"') : $link_id, '', ' scope="row" class="txp-list-col-id"') . td($can_edit ? href(txpspecialchars($link_linkname), $edit_url, ' title="' . gTxt('edit') . '"') : txpspecialchars($link_linkname), '', 'txp-list-col-name') . td(txpspecialchars($link_description), '', 'txp-list-col-description links_detail') . td(span($link_category, array('title' => fetch_category_title($link_category, 'link'))), '', 'txp-list-col-category category' . $vc) . td(href($view_url, $view_url, ' rel="external" target="_blank"'), '', 'txp-list-col-url') . td(gTime($link_uDate), '', 'txp-list-col-created date links_detail') . ($show_authors ? td(span(txpspecialchars($link_author), array('title' => get_author_name($link_author))), '', 'txp-list-col-author name') : ''));
        }
        echo n . tag_end('tbody') . n . tag_end('table') . n . tag_end('div') . link_multiedit_form($page, $sort, $dir, $crit, $search_method) . tInput() . n . tag_end('form') . graf(toggle_box('links_detail'), array('class' => 'detail-toggle')) . n . tag_start('div', array('id' => $event . '_navigation', 'class' => 'txp-navigation')) . pageby_form('link', $link_list_pageby) . nav_form('link', $page, $numPages, $sort, $dir, $crit, $search_method, $total, $limit) . n . tag_end('div') . n . tag_end('div');
    }
}
Example #9
0
function image_list($message = '')
{
    global $txpcfg, $extensions, $img_dir, $file_max_upload_size, $image_list_pageby, $txp_user, $event;
    pagetop(gTxt('tab_image'), $message);
    extract($txpcfg);
    extract(gpsa(array('page', 'sort', 'dir', 'crit', 'search_method')));
    if ($sort === '') {
        $sort = get_pref('image_sort_column', 'id');
    }
    if ($dir === '') {
        $dir = get_pref('image_sort_dir', 'desc');
    }
    $dir = $dir == 'asc' ? 'asc' : 'desc';
    echo '<h1 class="txp-heading">' . gTxt('tab_image') . '</h1>';
    echo '<div id="' . $event . '_control" class="txp-control-panel">';
    if (!is_dir(IMPATH) or !is_writeable(IMPATH)) {
        echo graf(gTxt('img_dir_not_writeable', array('{imgdir}' => IMPATH)), ' class="alert-block warning"');
    } elseif (has_privs('image.edit.own')) {
        echo upload_form(gTxt('upload_image'), 'upload_image', 'image_insert', 'image', '', $file_max_upload_size);
    }
    switch ($sort) {
        case 'name':
            $sort_sql = 'name ' . $dir;
            break;
        case 'thumbnail':
            $sort_sql = 'thumbnail ' . $dir . ', id asc';
            break;
        case 'category':
            $sort_sql = 'category ' . $dir . ', id asc';
            break;
        case 'date':
            $sort_sql = 'date ' . $dir . ', id asc';
            break;
        case 'author':
            $sort_sql = 'author ' . $dir . ', id asc';
            break;
        default:
            $sort = 'id';
            $sort_sql = 'id ' . $dir;
            break;
    }
    set_pref('image_sort_column', $sort, 'image', 2, '', 0, PREF_PRIVATE);
    set_pref('image_sort_dir', $dir, 'image', 2, '', 0, PREF_PRIVATE);
    $switch_dir = $dir == 'desc' ? 'asc' : 'desc';
    $criteria = 1;
    if ($search_method and $crit != '') {
        $verbatim = preg_match('/^"(.*)"$/', $crit, $m);
        $crit_escaped = doSlash($verbatim ? $m[1] : str_replace(array('\\', '%', '_', '\''), array('\\\\', '\\%', '\\_', '\\\''), $crit));
        $critsql = $verbatim ? array('id' => "ID in ('" . join("','", do_list($crit_escaped)) . "')", 'name' => "name = '{$crit_escaped}'", 'category' => "category = '{$crit_escaped}'", 'author' => "author = '{$crit_escaped}'", 'alt' => "alt = '{$crit_escaped}'", 'caption' => "caption = '{$crit_escaped}'") : array('id' => "ID in ('" . join("','", do_list($crit_escaped)) . "')", 'name' => "name like '%{$crit_escaped}%'", 'category' => "category like '%{$crit_escaped}%'", 'author' => "author like '%{$crit_escaped}%'", 'alt' => "alt like '%{$crit_escaped}%'", 'caption' => "caption like '%{$crit_escaped}%'");
        if (array_key_exists($search_method, $critsql)) {
            $criteria = $critsql[$search_method];
            $limit = 500;
        } else {
            $search_method = '';
            $crit = '';
        }
    } else {
        $search_method = '';
        $crit = '';
    }
    $criteria .= callback_event('admin_criteria', 'image_list', 0, $criteria);
    $total = safe_count('txp_image', "{$criteria}");
    if ($total < 1) {
        if ($criteria != 1) {
            echo n . image_search_form($crit, $search_method) . n . graf(gTxt('no_results_found'), ' class="indicator"') . '</div>';
        } else {
            echo n . graf(gTxt('no_images_recorded'), ' class="indicator"') . '</div>';
        }
        return;
    }
    $limit = max($image_list_pageby, 15);
    list($page, $offset, $numPages) = pager($total, $limit, $page);
    echo image_search_form($crit, $search_method);
    $rs = safe_rows_start('*, unix_timestamp(date) as uDate', 'txp_image', "{$criteria} order by {$sort_sql} limit {$offset}, {$limit}\n\t\t");
    echo pluggable_ui('image_ui', 'extend_controls', '', $rs);
    echo '</div>';
    // end txp-control-panel
    if ($rs) {
        $show_authors = !has_single_author('txp_image');
        echo n . '<div id="' . $event . '_container" class="txp-container">';
        echo n . n . '<form name="longform" id="images_form" class="multi_edit_form" method="post" action="index.php">' . n . '<div class="txp-listtables">' . n . startTable('', '', 'txp-list') . n . '<thead>' . n . tr(n . hCell(fInput('checkbox', 'select_all', 0, '', '', '', '', '', 'select_all'), '', ' title="' . gTxt('toggle_all_selected') . '" class="multi-edit"') . n . column_head('ID', 'id', 'image', true, $switch_dir, $crit, $search_method, ('id' == $sort ? "{$dir} " : '') . 'id') . n . column_head('name', 'name', 'image', true, $switch_dir, $crit, $search_method, ('name' == $sort ? "{$dir} " : '') . 'name') . n . column_head('date', 'date', 'image', true, $switch_dir, $crit, $search_method, ('date' == $sort ? "{$dir} " : '') . 'images_detail date created') . n . column_head('thumbnail', 'thumbnail', 'image', true, $switch_dir, $crit, $search_method, ('thumbnail' == $sort ? "{$dir} " : '') . 'thumbnail') . n . hCell(gTxt('tags'), '', ' class="images_detail tag-build"') . n . column_head('image_category', 'category', 'image', true, $switch_dir, $crit, $search_method, ('category' == $sort ? "{$dir} " : '') . 'category') . ($show_authors ? n . column_head('author', 'author', 'image', true, $switch_dir, $crit, $search_method, ('author' == $sort ? "{$dir} " : '') . 'author') : '')) . n . '</thead>';
        echo '<tbody>';
        $validator = new Validator();
        while ($a = nextRow($rs)) {
            extract($a);
            $edit_url = '?event=image' . a . 'step=image_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') : txpspecialchars($name);
            if ($thumbnail) {
                if ($ext != '.swf') {
                    $thumbnail = '<img class="content-image" src="' . imagesrcurl($id, $ext, true) . "?{$uDate}" . '" alt="" ' . "title='{$id}{$ext} ({$w} &#215; {$h})'" . ($thumb_w ? " width='{$thumb_w}' height='{$thumb_h}'" : '') . ' />';
                } else {
                    $thumbnail = '';
                }
            } else {
                $thumbnail = gTxt('no');
            }
            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 = '<a target="_blank" href="' . $tag_url . a . 'type=textile" onclick="popWin(this.href); return false;">Textile</a>' . sp . '&#124;' . sp . '<a target="_blank" href="' . $tag_url . a . 'type=textpattern" onclick="popWin(this.href); return false;">Textpattern</a>' . sp . '&#124;' . sp . '<a target="_blank" href="' . $tag_url . a . 'type=html" onclick="popWin(this.href); return false;">HTML</a>';
            } else {
                $tagbuilder = sp;
            }
            $validator->setConstraints(array(new CategoryConstraint($category, array('type' => 'image'))));
            $vc = $validator->validate() ? '' : ' error';
            $category = $category ? '<span title="' . txpspecialchars(fetch_category_title($category, 'image')) . '">' . $category . '</span>' : '';
            $can_edit = has_privs('image.edit') || $author == $txp_user && has_privs('image.edit.own');
            echo n . n . tr(n . td($can_edit ? fInput('checkbox', 'selected[]', $id) : '&#160;', '', 'multi-edit') . n . td(($can_edit ? href($id, $edit_url, ' title="' . gTxt('edit') . '"') : $id) . sp . '<span class="images_detail">[<a href="' . imagesrcurl($id, $ext) . '">' . gTxt('view') . '</a>]</span>', '', 'id') . td($can_edit ? href($name, $edit_url, ' title="' . gTxt('edit') . '"') : $name, '', 'name') . td(gTime($uDate), '', 'images_detail date created') . td(pluggable_ui('image_ui', 'thumbnail', $can_edit ? href($thumbnail, $edit_url) : $thumbnail, $a), '', 'thumbnail') . td($tagbuilder, '', 'images_detail tag-build') . td($category, '', 'category' . $vc) . ($show_authors ? td('<span title="' . txpspecialchars(get_author_name($author)) . '">' . txpspecialchars($author) . '</span>', '', 'author') : ''));
        }
        echo '</tbody>', n, endTable(), n, '</div>', n, image_multiedit_form($page, $sort, $dir, $crit, $search_method), n, tInput(), n, '</form>', n, graf(toggle_box('images_detail'), ' class="detail-toggle"'), n, '<div id="' . $event . '_navigation" class="txp-navigation">', n, nav_form('image', $page, $numPages, $sort, $dir, $crit, $search_method, $total, $limit), n, pageby_form('image', $image_list_pageby), n, '</div>', n, '</div>';
    }
}
Example #10
0
/**
 * The main panel listing all images.
 *
 * @param string|array $message The activity message
 */
function image_list($message = '')
{
    global $txpcfg, $extensions, $img_dir, $file_max_upload_size, $image_list_pageby, $txp_user, $event;
    pagetop(gTxt('tab_image'), $message);
    extract($txpcfg);
    extract(gpsa(array('page', 'sort', 'dir', 'crit', 'search_method')));
    if ($sort === '') {
        $sort = get_pref('image_sort_column', 'id');
    } else {
        if (!in_array($sort, array('name', 'thumbnail', 'category', 'date', 'author'))) {
            $sort = 'id';
        }
        set_pref('image_sort_column', $sort, 'image', 2, '', 0, PREF_PRIVATE);
    }
    if ($dir === '') {
        $dir = get_pref('image_sort_dir', 'desc');
    } else {
        $dir = $dir == 'asc' ? "asc" : "desc";
        set_pref('image_sort_dir', $dir, 'image', 2, '', 0, PREF_PRIVATE);
    }
    switch ($sort) {
        case 'name':
            $sort_sql = "txp_image.name {$dir}";
            break;
        case 'thumbnail':
            $sort_sql = "txp_image.thumbnail {$dir}, txp_image.id ASC";
            break;
        case 'category':
            $sort_sql = "txp_category.title {$dir}, txp_image.id ASC";
            break;
        case 'date':
            $sort_sql = "txp_image.date {$dir}, txp_image.id ASC";
            break;
        case 'author':
            $sort_sql = "txp_users.RealName {$dir}, txp_image.id ASC";
            break;
        default:
            $sort = 'id';
            $sort_sql = "txp_image.id {$dir}";
            break;
    }
    $switch_dir = $dir == 'desc' ? 'asc' : 'desc';
    $search = new Filter($event, array('id' => array('column' => 'txp_image.id', 'label' => gTxt('ID'), 'type' => 'integer'), 'name' => array('column' => 'txp_image.name', 'label' => gTxt('name')), 'alt' => array('column' => 'txp_image.alt', 'label' => gTxt('alt_text')), 'caption' => array('column' => 'txp_image.caption', 'label' => gTxt('caption')), 'category' => array('column' => array('txp_image.category', 'txp_category.title'), 'label' => gTxt('image_category')), 'ext' => array('column' => 'txp_image.ext', 'label' => gTxt('extension')), 'author' => array('column' => array('txp_image.author', 'txp_users.RealName'), 'label' => gTxt('author')), 'thumbnail' => array('column' => array('txp_image.thumbnail'), 'label' => gTxt('thumbnail'), 'type' => 'boolean')));
    $alias_yes = '1, Yes';
    $alias_no = '0, No';
    $search->setAliases('thumbnail', array($alias_no, $alias_yes));
    list($criteria, $crit, $search_method) = $search->getFilter(array('id' => array('can_list' => true)));
    $search_render_options = array('placeholder' => 'search_images');
    $sql_from = safe_pfx_j('txp_image') . "\n        LEFT JOIN " . safe_pfx_j('txp_category') . " ON txp_category.name = txp_image.category AND txp_category.type = 'image'\n        LEFT JOIN " . safe_pfx_j('txp_users') . " ON txp_users.name = txp_image.author";
    if ($criteria === 1) {
        $total = getCount('txp_image', $criteria);
    } else {
        $total = getThing("SELECT COUNT(*) FROM {$sql_from} WHERE {$criteria}");
    }
    echo n . tag(hed(gTxt('tab_image'), 1, array('class' => 'txp-heading')), 'div', array('class' => 'txp-layout-2col-cell-1'));
    $searchBlock = n . tag($search->renderForm('image_list', $search_render_options), 'div', array('class' => 'txp-layout-2col-cell-2', 'id' => $event . '_control'));
    $createBlock = array();
    if (!is_dir(IMPATH) or !is_writeable(IMPATH)) {
        $createBlock[] = graf(span(null, array('class' => 'ui-icon ui-icon-alert')) . ' ' . gTxt('img_dir_not_writeable', array('{imgdir}' => IMPATH)), array('class' => 'alert-block warning'));
    } elseif (has_privs('image.edit.own')) {
        $createBlock[] = n . tag(n . upload_form('upload_image', 'upload_image', 'image_insert', 'image', '', $file_max_upload_size, '', '', ''), 'div', array('class' => 'txp-control-panel'));
    }
    $contentBlockStart = n . tag_start('div', array('class' => 'txp-layout-1col', 'id' => $event . '_container'));
    $createBlock = implode(n, $createBlock);
    if ($total < 1) {
        if ($criteria != 1) {
            echo $searchBlock . $contentBlockStart . $createBlock . graf(span(null, array('class' => 'ui-icon ui-icon-info')) . ' ' . gTxt('no_results_found'), array('class' => 'alert-block information'));
        } else {
            echo $contentBlockStart . $createBlock . graf(span(null, array('class' => 'ui-icon ui-icon-info')) . ' ' . gTxt('no_images_recorded'), array('class' => 'alert-block information'));
        }
        echo n . tag_end('div');
        return;
    }
    $limit = max($image_list_pageby, 15);
    list($page, $offset, $numPages) = pager($total, $limit, $page);
    echo $searchBlock . $contentBlockStart . $createBlock;
    $rs = safe_query("SELECT\n            txp_image.id,\n            txp_image.name,\n            txp_image.category,\n            txp_image.ext,\n            txp_image.w,\n            txp_image.h,\n            txp_image.alt,\n            txp_image.caption,\n            UNIX_TIMESTAMP(txp_image.date) AS uDate,\n            txp_image.author,\n            txp_image.thumbnail,\n            txp_image.thumb_w,\n            txp_image.thumb_h,\n            txp_users.RealName AS realname,\n            txp_category.Title AS category_title\n        FROM {$sql_from} WHERE {$criteria} ORDER BY {$sort_sql} LIMIT {$offset}, {$limit}");
    echo pluggable_ui('image_ui', 'extend_controls', '', $rs);
    if ($rs && numRows($rs)) {
        $show_authors = !has_single_author('txp_image');
        echo n . tag(toggle_box('images_detail'), 'div', array('class' => 'txp-list-options')) . n . tag_start('form', array('class' => 'multi_edit_form', 'id' => 'images_form', 'name' => 'longform', 'method' => 'post', 'action' => 'index.php')) . n . tag_start('div', array('class' => 'txp-listtables')) . n . tag_start('table', array('class' => 'txp-list')) . n . tag_start('thead') . tr(hCell(fInput('checkbox', 'select_all', 0, '', '', '', '', '', 'select_all'), '', ' class="txp-list-col-multi-edit" scope="col" title="' . gTxt('toggle_all_selected') . '"') . column_head('ID', 'id', 'image', true, $switch_dir, $crit, $search_method, ('id' == $sort ? "{$dir} " : '') . 'txp-list-col-id') . column_head('name', 'name', 'image', true, $switch_dir, $crit, $search_method, ('name' == $sort ? "{$dir} " : '') . 'txp-list-col-name') . column_head('date', 'date', 'image', true, $switch_dir, $crit, $search_method, ('date' == $sort ? "{$dir} " : '') . 'txp-list-col-created date images_detail') . column_head('thumbnail', 'thumbnail', 'image', true, $switch_dir, $crit, $search_method, ('thumbnail' == $sort ? "{$dir} " : '') . 'txp-list-col-thumbnail') . hCell(gTxt('tags'), '', ' class="txp-list-col-tag-build images_detail" scope="col"') . column_head('image_category', 'category', 'image', true, $switch_dir, $crit, $search_method, ('category' == $sort ? "{$dir} " : '') . 'txp-list-col-category category') . ($show_authors ? column_head('author', 'author', 'image', true, $switch_dir, $crit, $search_method, ('author' == $sort ? "{$dir} " : '') . 'txp-list-col-author name') : '')) . n . tag_end('thead') . n . tag_start('tbody');
        $validator = new Validator();
        while ($a = nextRow($rs)) {
            extract($a);
            $edit_url = array('event' => 'image', 'step' => 'image_edit', 'id' => $id, 'sort' => $sort, 'dir' => $dir, 'page' => $page, 'search_method' => $search_method, 'crit' => $crit);
            $name = empty($name) ? gTxt('unnamed') : txpspecialchars($name);
            if ($thumbnail) {
                if ($ext != '.swf') {
                    $thumbnail = '<img class="content-image" src="' . imagesrcurl($id, $ext, true) . "?{$uDate}" . '" alt="" ' . "title='{$id}{$ext} ({$w} &#215; {$h})'" . ($thumb_w ? " width='{$thumb_w}' height='{$thumb_h}'" : '') . ' />';
                } else {
                    $thumbnail = '';
                }
            } else {
                $thumbnail = gTxt('no');
            }
            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 = href('Textile', $tag_url . a . 'type=textile', ' target="_blank" onclick="popWin(this.href); return false;"') . sp . span('&#124;', array('role' => 'separator')) . sp . href('Textpattern', $tag_url . a . 'type=textpattern', ' target="_blank" onclick="popWin(this.href); return false;"') . sp . span('&#124;', array('role' => 'separator')) . sp . href('HTML', $tag_url . a . 'type=html', ' target="_blank" onclick="popWin(this.href); return false;"');
            } else {
                $tagbuilder = sp;
            }
            $validator->setConstraints(array(new CategoryConstraint($category, array('type' => 'image'))));
            $vc = $validator->validate() ? '' : ' error';
            if ($category) {
                $category = span(txpspecialchars($category_title), array('title' => $category));
            }
            $can_edit = has_privs('image.edit') || $author === $txp_user && has_privs('image.edit.own');
            echo tr(td($can_edit ? fInput('checkbox', 'selected[]', $id) : '&#160;', '', 'txp-list-col-multi-edit') . hCell(($can_edit ? href($id, $edit_url, array('title' => gTxt('edit'))) : $id) . sp . span(span('[', array('aria-hidden' => 'true')) . href(gTxt('view'), imagesrcurl($id, $ext)) . span(']', array('aria-hidden' => 'true')), array('class' => 'txp-option-link images_detail')), '', ' class="txp-list-col-id" scope="row"') . td($can_edit ? href($name, $edit_url, ' title="' . gTxt('edit') . '"') : $name, '', 'txp-list-col-name') . td(gTime($uDate), '', 'txp-list-col-created date images_detail') . td(pluggable_ui('image_ui', 'thumbnail', $can_edit ? href($thumbnail, $edit_url) : $thumbnail, $a), '', 'txp-list-col-thumbnail') . td($tagbuilder, '', 'txp-list-col-tag-build images_detail') . td($category, '', 'txp-list-col-category category' . $vc) . ($show_authors ? td(span(txpspecialchars($realname), array('title' => $author)), '', 'txp-list-col-author name') : ''));
        }
        echo n . tag_end('tbody') . n . tag_end('table') . n . tag_end('div') . image_multiedit_form($page, $sort, $dir, $crit, $search_method) . tInput() . n . tag_end('form') . n . tag_start('div', array('class' => 'txp-navigation', 'id' => $event . '_navigation')) . pageby_form('image', $image_list_pageby) . nav_form('image', $page, $numPages, $sort, $dir, $crit, $search_method, $total, $limit) . n . tag_end('div');
    }
}
Example #11
0
function ipban_list($message = '')
{
    global $event;
    pageTop(gTxt('list_banned_ips'), $message);
    echo hed(gTxt('banned_ips'), 1, array('class' => 'txp-heading'));
    echo n . '<div id="' . $event . '_banned_control" class="txp-control-panel">' . graf(sLink('discuss', 'discuss_list', gTxt('list_discussions')), ' class="txp-buttons"') . n . '</div>';
    $rs = safe_rows_start('*, unix_timestamp(date_banned) as uBanned', 'txp_discuss_ipban', "1 = 1 order by date_banned desc");
    if ($rs and numRows($rs) > 0) {
        echo n . tag_start('div', array('id' => $event . '_ban_container', 'class' => 'txp-container')) . n . tag_start('div', array('class' => 'txp-listtables')) . n . tag_start('table', array('class' => 'txp-list')) . n . tag_start('thead') . tr(hCell(gTxt('date_banned'), '', ' scope="col" class="txp-list-col-banned date"') . hCell(gTxt('IP'), '', ' scope="col" class="txp-list-col-ip"') . hCell(gTxt('name_used'), '', ' scope="col" class="txp-list-col-name"') . hCell(gTxt('banned_for'), '', ' scope="col" class="txp-list-col-id"')) . n . tag_end('thead') . n . tag_start('tbody');
        while ($a = nextRow($rs)) {
            extract($a);
            echo tr(hCell(gTime($uBanned), '', ' scope="row" class="txp-list-col-banned date"') . td(txpspecialchars($ip) . sp . span('[', array('aria-hidden' => 'true')) . href(gTxt('unban'), array('event' => 'discuss', 'step' => 'ipban_unban', 'ip' => $ip, '_txp_token' => form_token()), array('class' => 'action-ban')) . span(']', array('aria-hidden' => 'true')), '', 'txp-list-col-ip') . td(txpspecialchars($name_used), '', 'txp-list-col-name') . td(href($banned_on_message, '?event=discuss' . a . 'step=discuss_edit' . a . 'discussid=' . $banned_on_message), '', 'txp-list-col-id'));
        }
        echo n . tag_end('tbody') . n . tag_end('table') . n . tag_end('div') . n . tag_end('div');
    } else {
        echo graf(gTxt('no_ips_banned'), ' class="indicator"');
    }
}
Example #12
0
/**
 * The main panel listing all log hits.
 *
 * @param string|array $message The activity message
 */
function log_list($message = '')
{
    global $event, $log_list_pageby, $expire_logs_after;
    pagetop(gTxt('tab_logs'), $message);
    extract(gpsa(array('page', 'sort', 'dir', 'crit', 'search_method')));
    if ($sort === '') {
        $sort = get_pref('log_sort_column', 'time');
    }
    if ($dir === '') {
        $dir = get_pref('log_sort_dir', 'desc');
    }
    $dir = $dir == 'asc' ? 'asc' : 'desc';
    $expire_logs_after = assert_int($expire_logs_after);
    safe_delete('txp_log', "time < date_sub(now(), interval {$expire_logs_after} day)");
    switch ($sort) {
        case 'ip':
            $sort_sql = 'ip ' . $dir;
            break;
        case 'host':
            $sort_sql = 'host ' . $dir;
            break;
        case 'page':
            $sort_sql = 'page ' . $dir;
            break;
        case 'refer':
            $sort_sql = 'refer ' . $dir;
            break;
        case 'method':
            $sort_sql = 'method ' . $dir;
            break;
        case 'status':
            $sort_sql = 'status ' . $dir;
            break;
        default:
            $sort = 'time';
            $sort_sql = 'time ' . $dir;
            break;
    }
    set_pref('log_sort_column', $sort, 'log', 2, '', 0, PREF_PRIVATE);
    set_pref('log_sort_dir', $dir, 'log', 2, '', 0, PREF_PRIVATE);
    $switch_dir = $dir == 'desc' ? 'asc' : 'desc';
    $criteria = 1;
    if ($search_method and $crit != '') {
        $verbatim = preg_match('/^"(.*)"$/', $crit, $m);
        $crit_escaped = $verbatim ? doSlash($m[1]) : doLike($crit);
        $critsql = $verbatim ? array('ip' => "ip = '{$crit_escaped}'", 'host' => "host = '{$crit_escaped}'", 'page' => "page = '{$crit_escaped}'", 'refer' => "refer = '{$crit_escaped}'", 'method' => "method = '{$crit_escaped}'", 'status' => "status = '{$crit_escaped}'") : array('ip' => "ip like '%{$crit_escaped}%'", 'host' => "host like '%{$crit_escaped}%'", 'page' => "page like '%{$crit_escaped}%'", 'refer' => "refer like '%{$crit_escaped}%'", 'method' => "method like '%{$crit_escaped}%'", 'status' => "status like '%{$crit_escaped}%'");
        if (array_key_exists($search_method, $critsql)) {
            $criteria = $critsql[$search_method];
            $limit = 500;
        } else {
            $search_method = '';
            $crit = '';
        }
    } else {
        $search_method = '';
        $crit = '';
    }
    $criteria .= callback_event('admin_criteria', 'log_list', 0, $criteria);
    $total = safe_count('txp_log', "{$criteria}");
    echo hed(gTxt('tab_logs'), 1, array('class' => 'txp-heading'));
    echo n . '<div id="' . $event . '_control" class="txp-control-panel">';
    if ($total < 1) {
        if ($criteria != 1) {
            echo log_search_form($crit, $search_method) . graf(gTxt('no_results_found'), ' class="indicator"') . '</div>';
        } else {
            echo graf(gTxt('no_refers_recorded'), ' class="indicator"') . '</div>';
        }
        return;
    }
    $limit = max($log_list_pageby, 15);
    list($page, $offset, $numPages) = pager($total, $limit, $page);
    echo log_search_form($crit, $search_method) . '</div>';
    $rs = safe_rows_start('*, unix_timestamp(time) as uTime', 'txp_log', "{$criteria} order by {$sort_sql} limit {$offset}, {$limit}");
    if ($rs) {
        echo n . tag_start('div', array('id' => $event . '_container', 'class' => 'txp-container')) . n . tag_start('form', array('action' => 'index.php', 'id' => 'log_form', 'class' => 'multi_edit_form', 'method' => 'post', 'name' => 'longform')) . n . tag_start('div', array('class' => 'txp-listtables')) . n . tag_start('table', array('class' => 'txp-list')) . n . tag_start('thead') . tr(hCell(fInput('checkbox', 'select_all', 0, '', '', '', '', '', 'select_all'), '', ' scope="col" title="' . gTxt('toggle_all_selected') . '" class="txp-list-col-multi-edit"') . column_head('time', 'time', 'log', true, $switch_dir, $crit, $search_method, ('time' == $sort ? "{$dir} " : '') . 'txp-list-col-time') . column_head('IP', 'ip', 'log', true, $switch_dir, $crit, $search_method, ('ip' == $sort ? "{$dir} " : '') . 'txp-list-col-ip') . column_head('host', 'host', 'log', true, $switch_dir, $crit, $search_method, ('host' == $sort ? "{$dir} " : '') . 'txp-list-col-host log_detail') . column_head('page', 'page', 'log', true, $switch_dir, $crit, $search_method, ('page' == $sort ? "{$dir} " : '') . 'txp-list-col-page') . column_head('referrer', 'refer', 'log', true, $switch_dir, $crit, $search_method, ('refer' == $sort ? "{$dir} " : '') . 'txp-list-col-refer') . column_head('method', 'method', 'log', true, $switch_dir, $crit, $search_method, ('method' == $sort ? "{$dir} " : '') . 'txp-list-col-method log_detail') . column_head('status', 'status', 'log', true, $switch_dir, $crit, $search_method, ('status' == $sort ? "{$dir} " : '') . 'txp-list-col-status log_detail')) . n . tag_end('thead') . n . tag_start('tbody');
        while ($a = nextRow($rs)) {
            extract($a, EXTR_PREFIX_ALL, 'log');
            if ($log_refer) {
                $log_refer = href(txpspecialchars(soft_wrap(preg_replace('#^http://#', '', $log_refer), 30)), txpspecialchars($log_refer), ' target="_blank"');
            }
            if ($log_page) {
                $log_anchor = preg_replace('/\\/$/', '', $log_page);
                $log_anchor = soft_wrap(substr($log_anchor, 1), 30);
                $log_page = href(txpspecialchars($log_anchor), txpspecialchars($log_page), ' target="_blank"');
                if ($log_method == 'POST') {
                    $log_page = strong($log_page);
                }
            }
            echo tr(td(fInput('checkbox', 'selected[]', $log_id), '', 'txp-list-col-multi-edit') . hCell(gTime($log_uTime), '', ' scope="row" class="txp-list-col-time"') . td(href(txpspecialchars($log_ip), 'https://whois.domaintools.com/' . rawurlencode($log_ip), array('rel' => 'external', 'target' => '_blank')), '', 'txp-list-col-ip') . td(txpspecialchars($log_host), '', 'txp-list-col-host log_detail') . td($log_page, '', 'txp-list-col-page') . td($log_refer, '', 'txp-list-col-refer') . td(txpspecialchars($log_method), '', 'txp-list-col-method log_detail') . td($log_status, '', 'txp-list-col-status log_detail'));
        }
        echo n . tag_end('tbody') . n . tag_end('table') . n . tag_end('div') . log_multiedit_form($page, $sort, $dir, $crit, $search_method) . tInput() . n . tag_end('form') . graf(toggle_box('log_detail'), array('class' => 'detail-toggle')) . n . tag_start('div', array('id' => $event . '_navigation', 'class' => 'txp-navigation')) . pageby_form('log', $log_list_pageby) . nav_form('log', $page, $numPages, $sort, $dir, $crit, $search_method, $total, $limit) . n . tag_end('div') . n . tag_end('div');
    }
}
Example #13
0
/**
 * The main panel listing all links.
 *
 * @param string|array $message The activity message
 */
function link_list($message = '')
{
    global $event, $step, $link_list_pageby, $txp_user;
    pagetop(gTxt('tab_link'), $message);
    extract(gpsa(array('page', 'sort', 'dir', 'crit', 'search_method')));
    if ($sort === '') {
        $sort = get_pref('link_sort_column', 'name');
    } else {
        if (!in_array($sort, array('id', 'description', 'url', 'category', 'date', 'author'))) {
            $sort = 'name';
        }
        set_pref('link_sort_column', $sort, 'link', 2, '', 0, PREF_PRIVATE);
    }
    if ($dir === '') {
        $dir = get_pref('link_sort_dir', 'asc');
    } else {
        $dir = $dir == 'desc' ? "desc" : "asc";
        set_pref('link_sort_dir', $dir, 'link', 2, '', 0, PREF_PRIVATE);
    }
    switch ($sort) {
        case 'id':
            $sort_sql = "txp_link.id {$dir}";
            break;
        case 'description':
            $sort_sql = "txp_link.description {$dir}, txp_link.id ASC";
            break;
        case 'url':
            $sort_sql = "txp_link.url {$dir}, txp_link.id ASC";
            break;
        case 'category':
            $sort_sql = "txp_category.title {$dir}, txp_link.id ASC";
            break;
        case 'date':
            $sort_sql = "txp_link.date {$dir}, txp_link.id ASC";
            break;
        case 'author':
            $sort_sql = "txp_users.RealName {$dir}, txp_link.id ASC";
            break;
        default:
            $sort = 'name';
            $sort_sql = "txp_link.linksort {$dir}, txp_link.id ASC";
            break;
    }
    $switch_dir = $dir == 'desc' ? 'asc' : 'desc';
    $search = new Filter($event, array('id' => array('column' => 'txp_link.id', 'label' => gTxt('ID'), 'type' => 'integer'), 'name' => array('column' => 'txp_link.linkname', 'label' => gTxt('link_name')), 'url' => array('column' => 'txp_link.url', 'label' => gTxt('url')), 'description' => array('column' => 'txp_link.description', 'label' => gTxt('description')), 'category' => array('column' => array('txp_link.category', 'txp_category.title'), 'label' => gTxt('link_category')), 'author' => array('column' => array('txp_link.author', 'txp_users.RealName'), 'label' => gTxt('author')), 'linksort' => array('column' => 'txp_link.linksort', 'label' => gTxt('sort_value'))));
    list($criteria, $crit, $search_method) = $search->getFilter(array('id' => array('can_list' => true)));
    $search_render_options = array('placeholder' => 'search_links');
    $sql_from = safe_pfx_j('txp_link') . "\n        LEFT JOIN " . safe_pfx_j('txp_category') . " ON txp_category.name = txp_link.category AND txp_category.type = 'link'\n        LEFT JOIN " . safe_pfx_j('txp_users') . " ON txp_users.name = txp_link.author";
    if ($criteria === 1) {
        $total = safe_count('txp_link', $criteria);
    } else {
        $total = getThing("SELECT COUNT(*) FROM {$sql_from} WHERE {$criteria}");
    }
    echo n . tag(hed(gTxt('tab_link'), 1, array('class' => 'txp-heading')), 'div', array('class' => 'txp-layout-2col-cell-1'));
    $searchBlock = n . tag($search->renderForm('link_list', $search_render_options), 'div', array('class' => 'txp-layout-2col-cell-2', 'id' => $event . '_control'));
    $createBlock = array();
    if (has_privs('link.edit')) {
        $createBlock[] = n . tag(sLink('link', 'link_edit', gTxt('add_new_link'), 'txp-button'), 'div', array('class' => 'txp-control-panel'));
    }
    $contentBlockStart = n . tag_start('div', array('class' => 'txp-layout-1col', 'id' => $event . '_container'));
    $createBlock = implode(n, $createBlock);
    if ($total < 1) {
        if ($criteria != 1) {
            echo $searchBlock . $contentBlockStart . $createBlock . graf(span(null, array('class' => 'ui-icon ui-icon-info')) . ' ' . gTxt('no_results_found'), array('class' => 'alert-block information'));
        } else {
            echo $contentBlockStart . $createBlock . graf(span(null, array('class' => 'ui-icon ui-icon-info')) . ' ' . gTxt('no_links_recorded'), array('class' => 'alert-block information'));
        }
        echo n . tag_end('div');
        return;
    }
    $limit = max($link_list_pageby, 15);
    list($page, $offset, $numPages) = pager($total, $limit, $page);
    echo $searchBlock . $contentBlockStart . $createBlock;
    $rs = safe_query("SELECT\n            txp_link.id,\n            UNIX_TIMESTAMP(txp_link.date) AS uDate,\n            txp_link.category,\n            txp_link.url,\n            txp_link.linkname,\n            txp_link.description,\n            txp_link.author,\n            txp_users.RealName AS realname,\n            txp_category.Title AS category_title\n        FROM {$sql_from} WHERE {$criteria} ORDER BY {$sort_sql} LIMIT {$offset}, {$limit}");
    if ($rs && numRows($rs)) {
        $show_authors = !has_single_author('txp_link');
        echo n . tag(toggle_box('links_detail'), 'div', array('class' => 'txp-list-options')) . n . tag_start('form', array('class' => 'multi_edit_form', 'id' => 'links_form', 'name' => 'longform', 'method' => 'post', 'action' => 'index.php')) . n . tag_start('div', array('class' => 'txp-listtables')) . n . tag_start('table', array('class' => 'txp-list')) . n . tag_start('thead') . tr(hCell(fInput('checkbox', 'select_all', 0, '', '', '', '', '', 'select_all'), '', ' class="txp-list-col-multi-edit" scope="col" title="' . gTxt('toggle_all_selected') . '"') . column_head('ID', 'id', 'link', true, $switch_dir, $crit, $search_method, ('id' == $sort ? "{$dir} " : '') . 'txp-list-col-id') . column_head('link_name', 'name', 'link', true, $switch_dir, $crit, $search_method, ('name' == $sort ? "{$dir} " : '') . 'txp-list-col-name') . column_head('description', 'description', 'link', true, $switch_dir, $crit, $search_method, ('description' == $sort ? "{$dir} " : '') . 'txp-list-col-description links_detail') . column_head('link_category', 'category', 'link', true, $switch_dir, $crit, $search_method, ('category' == $sort ? "{$dir} " : '') . 'txp-list-col-category category') . column_head('url', 'url', 'link', true, $switch_dir, $crit, $search_method, ('url' == $sort ? "{$dir} " : '') . 'txp-list-col-url') . column_head('date', 'date', 'link', true, $switch_dir, $crit, $search_method, ('date' == $sort ? "{$dir} " : '') . 'txp-list-col-created date links_detail') . ($show_authors ? column_head('author', 'author', 'link', true, $switch_dir, $crit, $search_method, ('author' == $sort ? "{$dir} " : '') . 'txp-list-col-author name') : '')) . n . tag_end('thead') . n . tag_start('tbody');
        $validator = new Validator();
        while ($a = nextRow($rs)) {
            extract($a, EXTR_PREFIX_ALL, 'link');
            $edit_url = array('event' => 'link', 'step' => 'link_edit', 'id' => $link_id, 'sort' => $sort, 'dir' => $dir, 'page' => $page, 'search_method' => $search_method, 'crit' => $crit);
            $validator->setConstraints(array(new CategoryConstraint($link_category, array('type' => 'link'))));
            $vc = $validator->validate() ? '' : ' error';
            if ($link_category) {
                $link_category = span(txpspecialchars($link_category_title), array('title' => $link_category));
            }
            $can_edit = has_privs('link.edit') || $link_author === $txp_user && has_privs('link.edit.own');
            $view_url = txpspecialchars($link_url);
            echo tr(td(fInput('checkbox', 'selected[]', $link_id), '', 'txp-list-col-multi-edit') . hCell($can_edit ? href($link_id, $edit_url, ' title="' . gTxt('edit') . '"') : $link_id, '', ' class="txp-list-col-id" scope="row"') . td($can_edit ? href(txpspecialchars($link_linkname), $edit_url, ' title="' . gTxt('edit') . '"') : txpspecialchars($link_linkname), '', 'txp-list-col-name') . td(txpspecialchars($link_description), '', 'txp-list-col-description links_detail') . td($link_category, '', 'txp-list-col-category category' . $vc) . td(href($view_url, $view_url, ' rel="external" target="_blank"'), '', 'txp-list-col-url') . td(gTime($link_uDate), '', 'txp-list-col-created date links_detail') . ($show_authors ? td(span(txpspecialchars($link_realname), array('title' => $link_author)), '', 'txp-list-col-author name') : ''));
        }
        echo n . tag_end('tbody') . n . tag_end('table') . n . tag_end('div') . link_multiedit_form($page, $sort, $dir, $crit, $search_method) . tInput() . n . tag_end('form') . n . tag_start('div', array('class' => 'txp-navigation', 'id' => $event . '_navigation')) . pageby_form('link', $link_list_pageby) . nav_form('link', $page, $numPages, $sort, $dir, $crit, $search_method, $total, $limit) . n . tag_end('div');
    }
    echo n . tag_end('div');
}
Example #14
0
/**
 * Outputs the main panel listing all comments.
 *
 * @param  string|array $message The activity message
 */
function discuss_list($message = '')
{
    global $event, $comment_list_pageby;
    pagetop(gTxt('list_discussions'), $message);
    extract(gpsa(array('sort', 'dir', 'page', 'crit', 'search_method')));
    if ($sort === '') {
        $sort = get_pref('discuss_sort_column', 'date');
    } else {
        if (!in_array($sort, array('id', 'ip', 'name', 'email', 'website', 'message', 'status', 'parent'))) {
            $sort = 'date';
        }
        set_pref('discuss_sort_column', $sort, 'discuss', 2, '', 0, PREF_PRIVATE);
    }
    if ($dir === '') {
        $dir = get_pref('discuss_sort_dir', 'desc');
    } else {
        $dir = $dir == 'asc' ? "asc" : "desc";
        set_pref('discuss_sort_dir', $dir, 'discuss', 2, '', 0, PREF_PRIVATE);
    }
    switch ($sort) {
        case 'id':
            $sort_sql = "txp_discuss.discussid {$dir}";
            break;
        case 'ip':
            $sort_sql = "txp_discuss.ip {$dir}";
            break;
        case 'name':
            $sort_sql = "txp_discuss.name {$dir}";
            break;
        case 'email':
            $sort_sql = "txp_discuss.email {$dir}";
            break;
        case 'website':
            $sort_sql = "txp_discuss.web {$dir}";
            break;
        case 'message':
            $sort_sql = "txp_discuss.message {$dir}";
            break;
        case 'status':
            $sort_sql = "txp_discuss.visible {$dir}";
            break;
        case 'parent':
            $sort_sql = "txp_discuss.parentid {$dir}";
            break;
        default:
            $sort = 'date';
            $sort_sql = "txp_discuss.posted {$dir}";
            break;
    }
    if ($sort != 'date') {
        $sort_sql .= ", txp_discuss.posted ASC";
    }
    $switch_dir = $dir == 'desc' ? 'asc' : 'desc';
    $search = new Filter($event, array('id' => array('column' => 'txp_discuss.discussid', 'label' => gTxt('ID'), 'type' => 'integer'), 'parent' => array('column' => array('txp_discuss.parentid', 'textpattern.Title'), 'label' => gTxt('parent')), 'name' => array('column' => 'txp_discuss.name', 'label' => gTxt('name')), 'message' => array('column' => 'txp_discuss.message', 'label' => gTxt('message')), 'email' => array('column' => 'txp_discuss.email', 'label' => gTxt('email')), 'website' => array('column' => 'txp_discuss.web', 'label' => gTxt('website')), 'ip' => array('column' => 'txp_discuss.ip', 'label' => gTxt('IP')), 'visible' => array('column' => 'txp_discuss.visible', 'label' => gTxt('visible'), 'type' => 'numeric')));
    $alias_yes = VISIBLE . ', Yes';
    $alias_no = MODERATE . ', No, Unmoderated, Pending';
    $alias_spam = SPAM . ', Spam';
    $search->setAliases('visible', array(VISIBLE => $alias_yes, MODERATE => $alias_no, SPAM => $alias_spam));
    list($criteria, $crit, $search_method) = $search->getFilter(array('id' => array('can_list' => true)));
    $search_render_options = array('placeholder' => 'search_comments');
    $sql_from = safe_pfx_j('txp_discuss') . "\n        left join " . safe_pfx_j('textpattern') . " on txp_discuss.parentid = textpattern.ID";
    $counts = getRows("SELECT txp_discuss.visible, COUNT(*) AS c\n        FROM " . safe_pfx_j('txp_discuss') . "\n            LEFT JOIN " . safe_pfx_j('textpattern') . "\n            ON txp_discuss.parentid = textpattern.ID\n        WHERE {$criteria} GROUP BY txp_discuss.visible");
    $count[SPAM] = $count[MODERATE] = $count[VISIBLE] = 0;
    if ($counts) {
        foreach ($counts as $c) {
            $count[$c['visible']] = $c['c'];
        }
    }
    // Grand total comment count.
    $total = $count[SPAM] + $count[MODERATE] + $count[VISIBLE];
    echo n . tag(hed(gTxt('list_discussions'), 1, array('class' => 'txp-heading')), 'div', array('class' => 'txp-layout-2col-cell-1'));
    $searchBlock = n . tag($search->renderForm('discuss_list', $search_render_options), 'div', array('class' => 'txp-layout-2col-cell-2', 'id' => $event . '_control'));
    $contentBlockStart = n . tag_start('div', array('class' => 'txp-layout-1col', 'id' => $event . '_container'));
    if ($total < 1) {
        if ($criteria != 1) {
            echo $searchBlock . $contentBlockStart . graf(span(null, array('class' => 'ui-icon ui-icon-info')) . ' ' . gTxt('no_results_found'), array('class' => 'alert-block information'));
        } else {
            echo $contentBlockStart . graf(span(null, array('class' => 'ui-icon ui-icon-info')) . ' ' . gTxt('no_comments_recorded'), array('class' => 'alert-block information'));
        }
        echo n . tag_end('div');
        return;
    }
    if (!cs('toggle_show_spam')) {
        $total = $count[MODERATE] + $count[VISIBLE];
        $criteria = 'visible != ' . intval(SPAM) . ' and ' . $criteria;
    }
    $limit = max($comment_list_pageby, 15);
    list($page, $offset, $numPages) = pager($total, $limit, $page);
    echo $searchBlock . $contentBlockStart;
    $rs = safe_query("SELECT\n            txp_discuss.discussid,\n            txp_discuss.parentid,\n            txp_discuss.name,\n            txp_discuss.email,\n            txp_discuss.web,\n            txp_discuss.ip,\n            txp_discuss.message,\n            txp_discuss.visible,\n            UNIX_TIMESTAMP(txp_discuss.posted) AS uPosted,\n            textpattern.ID AS thisid,\n            textpattern.Section AS section,\n            textpattern.url_title,\n            textpattern.Title AS title,\n            textpattern.Status,\n            UNIX_TIMESTAMP(textpattern.Posted) AS posted\n        FROM " . safe_pfx_j('txp_discuss') . "\n            LEFT JOIN " . safe_pfx_j('textpattern') . " ON txp_discuss.parentid = textpattern.ID\n        WHERE {$criteria} ORDER BY {$sort_sql} LIMIT {$offset}, {$limit}");
    if ($rs) {
        echo n . tag(cookie_box('show_spam') . toggle_box('discuss_detail'), 'div', array('class' => 'txp-list-options')) . n . tag_start('form', array('class' => 'multi_edit_form', 'id' => 'discuss_form', 'name' => 'longform', 'method' => 'post', 'action' => 'index.php')) . n . tag_start('div', array('class' => 'txp-listtables')) . n . tag_start('table', array('class' => 'txp-list')) . n . tag_start('thead') . tr(hCell(fInput('checkbox', 'select_all', 0, '', '', '', '', '', 'select_all'), '', ' class="txp-list-col-multi-edit" scope="col" title="' . gTxt('toggle_all_selected') . '"') . column_head('ID', 'id', 'discuss', true, $switch_dir, $crit, $search_method, ('id' == $sort ? "{$dir} " : '') . 'txp-list-col-id') . column_head('date', 'date', 'discuss', true, $switch_dir, $crit, $search_method, ('date' == $sort ? "{$dir} " : '') . 'txp-list-col-created date') . column_head('name', 'name', 'discuss', true, $switch_dir, $crit, $search_method, ('name' == $sort ? "{$dir} " : '') . 'txp-list-col-name') . column_head('message', 'message', 'discuss', true, $switch_dir, $crit, $search_method, 'message' == $sort ? "{$dir} " : 'txp-list-col-message') . column_head('email', 'email', 'discuss', true, $switch_dir, $crit, $search_method, ('email' == $sort ? "{$dir} " : '') . 'txp-list-col-email discuss_detail') . column_head('website', 'website', 'discuss', true, $switch_dir, $crit, $search_method, ('website' == $sort ? "{$dir} " : '') . 'txp-list-col-website discuss_detail') . column_head('IP', 'ip', 'discuss', true, $switch_dir, $crit, $search_method, ('ip' == $sort ? "{$dir} " : '') . 'txp-list-col-ip discuss_detail') . column_head('status', 'status', 'discuss', true, $switch_dir, $crit, $search_method, ('status' == $sort ? "{$dir} " : '') . 'txp-list-col-status') . column_head('parent', 'parent', 'discuss', true, $switch_dir, $crit, $search_method, ('parent' == $sort ? "{$dir} " : '') . 'txp-list-col-parent')) . n . tag_end('thead');
        include_once txpath . '/publish/taghandlers.php';
        echo n . tag_start('tbody');
        while ($a = nextRow($rs)) {
            extract($a);
            $parentid = assert_int($parentid);
            $edit_url = array('event' => 'discuss', 'step' => 'discuss_edit', 'discussid' => $discussid, 'sort' => $sort, 'dir' => $dir, 'page' => $page, 'search_method' => $search_method, 'crit' => $crit);
            $dmessage = $visible == SPAM ? short_preview($message) : $message;
            switch ($visible) {
                case VISIBLE:
                    $comment_status = gTxt('visible');
                    $row_class = 'visible';
                    break;
                case SPAM:
                    $comment_status = gTxt('spam');
                    $row_class = 'spam';
                    break;
                case MODERATE:
                    $comment_status = gTxt('unmoderated');
                    $row_class = 'moderate';
                    break;
                default:
                    break;
            }
            if (empty($thisid)) {
                $parent = gTxt('article_deleted') . ' (' . $parentid . ')';
                $view = '';
            } else {
                $parent_title = empty($title) ? '<em>' . gTxt('untitled') . '</em>' : escape_title($title);
                $parent = href($parent_title, '?event=article' . a . 'step=edit' . a . 'ID=' . $parentid);
                $view = $comment_status;
                if ($visible == VISIBLE and in_array($Status, array(4, 5))) {
                    $view = href($comment_status, permlinkurl($a) . '#c' . $discussid, ' title="' . gTxt('view') . '"');
                }
            }
            echo tr(td(fInput('checkbox', 'selected[]', $discussid), '', 'txp-list-col-multi-edit') . hCell(href($discussid, $edit_url, ' title="' . gTxt('edit') . '"'), '', ' class="txp-list-col-id" scope="row"') . td(gTime($uPosted), '', 'txp-list-col-created date') . td(txpspecialchars(soft_wrap($name, 15)), '', 'txp-list-col-name') . td(short_preview($dmessage), '', 'txp-list-col-message') . td(txpspecialchars(soft_wrap($email, 15)), '', 'txp-list-col-email discuss_detail') . td(txpspecialchars(soft_wrap($web, 15)), '', 'txp-list-col-website discuss_detail') . td(href(txpspecialchars($ip), 'https://whois.domaintools.com/' . rawurlencode($ip), array('rel' => 'external', 'target' => '_blank')), '', 'txp-list-col-ip discuss_detail') . td($view, '', 'txp-list-col-status') . td($parent, '', 'txp-list-col-parent'), ' class="' . $row_class . '"');
        }
        if (empty($message)) {
            echo n . tr(tda(gTxt('just_spam_results_found'), ' colspan="10"'));
        }
        echo n . tag_end('tbody') . n . tag_end('table') . n . tag_end('div') . discuss_multiedit_form($page, $sort, $dir, $crit, $search_method) . tInput() . n . tag_end('form') . n . tag_start('div', array('class' => 'txp-navigation', 'id' => $event . '_navigation')) . pageby_form('discuss', $comment_list_pageby) . nav_form('discuss', $page, $numPages, $sort, $dir, $crit, $search_method, $total, $limit) . n . tag_end('div');
    }
    echo n . tag_end('div');
}
Example #15
0
function log_list($message = '')
{
    pagetop(gTxt('visitor_logs'), $message);
    extract(get_prefs());
    extract(gpsa(array('page', 'sort', 'dir', 'crit', 'search_method')));
    $expire_logs_after = assert_int($expire_logs_after);
    safe_delete('txp_log', "time < date_sub(now(), interval {$expire_logs_after} day)");
    $dir = $dir == 'asc' ? 'asc' : 'desc';
    switch ($sort) {
        case 'ip':
            $sort_sql = 'ip ' . $dir;
            break;
        case 'host':
            $sort_sql = 'host ' . $dir;
            break;
        case 'page':
            $sort_sql = 'page ' . $dir;
            break;
        case 'refer':
            $sort_sql = 'refer ' . $dir;
            break;
        case 'method':
            $sort_sql = 'method ' . $dir;
            break;
        case 'status':
            $sort_sql = 'status ' . $dir;
            break;
        default:
            $sort = 'time';
            $sort_sql = 'time ' . $dir;
            break;
    }
    $switch_dir = $dir == 'desc' ? 'asc' : 'desc';
    $criteria = 1;
    if ($search_method and $crit) {
        $crit_escaped = doSlash($crit);
        $critsql = array('ip' => "ip like '%{$crit_escaped}%'", 'host' => "host like '%{$crit_escaped}%'", 'page' => "page like '%{$crit_escaped}%'", 'refer' => "refer like '%{$crit_escaped}%'", 'method' => "method like '%{$crit_escaped}%'", 'status' => "status like '%{$crit_escaped}%'");
        if (array_key_exists($search_method, $critsql)) {
            $criteria = $critsql[$search_method];
            $limit = 500;
        } else {
            $search_method = '';
            $crit = '';
        }
    } else {
        $search_method = '';
        $crit = '';
    }
    $total = safe_count('txp_log', "{$criteria}");
    if ($total < 1) {
        if ($criteria != 1) {
            echo n . log_search_form($crit, $search_method) . n . graf(gTxt('no_results_found'), ' style="text-align: center;"');
        } else {
            echo graf(gTxt('no_refers_recorded'), ' style="text-align: center;"');
        }
        return;
    }
    $limit = max(@$log_list_pageby, 15);
    list($page, $offset, $numPages) = pager($total, $limit, $page);
    echo n . log_search_form($crit, $search_method);
    $rs = safe_rows_start('*, unix_timestamp(time) as uTime', 'txp_log', "{$criteria} order by {$sort_sql} limit {$offset}, {$limit}");
    if ($rs) {
        echo n . n . '<form action="index.php" method="post" name="longform" onsubmit="return verify(\'' . gTxt('are_you_sure') . '\')">' . startTable('list', '', '', '', '90%') . n . tr(n . column_head('time', 'time', 'log', true, $switch_dir, $crit, $search_method, 'time' == $sort ? $dir : '') . column_head('IP', 'ip', 'log', true, $switch_dir, $crit, $search_method, ('ip' == $sort ? "{$dir} " : '') . 'log_detail') . column_head('host', 'host', 'log', true, $switch_dir, $crit, $search_method, 'host' == $sort ? $dir : '') . column_head('page', 'page', 'log', true, $switch_dir, $crit, $search_method, 'page' == $sort ? $dir : '') . column_head('referrer', 'refer', 'log', true, $switch_dir, $crit, $search_method, 'refer' == $sort ? $dir : '') . column_head('method', 'method', 'log', true, $switch_dir, $crit, $search_method, ('method' == $sort ? "{$dir} " : '') . 'log_detail') . column_head('status', 'status', 'log', true, $switch_dir, $crit, $search_method, ('status' == $sort ? "{$dir} " : '') . 'log_detail') . hCell());
        while ($a = nextRow($rs)) {
            extract($a, EXTR_PREFIX_ALL, 'log');
            if ($log_refer) {
                $log_refer = htmlspecialchars('http://' . $log_refer);
                $log_refer = '<a href="' . $log_refer . '" target="_blank">' . soft_wrap($log_refer, 30) . '</a>';
            }
            if ($log_page) {
                $log_page = htmlspecialchars($log_page);
                $log_page = '<a href="' . $log_page . '" target="_blank">' . soft_wrap(preg_replace('/\\/$/', '', substr($log_page, 1)), 30) . '</a>';
                if ($log_method == 'POST') {
                    $log_page = '<strong>' . $log_page . '</strong>';
                }
            }
            echo tr(n . td(gTime($log_uTime), 85) . td($log_ip, 20, 'log_detail') . td(soft_wrap($log_host, 30)) . td($log_page) . td($log_refer) . td($log_method, 60, 'log_detail') . td($log_status, 60, 'log_detail') . td(fInput('checkbox', 'selected[]', $log_id)));
        }
        echo n . n . tr(tda(toggle_box('log_detail'), ' colspan="2" style="text-align: left; border: none;"') . tda(select_buttons() . log_multiedit_form($page, $sort, $dir, $crit, $search_method), ' colspan="6" style="text-align: right; border: none;"')) . n . endTable() . '</form>' . n . nav_form('log', $page, $numPages, $sort, $dir, $crit, $search_method) . n . pageby_form('log', $log_list_pageby);
    }
}
Example #16
0
function list_list($message = '', $post = '')
{
    global $statuses, $comments_disabled_after, $step, $txp_user, $article_list_pageby, $event;
    pagetop(gTxt('tab_list'), $message);
    extract(gpsa(array('page', 'sort', 'dir', 'crit', 'search_method')));
    if ($sort === '') {
        $sort = get_pref('article_sort_column', 'posted');
    }
    if ($dir === '') {
        $dir = get_pref('article_sort_dir', 'desc');
    }
    $dir = $dir == 'asc' ? 'asc' : 'desc';
    $sesutats = array_flip($statuses);
    switch ($sort) {
        case 'id':
            $sort_sql = 'ID ' . $dir;
            break;
        case 'title':
            $sort_sql = 'Title ' . $dir . ', Posted desc';
            break;
        case 'expires':
            $sort_sql = 'Expires ' . $dir;
            break;
        case 'section':
            $sort_sql = 'Section ' . $dir . ', Posted desc';
            break;
        case 'category1':
            $sort_sql = 'Category1 ' . $dir . ', Posted desc';
            break;
        case 'category2':
            $sort_sql = 'Category2 ' . $dir . ', Posted desc';
            break;
        case 'status':
            $sort_sql = 'Status ' . $dir . ', Posted desc';
            break;
        case 'author':
            $sort_sql = 'AuthorID ' . $dir . ', Posted desc';
            break;
        case 'comments':
            $sort_sql = 'comments_count ' . $dir . ', Posted desc';
            break;
        case 'lastmod':
            $sort_sql = 'LastMod ' . $dir . ', Posted desc';
            break;
        default:
            $sort = 'posted';
            $sort_sql = 'Posted ' . $dir;
            break;
    }
    set_pref('article_sort_column', $sort, 'list', 2, '', 0, PREF_PRIVATE);
    set_pref('article_sort_dir', $dir, 'list', 2, '', 0, PREF_PRIVATE);
    $switch_dir = $dir == 'desc' ? 'asc' : 'desc';
    $criteria = 1;
    if ($search_method and $crit != '') {
        $verbatim = preg_match('/^"(.*)"$/', $crit, $m);
        $crit_escaped = doSlash($verbatim ? $m[1] : str_replace(array('\\', '%', '_', '\''), array('\\\\', '\\%', '\\_', '\\\''), $crit));
        $critsql = $verbatim ? array('id' => "ID in ('" . join("','", do_list($crit_escaped)) . "')", 'title_body_excerpt' => "Title = '{$crit_escaped}' or Body = '{$crit_escaped}' or Excerpt = '{$crit_escaped}'", 'section' => "Section = '{$crit_escaped}'", 'keywords' => "FIND_IN_SET('" . $crit_escaped . "',Keywords)", 'categories' => "Category1 = '{$crit_escaped}' or Category2 = '{$crit_escaped}'", 'status' => "Status = '" . @$sesutats[gTxt($crit_escaped)] . "'", 'author' => "AuthorID = '{$crit_escaped}'", 'article_image' => "Image in ('" . join("','", do_list($crit_escaped)) . "')", 'posted' => "Posted = '{$crit_escaped}'", 'lastmod' => "LastMod = '{$crit_escaped}'") : array('id' => "ID in ('" . join("','", do_list($crit_escaped)) . "')", 'title_body_excerpt' => "Title like '%{$crit_escaped}%' or Body like '%{$crit_escaped}%' or Excerpt like '%{$crit_escaped}%'", 'section' => "Section like '%{$crit_escaped}%'", 'keywords' => "FIND_IN_SET('" . $crit_escaped . "',Keywords)", 'categories' => "Category1 like '%{$crit_escaped}%' or Category2 like '%{$crit_escaped}%'", 'status' => "Status = '" . @$sesutats[gTxt($crit_escaped)] . "'", 'author' => "AuthorID like '%{$crit_escaped}%'", 'article_image' => "Image in ('" . join("','", do_list($crit_escaped)) . "')", 'posted' => "Posted like '{$crit_escaped}%'", 'lastmod' => "LastMod like '{$crit_escaped}%'");
        if (array_key_exists($search_method, $critsql)) {
            $criteria = $critsql[$search_method];
            $limit = 500;
        } else {
            $search_method = '';
            $crit = '';
        }
    } else {
        $search_method = '';
        $crit = '';
    }
    $criteria .= callback_event('admin_criteria', 'list_list', 0, $criteria);
    $total = safe_count('textpattern', "{$criteria}");
    echo '<h1 class="txp-heading">' . gTxt('tab_list') . '</h1>';
    echo '<div id="' . $event . '_control" class="txp-control-panel">';
    if ($total < 1) {
        if ($criteria != 1) {
            echo n . list_search_form($crit, $search_method) . n . graf(gTxt('no_results_found'), ' class="indicator"') . '</div>';
        } else {
            echo graf(gTxt('no_articles_recorded'), ' class="indicator"') . '</div>';
        }
        return;
    }
    $limit = max($article_list_pageby, 15);
    list($page, $offset, $numPages) = pager($total, $limit, $page);
    echo n . list_search_form($crit, $search_method) . '</div>';
    $rs = safe_rows_start('*, unix_timestamp(Posted) as posted, unix_timestamp(LastMod) as lastmod, unix_timestamp(Expires) as expires', 'textpattern', "{$criteria} order by {$sort_sql} limit {$offset}, {$limit}");
    if ($rs) {
        $show_authors = !has_single_author('textpattern', 'AuthorID');
        $total_comments = array();
        // fetch true comment count, not the public comment count
        // maybe we should have another row in the db?
        $rs2 = safe_rows_start('parentid, count(*) as num', 'txp_discuss', "1 group by parentid order by parentid");
        if ($rs2) {
            while ($a = nextRow($rs2)) {
                $pid = $a['parentid'];
                $num = $a['num'];
                $total_comments[$pid] = $num;
            }
        }
        echo n . '<div id="' . $event . '_container" class="txp-container">';
        echo n . n . '<form name="longform" id="articles_form" class="multi_edit_form" method="post" action="index.php">' . n . '<div class="txp-listtables">' . n . startTable('', '', 'txp-list') . n . '<thead>' . n . tr(n . hCell(fInput('checkbox', 'select_all', 0, '', '', '', '', '', 'select_all'), '', ' title="' . gTxt('toggle_all_selected') . '" class="multi-edit"') . n . column_head('ID', 'id', 'list', true, $switch_dir, $crit, $search_method, ('id' == $sort ? "{$dir} " : '') . 'id actions') . column_head('title', 'title', 'list', true, $switch_dir, $crit, $search_method, ('title' == $sort ? "{$dir} " : '') . 'title') . column_head('posted', 'posted', 'list', true, $switch_dir, $crit, $search_method, ('posted' == $sort ? "{$dir} " : '') . 'date posted created') . column_head('article_modified', 'lastmod', 'list', true, $switch_dir, $crit, $search_method, ('lastmod' == $sort ? "{$dir} " : '') . 'articles_detail date modified') . column_head('expires', 'expires', 'list', true, $switch_dir, $crit, $search_method, ('expires' == $sort ? "{$dir} " : '') . 'articles_detail date expires') . column_head('section', 'section', 'list', true, $switch_dir, $crit, $search_method, ('section' == $sort ? "{$dir} " : '') . 'section') . column_head('category1', 'category1', 'list', true, $switch_dir, $crit, $search_method, ('category1' == $sort ? "{$dir} " : '') . 'articles_detail category category1') . column_head('category2', 'category2', 'list', true, $switch_dir, $crit, $search_method, ('category2' == $sort ? "{$dir} " : '') . 'articles_detail category category2') . column_head('status', 'status', 'list', true, $switch_dir, $crit, $search_method, ('status' == $sort ? "{$dir} " : '') . 'status') . ($show_authors ? column_head('author', 'author', 'list', true, $switch_dir, $crit, $search_method, ('author' == $sort ? "{$dir} " : '') . 'author') : '') . column_head('comments', 'comments', 'list', true, $switch_dir, $crit, $search_method, ('comments' == $sort ? "{$dir} " : '') . 'articles_detail comments')) . n . '</thead>';
        include_once txpath . '/publish/taghandlers.php';
        echo '<tbody>';
        $validator = new Validator();
        while ($a = nextRow($rs)) {
            extract($a);
            if (empty($Title)) {
                $Title = '<em>' . eLink('article', 'edit', 'ID', $ID, gTxt('untitled')) . '</em>';
            } else {
                $Title = eLink('article', 'edit', 'ID', $ID, $Title);
            }
            // Valid section and categories?
            $validator->setConstraints(array(new SectionConstraint($Section)));
            $vs = $validator->validate() ? '' : ' error';
            $validator->setConstraints(array(new CategoryConstraint($Category1, array('type' => 'article'))));
            $vc[1] = $validator->validate() ? '' : ' error';
            $validator->setConstraints(array(new CategoryConstraint($Category2, array('type' => 'article'))));
            $vc[2] = $validator->validate() ? '' : ' error';
            $Category1 = $Category1 ? '<span title="' . txpspecialchars(fetch_category_title($Category1)) . '">' . $Category1 . '</span>' : '';
            $Category2 = $Category2 ? '<span title="' . txpspecialchars(fetch_category_title($Category2)) . '">' . $Category2 . '</span>' : '';
            if ($Status != STATUS_LIVE and $Status != STATUS_STICKY) {
                $view_url = '?txpreview=' . intval($ID) . '.' . time();
            } else {
                $view_url = permlinkurl($a);
            }
            $Status = !empty($Status) ? $statuses[$Status] : '';
            $comments = '(0)';
            if (isset($total_comments[$ID]) and $total_comments[$ID] > 0) {
                $comments = href('(' . $total_comments[$ID] . ')', 'index.php?event=discuss' . a . 'step=list' . a . 'search_method=parent' . a . 'crit=' . $ID, ' title="' . gTxt('manage') . '"');
            }
            $comment_status = $Annotate ? gTxt('on') : gTxt('off');
            if ($comments_disabled_after) {
                $lifespan = $comments_disabled_after * 86400;
                $time_since = time() - $posted;
                if ($time_since > $lifespan) {
                    $comment_status = gTxt('expired');
                }
            }
            $comments = n . '<span class="comments-status">' . $comment_status . '</span> <span class="comments-manage">' . $comments . '</span>';
            echo n . n . tr(n . td(($a['Status'] >= STATUS_LIVE and has_privs('article.edit.published') or $a['Status'] >= STATUS_LIVE and $AuthorID == $txp_user and has_privs('article.edit.own.published') or $a['Status'] < STATUS_LIVE and has_privs('article.edit') or $a['Status'] < STATUS_LIVE and $AuthorID == $txp_user and has_privs('article.edit.own')) ? fInput('checkbox', 'selected[]', $ID, 'checkbox') : '&#160;', '', 'multi-edit') . n . td(eLink('article', 'edit', 'ID', $ID, $ID) . sp . '<span class="articles_detail">[<a href="' . $view_url . '">' . gTxt('view') . '</a>]</span>', '', 'id') . td($Title, '', 'title') . td(gTime($posted), '', ($posted < time() ? '' : 'unpublished ') . 'date posted created') . td(gTime($lastmod), '', "articles_detail date modified") . td($expires ? gTime($expires) : '', '', 'articles_detail date expires') . td('<span title="' . txpspecialchars(fetch_section_title($Section)) . '">' . $Section . '</span>', '', 'section' . $vs) . td($Category1, '', "articles_detail category category1" . $vc[1]) . td($Category2, '', "articles_detail category category2" . $vc[2]) . td('<a href="' . $view_url . '" title="' . gTxt('view') . '">' . $Status . '</a>', '', 'status') . ($show_authors ? td('<span title="' . txpspecialchars(get_author_name($AuthorID)) . '">' . txpspecialchars($AuthorID) . '</span>', '', 'author') : '') . td($comments, '', "articles_detail comments"));
        }
        echo '</tbody>', n, endTable(), n, '</div>', n, list_multiedit_form($page, $sort, $dir, $crit, $search_method), n, tInput(), n, '</form>', n, graf(toggle_box('articles_detail'), ' class="detail-toggle"'), n, '<div id="' . $event . '_navigation" class="txp-navigation">', n, nav_form('list', $page, $numPages, $sort, $dir, $crit, $search_method, $total, $limit), n, pageby_form('list', $article_list_pageby), n, '</div>', n, '</div>';
    }
}
Example #17
0
function link_list($message = '')
{
    global $event, $step, $link_list_pageby, $txp_user;
    extract(gpsa(array('page', 'sort', 'dir', 'crit', 'search_method')));
    if ($sort === '') {
        $sort = get_pref('link_sort_column', 'name');
    }
    if ($dir === '') {
        $dir = get_pref('link_sort_dir', 'asc');
    }
    $dir = $dir == 'desc' ? 'desc' : 'asc';
    switch ($sort) {
        case 'id':
            $sort_sql = 'id ' . $dir;
            break;
        case 'description':
            $sort_sql = 'description ' . $dir . ', id asc';
            break;
        case 'category':
            $sort_sql = 'category ' . $dir . ', id asc';
            break;
        case 'date':
            $sort_sql = 'date ' . $dir . ', id asc';
            break;
        case 'author':
            $sort_sql = 'author ' . $dir . ', id asc';
            break;
        default:
            $sort = 'name';
            $sort_sql = 'linksort ' . $dir . ', id asc';
            break;
    }
    set_pref('link_sort_column', $sort, 'link', 2, '', 0, PREF_PRIVATE);
    set_pref('link_sort_dir', $dir, 'link', 2, '', 0, PREF_PRIVATE);
    $switch_dir = $dir == 'desc' ? 'asc' : 'desc';
    $criteria = 1;
    if ($search_method and $crit) {
        $crit_escaped = doSlash(str_replace(array('\\', '%', '_', '\''), array('\\\\', '\\%', '\\_', '\\\''), $crit));
        $critsql = array('id' => "ID in ('" . join("','", do_list($crit_escaped)) . "')", 'name' => "linkname like '%{$crit_escaped}%'", 'description' => "description like '%{$crit_escaped}%'", 'category' => "category like '%{$crit_escaped}%'", 'author' => "author like '%{$crit_escaped}%'");
        if (array_key_exists($search_method, $critsql)) {
            $criteria = $critsql[$search_method];
        } else {
            $search_method = '';
            $crit = '';
        }
    } else {
        $search_method = '';
        $crit = '';
    }
    $total = getCount('txp_link', $criteria);
    echo '<div id="' . $event . '_control" class="txp-control-panel">';
    if ($total < 1) {
        if ($criteria != 1) {
            echo n . link_search_form($crit, $search_method) . n . graf(gTxt('no_results_found'), ' class="indicator"') . '</div>';
        } else {
            echo n . graf(gTxt('no_links_recorded'), ' class="indicator"') . '</div>';
        }
        return;
    }
    $limit = max($link_list_pageby, 15);
    list($page, $offset, $numPages) = pager($total, $limit, $page);
    echo link_search_form($crit, $search_method) . '</div>';
    $rs = safe_rows_start('*, unix_timestamp(date) as uDate', 'txp_link', "{$criteria} order by {$sort_sql} limit {$offset}, {$limit}");
    if ($rs) {
        $show_authors = !has_single_author('txp_link');
        echo n . '<div class="txp-list">';
        echo n . n . '<form action="index.php" id="links_form" method="post" name="longform" onsubmit="return verify(\'' . gTxt('are_you_sure') . '\')">', startTable('list', '', 'list') . n . '<thead>' . n . tr(column_head('ID', 'id', 'link', true, $switch_dir, $crit, $search_method, ('id' == $sort ? "{$dir} " : '') . 'id') . hCell('', '', ' class="actions"') . column_head('link_name', 'name', 'link', true, $switch_dir, $crit, $search_method, ('name' == $sort ? "{$dir} " : '') . 'name') . column_head('description', 'description', 'link', true, $switch_dir, $crit, $search_method, ('description' == $sort ? "{$dir} " : '') . 'description') . column_head('link_category', 'category', 'link', true, $switch_dir, $crit, $search_method, ('category' == $sort ? "{$dir} " : '') . 'category') . column_head('date', 'date', 'link', true, $switch_dir, $crit, $search_method, ('date' == $sort ? "{$dir} " : '') . 'date created') . ($show_authors ? column_head('author', 'author', 'link', true, $switch_dir, $crit, $search_method, ('author' == $sort ? "{$dir} " : '') . 'author') : '') . hCell('', '', ' class="multi-edit"')) . n . '</thead>';
        $tfoot = n . '<tfoot>' . tr(tda(select_buttons() . link_multiedit_form($page, $sort, $dir, $crit, $search_method), ' class="multi-edit" colspan="' . ($show_authors ? '8' : '7') . '" style="text-align: right; border: none;"')) . n . '</tfoot>';
        echo $tfoot;
        echo '<tbody>';
        $ctr = 1;
        while ($a = nextRow($rs)) {
            extract($a);
            $edit_url = '?event=link' . a . 'step=link_edit' . a . 'id=' . $id . a . 'sort=' . $sort . a . 'dir=' . $dir . a . 'page=' . $page . a . 'search_method=' . $search_method . a . 'crit=' . $crit;
            $can_edit = has_privs('link.edit') || $author == $txp_user && has_privs('link.edit.own');
            echo tr(n . td($id, 20, 'id') . td(n . '<ul>' . ($can_edit ? n . t . '<li class="action-edit">' . href(gTxt('edit'), $edit_url) . '</li>' : '') . n . t . '<li class="action-view">' . href(gTxt('view'), $url) . '</li>' . n . '</ul>', 35, 'actions') . td($can_edit ? href($linkname, $edit_url) : $linkname, 125, 'name') . td(htmlspecialchars($description), 150, 'description') . td('<span title="' . htmlspecialchars(fetch_category_title($category, 'link')) . '">' . $category . '</span>', 125, 'category') . td(gTime($uDate), 75, 'date created') . ($show_authors ? td('<span title="' . htmlspecialchars(get_author_name($author)) . '">' . htmlspecialchars($author) . '</span>', '', 'author') : '') . td(fInput('checkbox', 'selected[]', $id), '', 'multi-edit'), ' class="' . ($ctr % 2 == 0 ? 'even' : 'odd') . '"');
            $ctr++;
        }
        echo '</tbody>' . n . endTable() . n . '</form>' . n . '<div id="' . $event . '_navigation" class="txp-navigation">' . n . nav_form('link', $page, $numPages, $sort, $dir, $crit, $search_method, $total, $limit) . pageby_form('link', $link_list_pageby) . n . '</div>' . n . '</div>';
    }
}
Example #18
0
function image_list($message = '')
{
    global $txpcfg, $extensions, $img_dir, $file_max_upload_size, $image_list_pageby;
    pagetop(gTxt('images'), $message);
    extract($txpcfg);
    extract(gpsa(array('page', 'sort', 'dir', 'crit', 'search_method')));
    if (!is_dir(IMPATH) or !is_writeable(IMPATH)) {
        echo graf(gTxt('img_dir_not_writeable', array('{imgdir}' => IMPATH)), ' id="warning"');
    } else {
        echo upload_form(gTxt('upload_image'), 'upload', 'image_insert', 'image', '', $file_max_upload_size);
    }
    $dir = $dir == 'asc' ? 'asc' : 'desc';
    switch ($sort) {
        case 'name':
            $sort_sql = 'name ' . $dir;
            break;
        case 'thumbnail':
            $sort_sql = 'thumbnail ' . $dir . ', id asc';
            break;
        case 'category':
            $sort_sql = 'category ' . $dir . ', id asc';
            break;
        case 'date':
            $sort_sql = 'date ' . $dir . ', id asc';
            break;
        case 'author':
            $sort_sql = 'author ' . $dir . ', id asc';
            break;
        default:
            $sort = 'id';
            $sort_sql = 'id ' . $dir;
            break;
    }
    $switch_dir = $dir == 'desc' ? 'asc' : 'desc';
    $criteria = 1;
    if ($search_method and $crit) {
        $crit_escaped = doSlash($crit);
        $critsql = array('id' => "ID in ('" . join("','", do_list($crit_escaped)) . "')", 'name' => "name like '%{$crit_escaped}%'", 'category' => "category like '%{$crit_escaped}%'", 'author' => "author like '%{$crit_escaped}%'", 'alt' => "alt like '%{$crit_escaped}%'", 'caption' => "caption like '%{$crit_escaped}%'");
        if (array_key_exists($search_method, $critsql)) {
            $criteria = $critsql[$search_method];
            $limit = 500;
        } else {
            $search_method = '';
            $crit = '';
        }
    } else {
        $search_method = '';
        $crit = '';
    }
    $total = safe_count('txp_image', "{$criteria}");
    if ($total < 1) {
        if ($criteria != 1) {
            echo n . image_search_form($crit, $search_method) . n . graf(gTxt('no_results_found'), ' class="indicator"');
        } else {
            echo n . graf(gTxt('no_images_recorded'), ' class="indicator"');
        }
        return;
    }
    $limit = max($image_list_pageby, 15);
    list($page, $offset, $numPages) = pager($total, $limit, $page);
    echo image_search_form($crit, $search_method);
    $rs = safe_rows_start('*, unix_timestamp(date) as uDate', 'txp_image', "{$criteria} order by {$sort_sql} limit {$offset}, {$limit}\n\t\t");
    if ($rs) {
        echo n . n . '<form name="longform" method="post" action="index.php" onsubmit="return verify(\'' . gTxt('are_you_sure') . '\')">' . n . n . startTable('list') . n . tr(column_head('ID', 'id', 'image', true, $switch_dir, $crit, $search_method, 'id' == $sort ? $dir : '') . hCell() . column_head('date', 'date', 'image', true, $switch_dir, $crit, $search_method, 'date' == $sort ? $dir : '') . column_head('name', 'name', 'image', true, $switch_dir, $crit, $search_method, 'name' == $sort ? $dir : '') . column_head('thumbnail', 'thumbnail', 'image', true, $switch_dir, $crit, $search_method, 'thumbnail' == $sort ? $dir : '') . hCell(gTxt('tags')) . column_head('image_category', 'category', 'image', true, $switch_dir, $crit, $search_method, 'category' == $sort ? $dir : '') . column_head('author', 'author', 'image', true, $switch_dir, $crit, $search_method, 'author' == $sort ? $dir : '') . hCell());
        while ($a = nextRow($rs)) {
            extract($a);
            $edit_url = '?event=image' . a . 'step=image_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 . "?{$uDate}" . '" alt="" />';
                } else {
                    $thumbnail = '';
                }
            } else {
                $thumbnail = gTxt('no');
            }
            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>' : '';
            echo n . n . tr(n . td($id, 20) . td(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>', 35) . td(gTime($uDate), 75) . td(href($name, $edit_url), 75) . td(href($thumbnail, $edit_url), 80) . td($tagbuilder, 85) . td($category, 75) . td('<span title="' . htmlspecialchars(get_author_name($author)) . '">' . htmlspecialchars($author) . '</span>', 75) . td(fInput('checkbox', 'selected[]', $id), 10));
        }
        echo n . n . tr(tda(select_buttons() . image_multiedit_form($page, $sort, $dir, $crit, $search_method), ' colspan="9" style="text-align: right; border: none;"')) . endTable() . '</form>' . nav_form('image', $page, $numPages, $sort, $dir, $crit, $search_method) . pageby_form('image', $image_list_pageby);
    }
}
Example #19
0
function log_list($message = '')
{
    global $event, $log_list_pageby, $expire_logs_after;
    pagetop(gTxt('tab_logs'), $message);
    extract(gpsa(array('page', 'sort', 'dir', 'crit', 'search_method')));
    if ($sort === '') {
        $sort = get_pref('log_sort_column', 'time');
    }
    if ($dir === '') {
        $dir = get_pref('log_sort_dir', 'desc');
    }
    $dir = $dir == 'asc' ? 'asc' : 'desc';
    $expire_logs_after = assert_int($expire_logs_after);
    safe_delete('txp_log', "time < date_sub(now(), interval {$expire_logs_after} day)");
    switch ($sort) {
        case 'ip':
            $sort_sql = 'ip ' . $dir;
            break;
        case 'host':
            $sort_sql = 'host ' . $dir;
            break;
        case 'page':
            $sort_sql = 'page ' . $dir;
            break;
        case 'refer':
            $sort_sql = 'refer ' . $dir;
            break;
        case 'method':
            $sort_sql = 'method ' . $dir;
            break;
        case 'status':
            $sort_sql = 'status ' . $dir;
            break;
        default:
            $sort = 'time';
            $sort_sql = 'time ' . $dir;
            break;
    }
    set_pref('log_sort_column', $sort, 'log', 2, '', 0, PREF_PRIVATE);
    set_pref('log_sort_dir', $dir, 'log', 2, '', 0, PREF_PRIVATE);
    $switch_dir = $dir == 'desc' ? 'asc' : 'desc';
    $criteria = 1;
    if ($search_method and $crit != '') {
        $verbatim = preg_match('/^"(.*)"$/', $crit, $m);
        $crit_escaped = doSlash($verbatim ? $m[1] : str_replace(array('\\', '%', '_', '\''), array('\\\\', '\\%', '\\_', '\\\''), $crit));
        $critsql = $verbatim ? array('ip' => "ip = '{$crit_escaped}'", 'host' => "host = '{$crit_escaped}'", 'page' => "page = '{$crit_escaped}'", 'refer' => "refer = '{$crit_escaped}'", 'method' => "method = '{$crit_escaped}'", 'status' => "status = '{$crit_escaped}'") : array('ip' => "ip like '%{$crit_escaped}%'", 'host' => "host like '%{$crit_escaped}%'", 'page' => "page like '%{$crit_escaped}%'", 'refer' => "refer like '%{$crit_escaped}%'", 'method' => "method like '%{$crit_escaped}%'", 'status' => "status like '%{$crit_escaped}%'");
        if (array_key_exists($search_method, $critsql)) {
            $criteria = $critsql[$search_method];
            $limit = 500;
        } else {
            $search_method = '';
            $crit = '';
        }
    } else {
        $search_method = '';
        $crit = '';
    }
    $criteria .= callback_event('admin_criteria', 'log_list', 0, $criteria);
    $total = safe_count('txp_log', "{$criteria}");
    echo '<h1 class="txp-heading">' . gTxt('tab_logs') . '</h1>';
    echo '<div id="' . $event . '_control" class="txp-control-panel">';
    if ($total < 1) {
        if ($criteria != 1) {
            echo n . log_search_form($crit, $search_method) . n . graf(gTxt('no_results_found'), ' class="indicator"') . '</div>';
        } else {
            echo graf(gTxt('no_refers_recorded'), ' class="indicator"') . '</div>';
        }
        return;
    }
    $limit = max($log_list_pageby, 15);
    list($page, $offset, $numPages) = pager($total, $limit, $page);
    echo n . log_search_form($crit, $search_method) . '</div>';
    $rs = safe_rows_start('*, unix_timestamp(time) as uTime', 'txp_log', "{$criteria} order by {$sort_sql} limit {$offset}, {$limit}");
    if ($rs) {
        echo n . '<div id="' . $event . '_container" class="txp-container">';
        echo n . n . '<form action="index.php" id="log_form" class="multi_edit_form" method="post" name="longform">' . n . '<div class="txp-listtables">' . n . startTable('', '', 'txp-list') . n . '<thead>' . n . tr(n . hCell(fInput('checkbox', 'select_all', 0, '', '', '', '', '', 'select_all'), '', ' title="' . gTxt('toggle_all_selected') . '" class="multi-edit"') . n . column_head('time', 'time', 'log', true, $switch_dir, $crit, $search_method, ('time' == $sort ? "{$dir} " : '') . 'date time') . n . column_head('IP', 'ip', 'log', true, $switch_dir, $crit, $search_method, ('ip' == $sort ? "{$dir} " : '') . 'log_detail ip') . n . column_head('host', 'host', 'log', true, $switch_dir, $crit, $search_method, ('host' == $sort ? "{$dir} " : '') . 'host') . n . column_head('page', 'page', 'log', true, $switch_dir, $crit, $search_method, ('page' == $sort ? "{$dir} " : '') . 'page') . n . column_head('referrer', 'refer', 'log', true, $switch_dir, $crit, $search_method, ('refer' == $sort ? "{$dir} " : '') . 'refer') . n . column_head('method', 'method', 'log', true, $switch_dir, $crit, $search_method, ('method' == $sort ? "{$dir} " : '') . 'log_detail method') . n . column_head('status', 'status', 'log', true, $switch_dir, $crit, $search_method, ('status' == $sort ? "{$dir} " : '') . 'log_detail status')) . n . '</thead>';
        echo '<tbody>';
        while ($a = nextRow($rs)) {
            extract($a, EXTR_PREFIX_ALL, 'log');
            if ($log_refer) {
                $log_refer = 'http://' . $log_refer;
                $log_refer = '<a href="' . txpspecialchars($log_refer) . '" target="_blank">' . txpspecialchars(soft_wrap($log_refer, 30)) . '</a>';
            }
            if ($log_page) {
                $log_anchor = preg_replace('/\\/$/', '', $log_page);
                $log_anchor = soft_wrap(substr($log_anchor, 1), 30);
                $log_page = '<a href="' . txpspecialchars($log_page) . '" target="_blank">' . txpspecialchars($log_anchor) . '</a>';
                if ($log_method == 'POST') {
                    $log_page = '<strong>' . $log_page . '</strong>';
                }
            }
            echo tr(n . td(fInput('checkbox', 'selected[]', $log_id), '', 'multi-edit') . td(gTime($log_uTime), '', 'date time') . td(txpspecialchars($log_ip), '', 'log_detail ip') . td(txpspecialchars(soft_wrap($log_host, 30)), '', 'host') . td($log_page, '', 'page') . td($log_refer, '', 'refer') . td(txpspecialchars($log_method), '', 'log_detail method') . td($log_status, '', 'log_detail status'));
        }
        echo '</tbody>', n, endTable(), n, '</div>', n, log_multiedit_form($page, $sort, $dir, $crit, $search_method), n, tInput(), n, '</form>', n, graf(toggle_box('log_detail'), ' class="detail-toggle"'), n, '<div id="' . $event . '_navigation" class="txp-navigation">', n, nav_form('log', $page, $numPages, $sort, $dir, $crit, $search_method, $total, $limit), n, pageby_form('log', $log_list_pageby), n, '</div>', n, '</div>';
    }
}
Example #20
0
/**
 * The main panel listing all files.
 *
 * @param string|array $message The activity message
 */
function file_list($message = '')
{
    global $file_base_path, $file_statuses, $file_list_pageby, $txp_user, $event;
    pagetop(gTxt('tab_file'), $message);
    extract(gpsa(array('page', 'sort', 'dir', 'crit', 'search_method')));
    if ($sort === '') {
        $sort = get_pref('file_sort_column', 'filename');
    } else {
        if (!in_array($sort, array('id', 'description', 'category', 'title', 'downloads', 'author'))) {
            $sort = 'filename';
        }
        set_pref('file_sort_column', $sort, 'file', PREF_HIDDEN, '', 0, PREF_PRIVATE);
    }
    if ($dir === '') {
        $dir = get_pref('file_sort_dir', 'asc');
    } else {
        $dir = $dir == 'asc' ? "asc" : "desc";
        set_pref('file_sort_dir', $dir, 'file', PREF_HIDDEN, '', 0, PREF_PRIVATE);
    }
    switch ($sort) {
        case 'id':
            $sort_sql = "txp_file.id {$dir}";
            break;
        case 'date':
            $sort_sql = "txp_file.created {$dir}, txp_file.id ASC";
            break;
        case 'category':
            $sort_sql = "txp_category.title {$dir}, txp_file.filename DESC";
            break;
        case 'title':
            $sort_sql = "txp_file.title {$dir}, txp_file.filename DESC";
            break;
        case 'downloads':
            $sort_sql = "txp_file.downloads {$dir}, txp_file.filename DESC";
            break;
        case 'author':
            $sort_sql = "txp_users.RealName {$dir}, txp_file.id ASC";
            break;
        default:
            $sort = 'filename';
            $sort_sql = "txp_file.filename {$dir}";
            break;
    }
    $switch_dir = $dir == 'desc' ? 'asc' : 'desc';
    $search = new Filter($event, array('id' => array('column' => 'txp_file.id', 'label' => gTxt('ID'), 'type' => 'integer'), 'filename' => array('column' => 'txp_file.filename', 'label' => gTxt('file_name')), 'title' => array('column' => 'txp_file.title', 'label' => gTxt('title')), 'description' => array('column' => 'txp_file.description', 'label' => gTxt('description')), 'category' => array('column' => array('txp_file.category', 'txp_category.title'), 'label' => gTxt('file_category')), 'status' => array('column' => array('txp_file.status'), 'label' => gTxt('status'), 'type' => 'boolean'), 'author' => array('column' => array('txp_file.author', 'txp_users.RealName'), 'label' => gTxt('author'))));
    $search->setAliases('status', $file_statuses);
    list($criteria, $crit, $search_method) = $search->getFilter(array('id' => array('can_list' => true)));
    $search_render_options = array('placeholder' => 'search_files');
    $sql_from = safe_pfx_j('txp_file') . "\n        LEFT JOIN " . safe_pfx_j('txp_category') . " ON txp_category.name = txp_file.category AND txp_category.type = 'file'\n        LEFT JOIN " . safe_pfx_j('txp_users') . " ON txp_users.name = txp_file.author";
    if ($criteria === 1) {
        $total = safe_count('txp_file', $criteria);
    } else {
        $total = getThing("SELECT COUNT(*) FROM {$sql_from} WHERE {$criteria}");
    }
    echo n . tag(hed(gTxt('tab_file'), 1, array('class' => 'txp-heading')), 'div', array('class' => 'txp-layout-2col-cell-1'));
    $searchBlock = n . tag($search->renderForm('file_list', $search_render_options), 'div', array('class' => 'txp-layout-2col-cell-2', 'id' => $event . '_control'));
    $createBlock = array();
    if (!is_dir($file_base_path) || !is_writeable($file_base_path)) {
        $createBlock[] = graf(span(null, array('class' => 'ui-icon ui-icon-alert')) . ' ' . gTxt('file_dir_not_writeable', array('{filedir}' => $file_base_path)), array('class' => 'alert-block warning'));
    } elseif (has_privs('file.edit.own')) {
        $createBlock[] = n . tag_start('div', array('class' => 'txp-control-panel')) . n . file_upload_form('upload_file', 'upload', 'file_insert', '', '', '', '');
        $existing_files = get_filenames();
        if ($existing_files) {
            $createBlock[] = form(eInput('file') . sInput('file_create') . tag(gTxt('existing_file'), 'label', array('for' => 'file-existing')) . selectInput('filename', $existing_files, '', 1, '', 'file-existing') . fInput('submit', '', gTxt('Create')), '', '', 'post', 'assign-existing-form', '', 'assign_file');
        }
        $createBlock[] = tag_end('div');
    }
    $contentBlockStart = n . tag_start('div', array('class' => 'txp-layout-1col', 'id' => $event . '_container'));
    $createBlock = implode(n, $createBlock);
    if ($total < 1) {
        if ($criteria != 1) {
            echo $searchBlock . $contentBlockStart . $createBlock . graf(span(null, array('class' => 'ui-icon ui-icon-info')) . ' ' . gTxt('no_results_found'), array('class' => 'alert-block information'));
        } else {
            echo $contentBlockStart . $createBlock . graf(span(null, array('class' => 'ui-icon ui-icon-info')) . ' ' . gTxt('no_files_recorded'), array('class' => 'alert-block information'));
        }
        echo n . tag_end('div');
        return;
    }
    $limit = max($file_list_pageby, 15);
    list($page, $offset, $numPages) = pager($total, $limit, $page);
    echo $searchBlock . $contentBlockStart . $createBlock;
    $rs = safe_query("SELECT\n            txp_file.id,\n            txp_file.filename,\n            txp_file.title,\n            txp_file.category,\n            txp_file.description,\n            UNIX_TIMESTAMP(txp_file.created) AS uDate,\n            txp_file.downloads,\n            txp_file.status,\n            txp_file.author,\n            txp_users.RealName AS realname,\n            txp_category.Title AS category_title\n        FROM {$sql_from} WHERE {$criteria} ORDER BY {$sort_sql} LIMIT {$offset}, {$limit}");
    if ($rs && numRows($rs)) {
        $show_authors = !has_single_author('txp_file');
        echo n . tag(toggle_box('files_detail'), 'div', array('class' => 'txp-list-options')) . n . tag_start('form', array('class' => 'multi_edit_form', 'id' => 'files_form', 'name' => 'longform', 'method' => 'post', 'action' => 'index.php')) . n . tag_start('div', array('class' => 'txp-listtables')) . n . tag_start('table', array('class' => 'txp-list')) . n . tag_start('thead') . tr(hCell(fInput('checkbox', 'select_all', 0, '', '', '', '', '', 'select_all'), '', ' class="txp-list-col-multi-edit" scope="col" title="' . gTxt('toggle_all_selected') . '"') . column_head('ID', 'id', 'file', true, $switch_dir, $crit, $search_method, ('id' == $sort ? "{$dir} " : '') . 'txp-list-col-id') . column_head('file_name', 'filename', 'file', true, $switch_dir, $crit, $search_method, ('filename' == $sort ? "{$dir} " : '') . 'txp-list-col-filename') . column_head('title', 'title', 'file', true, $switch_dir, $crit, $search_method, ('title' == $sort ? "{$dir} " : '') . 'txp-list-col-title files_detail') . column_head('date', 'date', 'image', true, $switch_dir, $crit, $search_method, ('date' == $sort ? "{$dir} " : '') . 'txp-list-col-created date files_detail') . column_head('file_category', 'category', 'file', true, $switch_dir, $crit, $search_method, ('category' == $sort ? "{$dir} " : '') . 'txp-list-col-category category') . hCell(gTxt('tags'), '', ' class="txp-list-col-tag-build files_detail" scope="col"') . hCell(gTxt('status'), '', ' class="txp-list-col-status" scope="col"') . hCell(gTxt('condition'), '', ' class="txp-list-col-condition" scope="col"') . column_head('downloads', 'downloads', 'file', true, $switch_dir, $crit, $search_method, ('downloads' == $sort ? "{$dir} " : '') . 'txp-list-col-downloads') . ($show_authors ? column_head('author', 'author', 'file', true, $switch_dir, $crit, $search_method, ('author' == $sort ? "{$dir} " : '') . 'txp-list-col-author name') : '')) . n . tag_end('thead') . n . tag_start('tbody');
        $validator = new Validator();
        while ($a = nextRow($rs)) {
            extract($a);
            $filename = sanitizeForFile($filename);
            $edit_url = array('event' => 'file', 'step' => 'file_edit', 'id' => $id, 'sort' => $sort, 'dir' => $dir, 'page' => $page, 'search_method' => $search_method, 'crit' => $crit);
            $tag_url = array('event' => 'tag', 'tag_name' => 'file_download_link', 'id' => $id, 'description' => $description, 'filename' => $filename);
            $file_exists = file_exists(build_file_path($file_base_path, $filename));
            $can_edit = has_privs('file.edit') || $author === $txp_user && has_privs('file.edit.own');
            $validator->setConstraints(array(new CategoryConstraint($category, array('type' => 'file'))));
            if ($validator->validate()) {
                $vc = '';
            } else {
                $vc = ' error';
            }
            if ($file_exists) {
                $downloads = make_download_link($id, $downloads, $filename);
                $condition = span(gTxt('file_status_ok'), array('class' => 'success'));
            } else {
                $condition = span(gTxt('file_status_missing'), array('class' => 'error'));
            }
            if ($category) {
                $category = span(txpspecialchars($category_title), array('title' => $category));
            }
            if ($can_edit) {
                $name = href(txpspecialchars($filename), $edit_url, array('title' => gTxt('edit')));
            } else {
                $name = txpspecialchars($filename);
            }
            if ($can_edit) {
                $id_column = href($id, $edit_url, array('title' => gTxt('edit')));
                $multi_edit = fInput('checkbox', 'selected[]', $id);
            } else {
                $id_column = $id;
                $multi_edit = '';
            }
            if ($file_exists) {
                $id_column .= sp . span(span('[', array('aria-hidden' => 'true')) . make_download_link($id, gTxt('download'), $filename) . span(']', array('aria-hidden' => 'true')), array('class' => 'txp-option-link'));
            }
            if (isset($file_statuses[$status])) {
                $status = $file_statuses[$status];
            } else {
                $status = span(gTxt('none'), array('class' => 'error'));
            }
            echo tr(td($multi_edit, '', 'txp-list-col-multi-edit') . hCell($id_column, '', array('class' => 'txp-list-col-id', 'scope' => 'row')) . td($name, '', 'txp-list-col-filename') . td(txpspecialchars($title), '', 'txp-list-col-title files_detail') . td(gTime($uDate), '', 'txp-list-col-created date files_detail') . td($category, '', 'txp-list-col-category category' . $vc) . td(href('Textile', $tag_url + array('type' => 'textile'), ' target="_blank" onclick="popWin(this.href); return false;"') . sp . span('&#124;', array('role' => 'separator')) . sp . href('Textpattern', $tag_url + array('type' => 'textpattern'), ' target="_blank" onclick="popWin(this.href); return false;"') . sp . span('&#124;', array('role' => 'separator')) . sp . href('HTML', $tag_url + array('type' => 'html'), ' target="_blank" onclick="popWin(this.href); return false;"'), '', 'txp-list-col-tag-build files_detail') . td($status, '', 'txp-list-col-status') . td($condition, '', 'txp-list-col-condition') . td($downloads, '', 'txp-list-col-downloads') . ($show_authors ? td(span(txpspecialchars($realname), array('title' => $author)), '', 'txp-list-col-author name') : ''));
        }
        echo n . tag_end('tbody') . n . tag_end('table') . n . tag_end('div') . file_multiedit_form($page, $sort, $dir, $crit, $search_method) . tInput() . n . tag_end('form') . n . tag_start('div', array('class' => 'txp-navigation', 'id' => $event . '_navigation')) . pageby_form('file', $file_list_pageby) . nav_form('file', $page, $numPages, $sort, $dir, $crit, $search_method, $total, $limit) . n . tag_end('div');
    }
}
Example #21
0
function list_list($message = '', $post = '')
{
    global $statuses, $comments_disabled_after, $step, $txp_user, $article_list_pageby;
    pagetop(gTxt('tab_list'), $message);
    extract(gpsa(array('page', 'sort', 'dir', 'crit', 'search_method')));
    $sesutats = array_flip($statuses);
    $dir = $dir == 'asc' ? 'asc' : 'desc';
    switch ($sort) {
        case 'id':
            $sort_sql = 'ID ' . $dir;
            break;
        case 'expires':
            $sort_sql = 'Expires ' . $dir;
            break;
        case 'title':
            $sort_sql = 'Title ' . $dir . ', Posted desc';
            break;
        case 'section':
            $sort_sql = 'Section ' . $dir . ', Posted desc';
            break;
        case 'category1':
            $sort_sql = 'Category1 ' . $dir . ', Posted desc';
            break;
        case 'category2':
            $sort_sql = 'Category2 ' . $dir . ', Posted desc';
            break;
        case 'status':
            $sort_sql = 'Status ' . $dir . ', Posted desc';
            break;
        case 'author':
            $sort_sql = 'AuthorID ' . $dir . ', Posted desc';
            break;
        case 'comments':
            $sort_sql = 'comments_count ' . $dir . ', Posted desc';
            break;
        case 'lastmod':
            $sort_sql = 'LastMod ' . $dir . ', Posted desc';
            break;
        default:
            $sort = 'posted';
            $sort_sql = 'Posted ' . $dir;
            break;
    }
    $switch_dir = $dir == 'desc' ? 'asc' : 'desc';
    $criteria = 1;
    if ($search_method and $crit) {
        $crit_escaped = doSlash($crit);
        $critsql = array('id' => "ID in ('" . join("','", do_list($crit_escaped)) . "')", 'title_body_excerpt' => "Title rlike '{$crit_escaped}' or Body rlike '{$crit_escaped}' or Excerpt rlike '{$crit_escaped}'", 'section' => "Section rlike '{$crit_escaped}'", 'keywords' => "FIND_IN_SET('" . $crit_escaped . "',Keywords)", 'categories' => "Category1 rlike '{$crit_escaped}' or Category2 rlike '{$crit_escaped}'", 'status' => "Status = '" . @$sesutats[gTxt($crit_escaped)] . "'", 'author' => "AuthorID rlike '{$crit_escaped}'", 'article_image' => "Image in ('" . join("','", do_list($crit_escaped)) . "')", 'posted' => "Posted like '{$crit_escaped}%'", 'lastmod' => "LastMod like '{$crit_escaped}%'");
        if (array_key_exists($search_method, $critsql)) {
            $criteria = $critsql[$search_method];
            $limit = 500;
        } else {
            $search_method = '';
            $crit = '';
        }
    } else {
        $search_method = '';
        $crit = '';
    }
    $total = safe_count('textpattern', "{$criteria}");
    if ($total < 1) {
        if ($criteria != 1) {
            echo n . list_search_form($crit, $search_method) . n . graf(gTxt('no_results_found'), ' class="indicator"');
        } else {
            echo graf(gTxt('no_articles_recorded'), ' class="indicator"');
        }
        return;
    }
    $limit = max($article_list_pageby, 15);
    list($page, $offset, $numPages) = pager($total, $limit, $page);
    echo n . list_search_form($crit, $search_method);
    $rs = safe_rows_start('*, unix_timestamp(Posted) as posted, unix_timestamp(LastMod) as lastmod, unix_timestamp(Expires) as expires', 'textpattern', "{$criteria} order by {$sort_sql} limit {$offset}, {$limit}");
    if ($rs) {
        $total_comments = array();
        // fetch true comment count, not the public comment count
        // maybe we should have another row in the db?
        $rs2 = safe_rows_start('parentid, count(*) as num', 'txp_discuss', "1 group by parentid order by parentid");
        if ($rs2) {
            while ($a = nextRow($rs2)) {
                $pid = $a['parentid'];
                $num = $a['num'];
                $total_comments[$pid] = $num;
            }
        }
        echo n . n . '<form name="longform" method="post" action="index.php" onsubmit="return verify(\'' . gTxt('are_you_sure') . '\')">' . n . startTable('list', '', '', '', '90%') . n . tr(n . column_head('ID', 'id', 'list', true, $switch_dir, $crit, $search_method, 'id' == $sort ? $dir : '') . column_head('posted', 'posted', 'list', true, $switch_dir, $crit, $search_method, 'posted' == $sort ? $dir : '') . column_head('article_modified', 'lastmod', 'list', true, $switch_dir, $crit, $search_method, ('lastmod' == $sort ? "{$dir} " : '') . 'articles_detail') . column_head('expires', 'expires', 'list', true, $switch_dir, $crit, $search_method, ('expires' == $sort ? "{$dir} " : '') . 'articles_detail') . column_head('title', 'title', 'list', true, $switch_dir, $crit, $search_method, 'title' == $sort ? $dir : '') . column_head('section', 'section', 'list', true, $switch_dir, $crit, $search_method, 'section' == $sort ? $dir : '') . column_head('category1', 'category1', 'list', true, $switch_dir, $crit, $search_method, ('category1' == $sort ? "{$dir} " : '') . 'articles_detail') . column_head('category2', 'category2', 'list', true, $switch_dir, $crit, $search_method, ('category2' == $sort ? "{$dir} " : '') . 'articles_detail') . column_head('status', 'status', 'list', true, $switch_dir, $crit, $search_method, 'status' == $sort ? $dir : '') . column_head('author', 'author', 'list', true, $switch_dir, $crit, $search_method, 'author' == $sort ? $dir : '') . column_head('comments', 'comments', 'list', true, $switch_dir, $crit, $search_method, ('comments' == $sort ? "{$dir} " : '') . 'articles_detail') . hCell());
        include_once txpath . '/publish/taghandlers.php';
        while ($a = nextRow($rs)) {
            extract($a);
            if (empty($Title)) {
                $Title = '<em>' . eLink('article', 'edit', 'ID', $ID, gTxt('untitled')) . '</em>';
            } else {
                $Title = eLink('article', 'edit', 'ID', $ID, $Title);
            }
            $Category1 = $Category1 ? '<span title="' . htmlspecialchars(fetch_category_title($Category1)) . '">' . $Category1 . '</span>' : '';
            $Category2 = $Category2 ? '<span title="' . htmlspecialchars(fetch_category_title($Category2)) . '">' . $Category2 . '</span>' : '';
            $view_url = permlinkurl($a);
            if ($Status != 4 and $Status != 5) {
                $view_url .= (strpos($view_url, '?') === FALSE ? '?' : '&amp;') . 'txpreview=' . intval($ID) . '.' . time();
            }
            $manage = n . '<ul class="articles_detail">' . n . t . '<li>' . eLink('article', 'edit', 'ID', $ID, gTxt('edit')) . '</li>' . n . t . '<li><a href="' . $view_url . '" class="article-view">' . gTxt('view') . '</a></li>' . n . '</ul>';
            $Status = !empty($Status) ? $statuses[$Status] : '';
            $comments = gTxt('none');
            if (isset($total_comments[$ID]) and $total_comments[$ID] > 0) {
                $comments = href(gTxt('manage'), 'index.php?event=discuss' . a . 'step=list' . a . 'search_method=parent' . a . 'crit=' . $ID) . ' (' . $total_comments[$ID] . ')';
            }
            $comment_status = $Annotate ? gTxt('on') : gTxt('off');
            if ($comments_disabled_after) {
                $lifespan = $comments_disabled_after * 86400;
                $time_since = time() - $posted;
                if ($time_since > $lifespan) {
                    $comment_status = gTxt('expired');
                }
            }
            $comments = n . '<ul>' . n . t . '<li>' . $comment_status . '</li>' . n . t . '<li>' . $comments . '</li>' . n . '</ul>';
            echo n . n . tr(n . td(eLink('article', 'edit', 'ID', $ID, $ID) . $manage) . td(gTime($posted), '', $posted < time() ? '' : 'unpublished') . td(gTime($lastmod), '', "articles_detail") . td($expires ? gTime($expires) : '', '', 'articles_detail') . td($Title) . td('<span title="' . htmlspecialchars(fetch_section_title($Section)) . '">' . $Section . '</span>', 75) . td($Category1, 100, "articles_detail") . td($Category2, 100, "articles_detail") . td($a['Status'] < 4 ? $Status : '<a href="' . permlinkurl($a) . '">' . $Status . '</a>', 50) . td('<span title="' . htmlspecialchars(get_author_name($AuthorID)) . '">' . htmlspecialchars($AuthorID) . '</span>') . td($comments, 50, "articles_detail") . td(($a['Status'] >= 4 and has_privs('article.edit.published') or $a['Status'] >= 4 and $AuthorID == $txp_user and has_privs('article.edit.own.published') or $a['Status'] < 4 and has_privs('article.edit') or $a['Status'] < 4 and $AuthorID == $txp_user and has_privs('article.edit.own')) ? fInput('checkbox', 'selected[]', $ID) : '&nbsp;'));
        }
        echo n . n . tr(tda(toggle_box('articles_detail'), ' colspan="2" style="text-align: left; border: none;"') . tda(select_buttons() . list_multiedit_form($page, $sort, $dir, $crit, $search_method), ' colspan="9" style="text-align: right; border: none;"')) . n . endTable() . n . '</form>' . n . nav_form('list', $page, $numPages, $sort, $dir, $crit, $search_method, $total, $limit) . n . pageby_form('list', $article_list_pageby);
    }
}
Example #22
0
function ipban_list($message = '')
{
    global $event;
    pageTop(gTxt('list_banned_ips'), $message);
    echo '<h1 class="txp-heading">' . gTxt('banned_ips') . '</h1>';
    echo '<div id="' . $event . '_banned_control" class="txp-control-panel">';
    echo graf(sLink('discuss', 'discuss_list', gTxt('list_discussions')), ' class="txp-buttons"');
    echo '</div>';
    $rs = safe_rows_start('*, unix_timestamp(date_banned) as uBanned', 'txp_discuss_ipban', "1 = 1 order by date_banned desc");
    if ($rs and numRows($rs) > 0) {
        echo '<div id="' . $event . '_ban_container" class="txp-container">' . startTable('', '', 'txp-list') . n . '<thead>' . tr(hCell(gTxt('date_banned'), '', ' class="date banned"') . hCell(gTxt('IP'), '', ' class="ip"') . hCell(gTxt('name_used'), '', ' class="name"') . hCell(gTxt('banned_for'), '', ' class="id"')) . n . '</thead>';
        echo '<tbody>';
        while ($a = nextRow($rs)) {
            extract($a);
            echo tr(td(gTime($uBanned), '', 'date banned') . td(txpspecialchars($ip) . n . '[<a class="action-ban" href="?event=discuss' . a . 'step=ipban_unban' . a . 'ip=' . txpspecialchars($ip) . a . '_txp_token=' . form_token() . '">' . gTxt('unban') . '</a>]', '', 'ip') . td(txpspecialchars($name_used), '', 'name') . td('<a href="?event=discuss' . a . 'step=discuss_edit' . a . 'discussid=' . $banned_on_message . '">' . $banned_on_message . '</a>', '', 'id'));
        }
        echo '</tbody>' . endTable() . '</div>';
    } else {
        echo graf(gTxt('no_ips_banned'), ' class="indicator"');
    }
}
Example #23
0
function link_list($message = '')
{
    global $step, $link_list_pageby;
    extract(gpsa(array('page', 'sort', 'dir', 'crit', 'search_method')));
    $dir = $dir == 'desc' ? 'desc' : 'asc';
    switch ($sort) {
        case 'id':
            $sort_sql = 'id ' . $dir;
            break;
        case 'description':
            $sort_sql = 'description ' . $dir . ', id asc';
            break;
        case 'category':
            $sort_sql = 'category ' . $dir . ', id asc';
            break;
        case 'date':
            $sort_sql = 'date ' . $dir . ', id asc';
            break;
        default:
            $sort = 'name';
            $sort_sql = 'linksort ' . $dir . ', id asc';
            break;
    }
    $switch_dir = $dir == 'desc' ? 'asc' : 'desc';
    $criteria = 1;
    if ($search_method and $crit) {
        $crit_escaped = doSlash($crit);
        $critsql = array('id' => "ID in ('" . join("','", do_list($crit_escaped)) . "')", 'name' => "linkname like '%{$crit_escaped}%'", 'description' => "description like '%{$crit_escaped}%'", 'category' => "category like '%{$crit_escaped}%'");
        if (array_key_exists($search_method, $critsql)) {
            $criteria = $critsql[$search_method];
        } else {
            $search_method = '';
            $crit = '';
        }
    } else {
        $search_method = '';
        $crit = '';
    }
    $total = getCount('txp_link', $criteria);
    if ($total < 1) {
        if ($criteria != 1) {
            echo n . link_search_form($crit, $search_method) . n . graf(gTxt('no_results_found'), ' class="indicator"');
        } else {
            echo n . graf(gTxt('no_links_recorded'), ' class="indicator"');
        }
        return;
    }
    $limit = max($link_list_pageby, 15);
    list($page, $offset, $numPages) = pager($total, $limit, $page);
    echo link_search_form($crit, $search_method);
    $rs = safe_rows_start('*, unix_timestamp(date) as uDate', 'txp_link', "{$criteria} order by {$sort_sql} limit {$offset}, {$limit}");
    if ($rs) {
        echo n . n . '<form action="index.php" method="post" name="longform" onsubmit="return verify(\'' . gTxt('are_you_sure') . '\')">', startTable('list') . n . tr(column_head('ID', 'id', 'link', true, $switch_dir, $crit, $search_method, 'id' == $sort ? $dir : '') . hCell() . column_head('link_name', 'name', 'link', true, $switch_dir, $crit, $search_method, 'name' == $sort ? $dir : '') . column_head('description', 'description', 'link', true, $switch_dir, $crit, $search_method, 'description' == $sort ? $dir : '') . column_head('link_category', 'category', 'link', true, $switch_dir, $crit, $search_method, 'category' == $sort ? $dir : '') . column_head('date', 'date', 'link', true, $switch_dir, $crit, $search_method, 'date' == $sort ? $dir : '') . hCell());
        while ($a = nextRow($rs)) {
            extract($a);
            $edit_url = '?event=link' . a . 'step=link_edit' . a . 'id=' . $id . a . 'sort=' . $sort . a . 'dir=' . $dir . a . 'page=' . $page . a . 'search_method=' . $search_method . a . 'crit=' . $crit;
            echo tr(n . td($id, 20) . td(n . '<ul>' . n . t . '<li>' . href(gTxt('edit'), $edit_url) . '</li>' . n . t . '<li>' . href(gTxt('view'), $url) . '</li>' . n . '</ul>', 35) . td(href(htmlspecialchars($linkname), $edit_url), 125) . td(htmlspecialchars($description), 150) . td('<span title="' . htmlspecialchars(fetch_category_title($category, 'link')) . '">' . $category . '</span>', 125) . td(gTime($uDate), 75) . td(fInput('checkbox', 'selected[]', $id)));
        }
        echo n . n . tr(tda(select_buttons() . link_multiedit_form($page, $sort, $dir, $crit, $search_method), ' colspan="7" style="text-align: right; border: none;"')) . endTable() . '</form>' . n . nav_form('link', $page, $numPages, $sort, $dir, $crit, $search_method, $total, $limit) . pageby_form('link', $link_list_pageby);
    }
}
Example #24
0
function image_list($message = '')
{
    global $txpcfg, $extensions, $img_dir, $file_max_upload_size, $image_list_pageby, $txp_user, $event;
    pagetop(gTxt('images'), $message);
    extract($txpcfg);
    extract(gpsa(array('page', 'sort', 'dir', 'crit', 'search_method')));
    if ($sort === '') {
        $sort = get_pref('image_sort_column', 'id');
    }
    if ($dir === '') {
        $dir = get_pref('image_sort_dir', 'desc');
    }
    $dir = $dir == 'asc' ? 'asc' : 'desc';
    echo '<div id="' . $event . '_control" class="txp-control-panel">';
    if (!is_dir(IMPATH) or !is_writeable(IMPATH)) {
        echo graf(gTxt('img_dir_not_writeable', array('{imgdir}' => IMPATH)), ' id="warning"');
    } elseif (has_privs('image.edit.own')) {
        echo upload_form(gTxt('upload_image'), 'upload_image', 'image_insert', 'image', '', $file_max_upload_size);
    }
    switch ($sort) {
        case 'name':
            $sort_sql = 'name ' . $dir;
            break;
        case 'thumbnail':
            $sort_sql = 'thumbnail ' . $dir . ', id asc';
            break;
        case 'category':
            $sort_sql = 'category ' . $dir . ', id asc';
            break;
        case 'date':
            $sort_sql = 'date ' . $dir . ', id asc';
            break;
        case 'author':
            $sort_sql = 'author ' . $dir . ', id asc';
            break;
        default:
            $sort = 'id';
            $sort_sql = 'id ' . $dir;
            break;
    }
    set_pref('image_sort_column', $sort, 'image', 2, '', 0, PREF_PRIVATE);
    set_pref('image_sort_dir', $dir, 'image', 2, '', 0, PREF_PRIVATE);
    $switch_dir = $dir == 'desc' ? 'asc' : 'desc';
    $criteria = 1;
    if ($search_method and $crit) {
        $crit_escaped = doSlash(str_replace(array('\\', '%', '_', '\''), array('\\\\', '\\%', '\\_', '\\\''), $crit));
        $critsql = array('id' => "ID in ('" . join("','", do_list($crit_escaped)) . "')", 'name' => "name like '%{$crit_escaped}%'", 'category' => "category like '%{$crit_escaped}%'", 'author' => "author like '%{$crit_escaped}%'", 'alt' => "alt like '%{$crit_escaped}%'", 'caption' => "caption like '%{$crit_escaped}%'");
        if (array_key_exists($search_method, $critsql)) {
            $criteria = $critsql[$search_method];
            $limit = 500;
        } else {
            $search_method = '';
            $crit = '';
        }
    } else {
        $search_method = '';
        $crit = '';
    }
    $total = safe_count('txp_image', "{$criteria}");
    if ($total < 1) {
        if ($criteria != 1) {
            echo n . image_search_form($crit, $search_method) . n . graf(gTxt('no_results_found'), ' class="indicator"') . '</div>';
        } else {
            echo n . graf(gTxt('no_images_recorded'), ' class="indicator"') . '</div>';
        }
        return;
    }
    $limit = max($image_list_pageby, 15);
    list($page, $offset, $numPages) = pager($total, $limit, $page);
    echo image_search_form($crit, $search_method);
    $rs = safe_rows_start('*, unix_timestamp(date) as uDate', 'txp_image', "{$criteria} order by {$sort_sql} limit {$offset}, {$limit}\n\t\t");
    echo pluggable_ui('image_ui', 'extend_controls', '', $rs);
    echo '</div>';
    // end txp-control-panel
    if ($rs) {
        $show_authors = !has_single_author('txp_image');
        echo n . '<div id="' . $event . '_container" class="txp-container txp-list">';
        echo n . n . '<form name="longform" id="images_form" method="post" action="index.php" onsubmit="return verify(\'' . gTxt('are_you_sure') . '\')">' . n . n . startTable('list', '', 'list') . n . '<thead>' . n . tr(column_head('ID', 'id', 'image', true, $switch_dir, $crit, $search_method, ('id' == $sort ? "{$dir} " : '') . 'id') . hCell('', '', ' class="actions"') . column_head('date', 'date', 'image', true, $switch_dir, $crit, $search_method, ('date' == $sort ? "{$dir} " : '') . 'date created') . column_head('name', 'name', 'image', true, $switch_dir, $crit, $search_method, ('name' == $sort ? "{$dir} " : '') . 'name') . column_head('thumbnail', 'thumbnail', 'image', true, $switch_dir, $crit, $search_method, ('thumbnail' == $sort ? "{$dir} " : '') . 'thumbnail') . hCell(gTxt('tags'), '', ' class="tag-build"') . column_head('image_category', 'category', 'image', true, $switch_dir, $crit, $search_method, ('category' == $sort ? "{$dir} " : '') . 'category') . ($show_authors ? column_head('author', 'author', 'image', true, $switch_dir, $crit, $search_method, ('author' == $sort ? "{$dir} " : '') . 'author') : '') . hCell('', '', ' class="multi-edit"')) . n . '</thead>';
        $tfoot = n . '<tfoot>' . tr(tda(select_buttons() . image_multiedit_form($page, $sort, $dir, $crit, $search_method), ' class="multi-edit" colspan="' . ($show_authors ? '9' : '8') . '" style="text-align: right; border: none;"')) . n . '</tfoot>';
        echo $tfoot;
        echo '<tbody>';
        $ctr = 1;
        while ($a = nextRow($rs)) {
            extract($a);
            $edit_url = '?event=image' . a . 'step=image_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="' . imagesrcurl($id, $ext, true) . "?{$uDate}" . '" alt="" ' . "title='{$id}{$ext} ({$w} &#215; {$h})'" . ($thumb_w ? "width='{$thumb_w}' height='{$thumb_h}'" : '') . ' />';
                } else {
                    $thumbnail = '';
                }
            } else {
                $thumbnail = gTxt('no');
            }
            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>' : '';
            $can_edit = has_privs('image.edit') || $author == $txp_user && has_privs('image.edit.own');
            echo n . n . tr(n . td($id, 20, 'id') . td(n . '<ul>' . ($can_edit ? n . t . '<li class="action-edit">' . href(gTxt('edit'), $edit_url) . '</li>' : '') . n . t . '<li class="action-view"><a href="' . imagesrcurl($id, $ext) . '">' . gTxt('view') . '</a></li>' . n . '</ul>', 35, 'actions') . td(gTime($uDate), 75, 'date created') . td($can_edit ? href($name, $edit_url) : $name, 75, 'name') . td(pluggable_ui('image_ui', 'thumbnail', $can_edit ? href($thumbnail, $edit_url) : $thumbnail, $a), 80, 'image thumbnail') . td($tagbuilder, 85, 'tag-build') . td($category, 75, 'category') . ($show_authors ? td('<span title="' . htmlspecialchars(get_author_name($author)) . '">' . htmlspecialchars($author) . '</span>', 75, 'author') : '') . td($can_edit ? fInput('checkbox', 'selected[]', $id) : '&nbsp;', 10, 'multi-edit'), ' class="' . ($ctr % 2 == 0 ? 'even' : 'odd') . '"');
            $ctr++;
        }
        echo '</tbody>' . n . endTable() . n . '</form>' . n . '<div id="' . $event . '_navigation" class="txp-navigation">' . nav_form('image', $page, $numPages, $sort, $dir, $crit, $search_method, $total, $limit) . pageby_form('image', $image_list_pageby) . n . '</div>' . n . '</div>';
    }
}
Example #25
0
function log_list($message = '')
{
    global $event, $log_list_pageby, $expire_logs_after;
    pagetop(gTxt('visitor_logs'), $message);
    extract(gpsa(array('page', 'sort', 'dir', 'crit', 'search_method')));
    if ($sort === '') {
        $sort = get_pref('log_sort_column', 'time');
    }
    if ($dir === '') {
        $dir = get_pref('log_sort_dir', 'desc');
    }
    $dir = $dir == 'asc' ? 'asc' : 'desc';
    $expire_logs_after = assert_int($expire_logs_after);
    safe_delete('txp_log', "time < date_sub(now(), interval {$expire_logs_after} day)");
    switch ($sort) {
        case 'ip':
            $sort_sql = 'ip ' . $dir;
            break;
        case 'host':
            $sort_sql = 'host ' . $dir;
            break;
        case 'page':
            $sort_sql = 'page ' . $dir;
            break;
        case 'refer':
            $sort_sql = 'refer ' . $dir;
            break;
        case 'method':
            $sort_sql = 'method ' . $dir;
            break;
        case 'status':
            $sort_sql = 'status ' . $dir;
            break;
        default:
            $sort = 'time';
            $sort_sql = 'time ' . $dir;
            break;
    }
    set_pref('log_sort_column', $sort, 'log', 2, '', 0, PREF_PRIVATE);
    set_pref('log_sort_dir', $dir, 'log', 2, '', 0, PREF_PRIVATE);
    $switch_dir = $dir == 'desc' ? 'asc' : 'desc';
    $criteria = 1;
    if ($search_method and $crit) {
        $crit_escaped = doSlash(str_replace(array('\\', '%', '_', '\''), array('\\\\', '\\%', '\\_', '\\\''), $crit));
        $critsql = array('ip' => "ip like '%{$crit_escaped}%'", 'host' => "host like '%{$crit_escaped}%'", 'page' => "page like '%{$crit_escaped}%'", 'refer' => "refer like '%{$crit_escaped}%'", 'method' => "method like '%{$crit_escaped}%'", 'status' => "status like '%{$crit_escaped}%'");
        if (array_key_exists($search_method, $critsql)) {
            $criteria = $critsql[$search_method];
            $limit = 500;
        } else {
            $search_method = '';
            $crit = '';
        }
    } else {
        $search_method = '';
        $crit = '';
    }
    $total = safe_count('txp_log', "{$criteria}");
    echo '<div id="' . $event . '_control" class="txp-control-panel">';
    if ($total < 1) {
        if ($criteria != 1) {
            echo n . log_search_form($crit, $search_method) . n . graf(gTxt('no_results_found'), ' class="indicator"') . '</div>';
        } else {
            echo graf(gTxt('no_refers_recorded'), ' class="indicator"') . '</div>';
        }
        return;
    }
    $limit = max($log_list_pageby, 15);
    list($page, $offset, $numPages) = pager($total, $limit, $page);
    echo n . log_search_form($crit, $search_method) . '</div>';
    $rs = safe_rows_start('*, unix_timestamp(time) as uTime', 'txp_log', "{$criteria} order by {$sort_sql} limit {$offset}, {$limit}");
    if ($rs) {
        echo n . '<div id="' . $event . '_container" class="txp-container txp-list">';
        echo n . n . '<form action="index.php" id="log_form" method="post" name="longform" onsubmit="return verify(\'' . gTxt('are_you_sure') . '\')">' . startTable('list', '', 'list', '', '90%') . n . '<thead>' . n . tr(n . column_head('time', 'time', 'log', true, $switch_dir, $crit, $search_method, ('time' == $sort ? "{$dir} " : '') . 'date time') . column_head('IP', 'ip', 'log', true, $switch_dir, $crit, $search_method, ('ip' == $sort ? "{$dir} " : '') . 'log_detail ip') . column_head('host', 'host', 'log', true, $switch_dir, $crit, $search_method, ('host' == $sort ? "{$dir} " : '') . 'host') . column_head('page', 'page', 'log', true, $switch_dir, $crit, $search_method, ('page' == $sort ? "{$dir} " : '') . 'page') . column_head('referrer', 'refer', 'log', true, $switch_dir, $crit, $search_method, ('refer' == $sort ? "{$dir} " : '') . 'refer') . column_head('method', 'method', 'log', true, $switch_dir, $crit, $search_method, ('method' == $sort ? "{$dir} " : '') . 'log_detail method') . column_head('status', 'status', 'log', true, $switch_dir, $crit, $search_method, ('status' == $sort ? "{$dir} " : '') . 'log_detail status') . hCell('', '', ' class="multi-edit"')) . n . '</thead>';
        $tfoot = n . '<tfoot>' . tr(tda(toggle_box('log_detail'), ' class="detail-toggle" colspan="2" style="text-align: left; border: none;"') . tda(select_buttons() . log_multiedit_form($page, $sort, $dir, $crit, $search_method), ' class="multi-edit" colspan="6" style="text-align: right; border: none;"')) . n . '</tfoot>';
        echo $tfoot;
        echo '<tbody>';
        $ctr = 1;
        while ($a = nextRow($rs)) {
            extract($a, EXTR_PREFIX_ALL, 'log');
            if ($log_refer) {
                $log_refer = 'http://' . $log_refer;
                $log_refer = '<a href="' . htmlspecialchars($log_refer) . '" target="_blank">' . htmlspecialchars(soft_wrap($log_refer, 30)) . '</a>';
            }
            if ($log_page) {
                $log_anchor = preg_replace('/\\/$/', '', $log_page);
                $log_anchor = soft_wrap(substr($log_anchor, 1), 30);
                $log_page = '<a href="' . htmlspecialchars($log_page) . '" target="_blank">' . htmlspecialchars($log_anchor) . '</a>';
                if ($log_method == 'POST') {
                    $log_page = '<strong>' . $log_page . '</strong>';
                }
            }
            echo tr(n . td(gTime($log_uTime), 85, 'date time') . td($log_ip, 20, 'log_detail ip') . td(soft_wrap($log_host, 30), '', 'host') . td($log_page, '', 'page') . td($log_refer, '', 'refer') . td(htmlspecialchars($log_method), 60, 'log_detail method') . td($log_status, 60, 'log_detail status') . td(fInput('checkbox', 'selected[]', $log_id), '', 'multi-edit'), ' class="' . ($ctr % 2 == 0 ? 'even' : 'odd') . '"');
            $ctr++;
        }
        echo '</tbody>' . n . endTable() . n . '</form>' . n . '<div id="' . $event . '_navigation" class="txp-navigation">' . n . nav_form('log', $page, $numPages, $sort, $dir, $crit, $search_method, $total, $limit) . n . pageby_form('log', $log_list_pageby) . n . '</div>' . n . '</div>';
    }
}
Example #26
0
function discuss_list($message = '')
{
    pagetop(gTxt('list_discussions'), $message);
    echo graf('<a href="index.php?event=discuss' . a . 'step=ipban_list">' . gTxt('list_banned_ips') . '</a>', ' style="text-align: center;"');
    extract(get_prefs());
    extract(gpsa(array('sort', 'dir', 'page', 'crit', 'search_method')));
    $dir = $dir == 'asc' ? 'asc' : 'desc';
    switch ($sort) {
        case 'id':
            $sort_sql = 'discussid ' . $dir;
            break;
        case 'ip':
            $sort_sql = 'ip ' . $dir . ', posted asc';
            break;
        case 'name':
            $sort_sql = 'name ' . $dir . ', posted asc';
            break;
        case 'email':
            $sort_sql = 'email ' . $dir . ', posted asc';
            break;
        case 'website':
            $sort_sql = 'web ' . $dir . ', posted asc';
            break;
        case 'message':
            $sort_sql = 'message ' . $dir . ', posted asc';
            break;
        case 'status':
            $sort_sql = "visible {$dir}, posted asc";
            break;
        case 'parent':
            $sort_sql = 'parentid ' . $dir . ', posted asc';
            break;
        default:
            $sort = 'date';
            $sort_sql = 'posted ' . $dir;
            break;
    }
    $switch_dir = $dir == 'desc' ? 'asc' : 'desc';
    $criteria = 1;
    if ($search_method and $crit) {
        $crit_escaped = doSlash($crit);
        $critsql = array('id' => "discussid = '{$crit_escaped}'", 'parent' => "parentid = '{$crit_escaped}'", 'name' => "name like '%{$crit_escaped}%'", 'message' => "message like '%{$crit_escaped}%'", 'email' => "email like '%{$crit_escaped}%'", 'website' => "web like '%{$crit_escaped}%'", 'ip' => "ip like '%{$crit_escaped}%'");
        if (array_key_exists($search_method, $critsql)) {
            $criteria = $critsql[$search_method];
            $limit = 500;
        } else {
            $search_method = '';
            $crit = '';
        }
    } else {
        $search_method = '';
        $crit = '';
    }
    $total = safe_count('txp_discuss', "{$criteria}");
    if ($total < 1) {
        if ($criteria != 1) {
            echo n . discuss_search_form($crit, $search_method) . n . graf(gTxt('no_results_found'), ' style="text-align: center;"');
        } else {
            echo graf(gTxt('no_comments_recorded'), ' style="text-align: center;"');
        }
        return;
    }
    $limit = max(@$comment_list_pageby, 15);
    list($page, $offset, $numPages) = pager($total, $limit, $page);
    echo discuss_search_form($crit, $search_method);
    $spamq = cs('toggle_show_spam') ? '1=1' : 'visible != ' . intval(SPAM);
    $rs = safe_rows_start('*, unix_timestamp(posted) as uPosted', 'txp_discuss', "{$spamq} and {$criteria} order by {$sort_sql} limit {$offset}, {$limit}");
    if ($rs) {
        echo n . n . '<form name="longform" method="post" action="index.php" onsubmit="return verify(\'' . gTxt('are_you_sure') . '\')">' . n . startTable('list', '', '', '', '90%') . n . n . tr(column_head('ID', 'id', 'discuss', true, $switch_dir, $crit, $search_method, 'id' == $sort ? $dir : '') . column_head('date', 'date', 'discuss', true, $switch_dir, $crit, $search_method, 'date' == $sort ? $dir : '') . column_head('name', 'name', 'discuss', true, $switch_dir, $crit, $search_method, 'name' == $sort ? $dir : '') . column_head('message', 'message', 'discuss', true, $switch_dir, $crit, $search_method, 'message' == $sort ? $dir : '') . column_head('email', 'email', 'discuss', true, $switch_dir, $crit, $search_method, ('email' == $sort ? "{$dir} " : '') . 'discuss_detail') . column_head('website', 'website', 'discuss', true, $switch_dir, $crit, $search_method, ('website' == $sort ? "{$dir} " : '') . 'discuss_detail') . column_head('IP', 'ip', 'discuss', true, $switch_dir, $crit, $search_method, ('ip' == $sort ? "{$dir} " : '') . 'discuss_detail') . column_head('status', 'status', 'discuss', true, $switch_dir, $crit, $search_method, ('status' == $sort ? "{$dir} " : '') . 'discuss_detail') . column_head('parent', 'parent', 'discuss', true, $switch_dir, $crit, $search_method, 'parent' == $sort ? $dir : '') . hCell());
        include_once txpath . '/publish/taghandlers.php';
        while ($a = nextRow($rs)) {
            extract($a);
            $parentid = assert_int($parentid);
            $tq = safe_row('*, ID as thisid, unix_timestamp(Posted) as posted', 'textpattern', "ID = {$parentid}");
            $edit_url = '?event=discuss' . a . 'step=discuss_edit' . a . 'discussid=' . $discussid . a . 'sort=' . $sort . a . 'dir=' . $dir . a . 'page=' . $page . a . 'search_method=' . $search_method . a . 'crit=' . $crit;
            $dmessage = $visible == SPAM ? short_preview($message) : $message;
            switch ($visible) {
                case VISIBLE:
                    $comment_status = gTxt('visible');
                    $row_class = 'visible';
                    break;
                case SPAM:
                    $comment_status = gTxt('spam');
                    $row_class = 'spam';
                    break;
                case MODERATE:
                    $comment_status = gTxt('unmoderated');
                    $row_class = 'moderate';
                    break;
                default:
                    break;
            }
            if (empty($tq)) {
                $parent = gTxt('article_deleted') . ' (' . $parentid . ')';
                $view = '';
            } else {
                $parent_title = empty($tq['Title']) ? '<em>' . gTxt('untitled') . '</em>' : escape_title($tq['Title']);
                $parent = href($parent_title, '?event=list' . a . 'step=list' . a . 'search_method=id' . a . 'crit=' . $tq['ID']);
                $view = '';
                if ($visible == VISIBLE and in_array($tq['Status'], array(4, 5))) {
                    $view = n . t . '<li><a href="' . permlinkurl($tq) . '#c' . $discussid . '">' . gTxt('view') . '</a></li>';
                }
            }
            echo n . n . tr(n . td('<a href="' . $edit_url . '">' . $discussid . '</a>' . n . '<ul class="discuss_detail">' . n . t . '<li><a href="' . $edit_url . '">' . gTxt('edit') . '</a></li>' . $view . n . '</ul>', 50) . td(gTime($uPosted)) . td(htmlspecialchars(soft_wrap($name, 15))) . td(short_preview($dmessage)) . td(htmlspecialchars(soft_wrap($email, 15)), '', 'discuss_detail') . td(htmlspecialchars(soft_wrap($web, 15)), '', 'discuss_detail') . td($ip, '', 'discuss_detail') . td($comment_status, '', 'discuss_detail') . td($parent) . td(fInput('checkbox', 'selected[]', $discussid)), ' class="' . $row_class . '"');
        }
        echo tr(tda(toggle_box('discuss_detail'), ' colspan="2" style="text-align: left; border: none;"') . tda(select_buttons() . discuss_multiedit_form($page, $sort, $dir, $crit, $search_method), ' colspan="9" style="text-align: right; border: none;"')) . endTable() . '</form>' . n . tag(cookie_box('show_spam'), 'div', ' style="margin:auto;padding:0 0 0 10px; width:90%"') . nav_form('discuss', $page, $numPages, $sort, $dir, $crit, $search_method) . pageby_form('discuss', $comment_list_pageby);
    }
}