': ', ), $atts)); $out = htmlspecialchars($sitename.$separator); if ($parentid) { $parent_id = (int) $parent_id; $out .= gTxt('comments_on').' '.escape_title(safe_field('Title', 'textpattern', "ID = $parentid")); } elseif ($thisarticle['title']) { $out .= escape_title($thisarticle['title']); } elseif ($q) { $out .= gTxt('search_results').htmlspecialchars($separator.$q); } elseif ($c) { $out .= htmlspecialchars(fetch_category_title($c)); } elseif ($s and $s != 'default') { $out .= htmlspecialchars(fetch_section_title($s)); } elseif ($pg) { $out .= gTxt('page').' '.$pg; } else { $out = htmlspecialchars($sitename); } return $out; } // ------------------------------------------------------------- function css($atts) { global $css; extract(lAtts(array( 'format' => 'url', 'media' => 'screen', 'n' => $css, 'rel' => 'stylesheet', 'title' => '', ), $atts)); if (empty($n)) $n = 'default'; $url = hu.'textpattern/css.php?n='.$n; if ($format == 'link') { return ''; } return $url; } // ------------------------------------------------------------- function image($atts) { global $img_dir; static $cache = array(); extract(lAtts(array( 'align' => '', // remove in crockery 'class' => '', 'escape' => 'html', 'html_id' => '', 'id' => '', 'name' => '', 'style' => '', // remove in crockery? 'wraptag' => '', ), $atts)); if ($name) { if (isset($cache['n'][$name])) { $rs = $cache['n'][$name]; } else { $name = doSlash($name); $rs = safe_row('*', 'txp_image', "name = '$name' limit 1"); $cache['n'][$name] = $rs; } } elseif ($id) { if (isset($cache['i'][$id])) { $rs = $cache['i'][$id]; } else { $id = (int) $id; $rs = safe_row('*', 'txp_image', "id = $id limit 1"); $cache['i'][$id] = $rs; } } else { trigger_error(gTxt('unknown_image')); return; } if ($rs) { extract($rs); if ($escape == 'html') { $alt = htmlspecialchars($alt); $caption = htmlspecialchars($caption); } $out = ''.$alt.''; return ($wraptag) ? doTag($out, $wraptag, $class, '', $html_id) : $out; } trigger_error(gTxt('unknown_image')); } // ------------------------------------------------------------- function thumbnail($atts) { global $img_dir; extract(lAtts(array( 'align' => '', // remove in crockery 'class' => '', 'escape' => 'html', 'html_id' => '', 'id' => '', 'link' => 0, 'link_rel' => '', 'name' => '', 'poplink' => 0, // remove in crockery 'style' => '', // remove in crockery 'wraptag' => '' ), $atts)); if ($name) { $name = doSlash($name); $rs = safe_row('*', 'txp_image', "name = '$name' limit 1"); } elseif ($id) { $id = (int) $id; $rs = safe_row('*', 'txp_image', "id = $id limit 1"); } else { trigger_error(gTxt('unknown_image')); return; } if ($rs) { extract($rs); if ($thumbnail) { if ($escape == 'html') { $alt = htmlspecialchars($alt); $caption = htmlspecialchars($caption); } $out = ''.$alt.''; if ($link) { $out = href($out, hu.$img_dir.'/'.$id.$ext, (!empty($link_rel) ? " rel='$link_rel'" : '')." title='$caption'"); } elseif ($poplink) { $out = ''.$out.''; } return ($wraptag) ? doTag($out, $wraptag, $class, '', $html_id) : $out; } } trigger_error(gTxt('unknown_image')); } // ------------------------------------------------------------- function output_form($atts) { extract(lAtts(array( 'form' => '', ), $atts)); if (!$form) trigger_error(gTxt('form_not_specified')); else return parse_form($form); } // ------------------------------------------------------------- function feed_link($atts, $thing = NULL) { global $s, $c; extract(lAtts(array( 'category' => $c, 'flavor' => 'rss', 'format' => 'a', 'label' => '', 'limit' => '', 'section' => ( $s == 'default' ? '' : $s), 'title' => gTxt('rss_feed_title'), 'wraptag' => '', ), $atts)); $url = pagelinkurl(array( $flavor => '1', 'section' => $section, 'category' => $category, 'limit' => $limit )); if ($flavor == 'atom') { $title = ($title == gTxt('rss_feed_title')) ? gTxt('atom_feed_title') : $title; } $title = htmlspecialchars($title); if ($format == 'link') { $type = ($flavor == 'atom') ? 'application/atom+xml' : 'application/rss+xml'; return ''; } $txt = ($thing === NULL ? $label : parse($thing)); $out = ''.$txt.''; return ($wraptag) ? tag($out, $wraptag) : $out; } // ------------------------------------------------------------- function link_feed_link($atts) { global $c; extract(lAtts(array( 'category' => $c, 'flavor' => 'rss', 'format' => 'a', 'label' => '', 'title' => gTxt('rss_feed_title'), 'wraptag' => '', ), $atts)); $url = pagelinkurl(array( $flavor => '1', 'area' =>'link', 'c' => $category )); if ($flavor == 'atom') { $title = ($title == gTxt('rss_feed_title')) ? gTxt('atom_feed_title') : $title; } $title = htmlspecialchars($title); if ($format == 'link') { $type = ($flavor == 'atom') ? 'application/atom+xml' : 'application/rss+xml'; return ''; } $out = ''.$label.''; return ($wraptag) ? tag($out, $wraptag) : $out; } // ------------------------------------------------------------- function linklist($atts, $thing = NULL) { global $thislink; extract(lAtts(array( 'break' => '', 'category' => '', 'class' => __FUNCTION__, 'form' => 'plainlinks', 'label' => '', 'labeltag' => '', 'limit' => 0, 'offset' => 0, 'sort' => 'linksort asc', 'wraptag' => '', ), $atts)); $qparts = array( ($category) ? "category IN ('".join("','", doSlash(do_list($category)))."')" : '1=1', 'order by '.doSlash($sort), ($limit) ? 'limit '.intval($offset).', '.intval($limit) : '' ); $rs = safe_rows_start('*, unix_timestamp(date) as uDate', 'txp_link', join(' ', $qparts)); if ($rs) { $out = array(); while ($a = nextRow($rs)) { extract($a); $thislink = array( 'id' => $id, 'linkname' => $linkname, 'url' => $url, 'description' => $description, 'date' => $uDate, 'category' => $category, ); $out[] = ($thing) ? parse($thing) : parse_form($form); $thislink = ''; } if ($out) { return doLabel($label, $labeltag).doWrap($out, $wraptag, $break, $class); } } return false; } // ------------------------------------------------------------- function tpt_link($atts) { global $thislink; assert_link(); extract(lAtts(array( 'rel' => '', ), $atts)); return tag( htmlspecialchars($thislink['linkname']), 'a', ($rel ? ' rel="'.$rel.'"' : ''). ' href="'.doSpecial($thislink['url']).'"' ); } // ------------------------------------------------------------- function linkdesctitle($atts) { global $thislink; assert_link(); extract(lAtts(array( 'rel' => '', ), $atts)); $description = ($thislink['description']) ? ' title="'.htmlspecialchars($thislink['description']).'"' : ''; return tag( htmlspecialchars($thislink['linkname']), 'a', ($rel ? ' rel="'.$rel.'"' : ''). ' href="'.doSpecial($thislink['url']).'"'.$description ); } // ------------------------------------------------------------- function link_name($atts) { global $thislink; assert_link(); extract(lAtts(array( 'escape' => 'html', ), $atts)); return ($escape == 'html') ? htmlspecialchars($thislink['linkname']) : $thislink['linkname']; } // ------------------------------------------------------------- function link_url() { global $thislink; assert_link(); return doSpecial($thislink['url']); } // ------------------------------------------------------------- function link_description($atts) { global $thislink; assert_link(); extract(lAtts(array( 'class' => '', 'escape' => 'html', 'label' => '', 'labeltag' => '', 'wraptag' => '', ), $atts)); if ($thislink['description']) { $description = ($escape == 'html') ? htmlspecialchars($thislink['description']) : $thislink['description']; return doLabel($label, $labeltag).doTag($description, $wraptag, $class); } } // ------------------------------------------------------------- function link_date($atts) { global $thislink, $dateformat; assert_link(); extract(lAtts(array( 'format' => $dateformat, 'gmt' => '', 'lang' => '', ), $atts)); return safe_strftime($format, $thislink['date'], $gmt, $lang); } // ------------------------------------------------------------- function link_category($atts) { global $thislink; assert_link(); extract(lAtts(array( 'class' => '', 'label' => '', 'labeltag' => '', 'title' => 0, 'wraptag' => '', ), $atts)); if ($thislink['category']) { $category = ($title) ? fetch_category_title($thislink['category'], 'link') : $thislink['category']; return doLabel($label, $labeltag).doTag($category, $wraptag, $class); } } // ------------------------------------------------------------- function eE($txt) // convert email address into unicode entities { for ($i=0;$i '', 'linktext' => gTxt('contact'), 'title' => '', ),$atts)); if($email) { $out = array( '', ($thing) ? parse($thing) : $linktext, '' ); return join('',$out); } return ''; } // ------------------------------------------------------------- function password_protect($atts) { ob_start(); extract(lAtts(array( 'login' => '', 'pass' => '', ),$atts)); $au = serverSet('PHP_AUTH_USER'); $ap = serverSet('PHP_AUTH_PW'); //For php as (f)cgi, two rules in htaccess often allow this workaround $ru = serverSet('REDIRECT_REMOTE_USER'); if ($ru && !$au && !$ap && substr( $ru,0,5) == 'Basic' ) { list ( $au, $ap ) = explode( ':', base64_decode( substr( $ru,6))); } if ($login && $pass) { if (!$au || !$ap || $au!= $login || $ap!= $pass) { header('WWW-Authenticate: Basic realm="Private"'); txp_die(gTxt('auth_required'), '401'); } } } // ------------------------------------------------------------- function recent_articles($atts) { global $prefs; extract(lAtts(array( 'break' => br, 'category' => '', 'class' => __FUNCTION__, 'label' => gTxt('recent_articles'), 'labeltag' => '', 'limit' => 10, 'section' => '', 'sort' => 'Posted desc', 'sortby' => '', 'sortdir' => '', 'wraptag' => '', 'no_widow' => @$prefs['title_no_widow'], ), $atts)); // for backwards compatibility // sortby and sortdir are deprecated if ($sortby) { if (!$sortdir) { $sortdir = 'desc'; } $sort = "$sortby $sortdir"; } elseif ($sortdir) { $sort = "Posted $sortdir"; } $category = join("','", doSlash(do_list($category))); $categories = ($category) ? "and (Category1 IN ('".$category."') or Category2 IN ('".$category."'))" : ''; $section = ($section) ? " and Section IN ('".join("','", doSlash(do_list($section)))."')" : ''; $expired = ($prefs['publish_expired_articles']) ? '' : ' and (now() <= Expires or Expires = '.NULLDATETIME.') '; $rs = safe_rows_start('*, id as thisid, unix_timestamp(Posted) as posted', 'textpattern', "Status = 4 $section $categories and Posted <= now()$expired order by ".doSlash($sort).' limit 0,'.intval($limit)); if ($rs) { $out = array(); while ($a = nextRow($rs)) { $a['Title'] = ($no_widow) ? noWidow(escape_title($a['Title'])) : escape_title($a['Title']); $out[] = href($a['Title'], permlinkurl($a)); } if ($out) { return doLabel($label, $labeltag).doWrap($out, $wraptag, $break, $class); } } return ''; } // ------------------------------------------------------------- function recent_comments($atts, $thing = NULL) { global $prefs; global $thisarticle, $thiscomment; extract(lAtts(array( 'break' => br, 'class' => __FUNCTION__, 'form' => '', 'label' => '', 'labeltag' => '', 'limit' => 10, 'offset' => 0, 'sort' => 'posted desc', 'wraptag' => '', ), $atts)); $sort = preg_replace('/\bposted\b/', 'd.posted', $sort); $expired = ($prefs['publish_expired_articles']) ? '' : ' and (now() <= t.Expires or t.Expires = '.NULLDATETIME.') '; $rs = startRows('select d.name, d.email, d.web, d.message, d.discussid, unix_timestamp(d.Posted) as time, '. 't.ID as thisid, unix_timestamp(t.Posted) as posted, t.Title as title, t.Section as section, t.url_title '. 'from '. safe_pfx('txp_discuss') .' as d inner join '. safe_pfx('textpattern') .' as t on d.parentid = t.ID '. 'where t.Status >= 4'.$expired.' and d.visible = '.VISIBLE.' order by '.doSlash($sort).' limit '.intval($offset).','.intval($limit)); if ($rs) { $out = array(); $old_article = $thisarticle; while ($c = nextRow($rs)) { if (empty($form) && empty($thing)) { $out[] = href( htmlspecialchars($c['name']).' ('.htmlspecialchars($c['title']).')', permlinkurl($c).'#c'.$c['discussid'] ); } else { $thiscomment['name'] = $c['name']; $thiscomment['email'] = $c['email']; $thiscomment['web'] = $c['web']; $thiscomment['message'] = $c['message']; $thiscomment['discussid'] = $c['discussid']; $thiscomment['time'] = $c['time']; // allow permlink guesstimation in permlinkurl(), elsewhere $thisarticle['ID'] = $c['thisid']; $thisarticle['posted'] = $c['posted']; $thisarticle['title'] = $c['title']; $thisarticle['section'] = $c['section']; $thisarticle['url_title'] = $c['url_title']; $out[] = ($thing) ? parse($thing) : parse_form($form); } } if ($out) { unset($GLOBALS['thiscomment']); $thisarticle = $old_article; return doLabel($label, $labeltag).doWrap($out, $wraptag, $break, $class); } } return ''; } // ------------------------------------------------------------- function related_articles($atts, $thing = NULL) { global $thisarticle, $prefs; assert_article(); extract(lAtts(array( 'break' => br, 'class' => __FUNCTION__, 'form' => '', 'label' => '', 'labeltag' => '', 'limit' => 10, 'match' => 'Category1,Category2', 'no_widow' => @$prefs['title_no_widow'], 'section' => '', 'sort' => 'Posted desc', 'wraptag' => '', ), $atts)); if (empty($thisarticle['category1']) and empty($thisarticle['category2'])) { return; } $match = do_list($match); if (!in_array('Category1', $match) and !in_array('Category2', $match)) { return; } $id = $thisarticle['thisid']; $cats = array(); if ($thisarticle['category1']) { $cats[] = doSlash($thisarticle['category1']); } if ($thisarticle['category2']) { $cats[] = doSlash($thisarticle['category2']); } $cats = join("','", $cats); $categories = array(); if (in_array('Category1', $match)) { $categories[] = "Category1 in('$cats')"; } if (in_array('Category2', $match)) { $categories[] = "Category2 in('$cats')"; } $categories = 'and ('.join(' or ', $categories).')'; $section = ($section) ? " and Section IN ('".join("','", doSlash(do_list($section)))."')" : ''; $expired = ($prefs['publish_expired_articles']) ? '' : ' and (now() <= Expires or Expires = '.NULLDATETIME.') '; $rs = safe_rows_start('*, unix_timestamp(Posted) as posted, unix_timestamp(LastMod) as uLastMod, unix_timestamp(Expires) as uExpires', 'textpattern', 'ID != '.intval($id)." and Status = 4 $expired and Posted <= now() $categories $section order by ".doSlash($sort).' limit 0,'.intval($limit)); if ($rs) { $out = array(); $old_article = $thisarticle; while ($a = nextRow($rs)) { $a['Title'] = ($no_widow) ? noWidow(escape_title($a['Title'])) : escape_title($a['Title']); $a['uPosted'] = $a['posted']; // populateArticleData() and permlinkurl() assume quite a bunch of posting dates... if (empty($form) && empty($thing)) { $out[] = href($a['Title'], permlinkurl($a)); } else { populateArticleData($a); $out[] = ($thing) ? parse($thing) : parse_form($form); } } $thisarticle = $old_article; if ($out) { return doLabel($label, $labeltag).doWrap($out, $wraptag, $break, $class); } } return ''; } // ------------------------------------------------------------- function popup($atts) { global $s, $c; extract(lAtts(array( 'label' => gTxt('browse'), 'wraptag' => '', 'section' => '', 'this_section' => 0, 'type' => 'c', ), $atts)); if ($type == 's') { $rs = safe_rows_start('name, title', 'txp_section', "name != 'default' order by name"); } else { $rs = safe_rows_start('name, title', 'txp_category', "type = 'article' and name != 'root' order by name"); } if ($rs) { $out = array(); $current = ($type == 's') ? $s : $c; $sel = ''; $selected = false; while ($a = nextRow($rs)) { extract($a); if ($name == $current) { $sel = ' selected="selected"'; $selected = true; } $out[] = ''; $sel = ''; } if ($out) { $section = ($this_section) ? ( $s == 'default' ? '' : $s) : $section; $out = n.''; if ($label) { $out = $label.br.$out; } if ($wraptag) { $out = tag($out, $wraptag); } return '
'. '
'. ( ($type != 's' and $section and $s) ? n.hInput('s', $section) : ''). n.$out. n.''. n.'
'. n.'
'; } } } // ------------------------------------------------------------- // output href list of site categories function category_list($atts, $thing = NULL) { global $s, $c, $thiscategory; extract(lAtts(array( 'active_class' => '', 'break' => br, 'categories' => '', 'class' => __FUNCTION__, 'exclude' => '', 'form' => '', 'label' => '', 'labeltag' => '', 'parent' => '', 'section' => '', 'children' => '1', 'sort' => '', 'this_section' => 0, 'type' => 'article', 'wraptag' => '', ), $atts)); $sort = doSlash($sort); if ($categories) { $categories = do_list($categories); $categories = join("','", doSlash($categories)); $rs = safe_rows_start('name, title', 'txp_category', "type = '".doSlash($type)."' and name in ('$categories') order by ".($sort ? $sort : "field(name, '$categories')")); } else { if ($children) { $shallow = ''; } else { // descend only one level from either 'parent' or 'root', plus parent category $shallow = ($parent) ? "and (parent = '".doSlash($parent)."' or name = '".doSlash($parent)."')" : "and parent = 'root'" ; } if ($exclude) { $exclude = do_list($exclude); $exclude = join("','", doSlash($exclude)); $exclude = "and name not in('$exclude')"; } if ($parent) { $qs = safe_row('lft, rgt', 'txp_category', "type = '".doSlash($type)."' and name = '".doSlash($parent)."'"); if ($qs) { extract($qs); $rs = safe_rows_start('name, title', 'txp_category', "(lft between $lft and $rgt) and type = '".doSlash($type)."' and name != 'default' $exclude $shallow order by ".($sort ? $sort : 'lft ASC')); } } else { $rs = safe_rows_start('name, title', 'txp_category', "type = '".doSlash($type)."' and name not in('default','root') $exclude $shallow order by ".($sort ? $sort : 'name ASC')); } } if ($rs) { $out = array(); $count = 0; $last = numRows($rs); if (isset($thiscategory)) $old_category = $thiscategory; while ($a = nextRow($rs)) { ++$count; extract($a); if ($name) { $section = ($this_section) ? ( $s == 'default' ? '' : $s ) : $section; if (empty($form) && empty($thing)) { $out[] = tag(htmlspecialchars($title), 'a', ( ($active_class and (0 == strcasecmp($c, $name))) ? ' class="'.$active_class.'"' : '' ). ' href="'.pagelinkurl(array('s' => $section, 'c' => $name)).'"' ); } else { $thiscategory = array('name' => $name, 'title' => $title, 'type' => $type); $thiscategory['is_first'] = ($count == 1); $thiscategory['is_last'] = ($count == $last); $out[] = ($thing) ? parse($thing) : parse_form($form); } } } $thiscategory = (isset($old_category) ? $old_category : NULL); if ($out) { return doLabel($label, $labeltag).doWrap($out, $wraptag, $break, $class); } } return ''; } // ------------------------------------------------------------- // output href list of site sections function section_list($atts, $thing = NULL) { global $sitename, $s, $thissection; extract(lAtts(array( 'active_class' => '', 'break' => br, 'class' => __FUNCTION__, 'default_title' => $sitename, 'exclude' => '', 'form' => '', 'include_default' => '', 'label' => '', 'labeltag' => '', 'sections' => '', 'sort' => '', 'wraptag' => '', ), $atts)); $sort = doSlash($sort); $rs = array(); if ($sections) { $sections = do_list($sections); $sections = join("','", doSlash($sections)); $rs = safe_rows('name, title', 'txp_section', "name in ('$sections') order by ".($sort ? $sort : "field(name, '$sections')")); } else { if ($exclude) { $exclude = do_list($exclude); $exclude = join("','", doSlash($exclude)); $exclude = "and name not in('$exclude')"; } $rs = safe_rows('name, title', 'txp_section', "name != 'default' $exclude order by ".($sort ? $sort : 'name ASC')); } if ($include_default) { array_unshift($rs, array('name' => 'default', 'title' => $default_title)); } if ($rs) { $out = array(); $count = 0; $last = count($rs); if (isset($thissection)) $old_section = $thissection; foreach ($rs as $a) { ++$count; extract($a); if (empty($form) && empty($thing)) { $url = pagelinkurl(array('s' => $name)); $out[] = tag(htmlspecialchars($title), 'a', ( ($active_class and (0 == strcasecmp($s, $name))) ? ' class="'.$active_class.'"' : '' ). ' href="'.$url.'"' ); } else { $thissection = array('name' => $name, 'title' => ($name == 'default') ? $default_title : $title); $thissection['is_first'] = ($count == 1); $thissection['is_last'] = ($count == $last); $out[] = ($thing) ? parse($thing) : parse_form($form); } } $thissection = (isset($old_section) ? $old_section : NULL); if ($out) { return doLabel($label, $labeltag).doWrap($out, $wraptag, $break, $class); } } return ''; } // ------------------------------------------------------------- function search_input($atts) // input form for search queries { global $q, $permlink_mode; extract(lAtts(array( 'form' => 'search_input', 'wraptag' => 'p', 'size' => '15', 'html_id' => '', 'label' => gTxt('search'), 'button' => '', 'section' => '', ),$atts)); if ($form) { $rs = fetch('form','txp_form','name',$form); if ($rs) { return parse($rs); } } $sub = (!empty($button)) ? '' : ''; $id = (!empty($html_id)) ? ' id="'.$html_id.'"' : ''; $out = fInput('text','q',$q,'','','',$size); $out = (!empty($label)) ? $label.br.$out.$sub : $out.$sub; $out = ($wraptag) ? tag($out,$wraptag) : $out; if (!$section) { return '
'. n.$out. n.'
'; } if ($permlink_mode != 'messy') { return '
'. n.$out. n.'
'; } return '
'. n.hInput('s', $section). n.$out. n.'
'; } // ------------------------------------------------------------- function search_term($atts) { global $q; if(empty($q)) return ''; extract(lAtts(array( 'escape' => 'html' ),$atts)); return ($escape == 'html' ? htmlspecialchars($q) : $q); } // ------------------------------------------------------------- // link to next article, if it exists function link_to_next($atts, $thing = NULL) { global $id, $next_id, $next_title; extract(lAtts(array( 'showalways' => 0, ), $atts)); if (intval($id) == 0) { global $thisarticle, $s; assert_article(); extract(getNextPrev( @$thisarticle['thisid'], @strftime('%Y-%m-%d %H:%M:%S', $thisarticle['posted']), @$s )); } if ($next_id) { $url = permlinkurl_id($next_id); if ($thing) { $thing = parse($thing); $next_title = escape_title($next_title); return ''; } return $url; } return ($showalways) ? parse($thing) : ''; } // ------------------------------------------------------------- // link to next article, if it exists function link_to_prev($atts, $thing = NULL) { global $id, $prev_id, $prev_title; extract(lAtts(array( 'showalways' => 0, ), $atts)); if (intval($id) == 0) { global $thisarticle, $s; assert_article(); extract(getNextPrev( $thisarticle['thisid'], @strftime('%Y-%m-%d %H:%M:%S', $thisarticle['posted']), @$s )); } if ($prev_id) { $url = permlinkurl_id($prev_id); if ($thing) { $thing = parse($thing); $prev_title = escape_title($prev_title); return ''; } return $url; } return ($showalways) ? parse($thing) : ''; } // ------------------------------------------------------------- function next_title() { return escape_title($GLOBALS['next_title']); } // ------------------------------------------------------------- function prev_title() { return escape_title($GLOBALS['prev_title']); } // ------------------------------------------------------------- function site_name() { return htmlspecialchars($GLOBALS['sitename']); } // ------------------------------------------------------------- function site_slogan() { return htmlspecialchars($GLOBALS['site_slogan']); } // ------------------------------------------------------------- function link_to_home($atts, $thing = NULL) { extract(lAtts(array( 'class' => false, ), $atts)); if ($thing) { $class = ($class) ? ' class="'.$class.'"' : ''; return ''.parse($thing).''; } return hu; } // ------------------------------------------------------------- function newer($atts, $thing = NULL) { global $thispage, $pretext, $permlink_mode; extract(lAtts(array( 'showalways' => 0, ), $atts)); $numPages = $thispage['numPages']; $pg = $thispage['pg']; if ($numPages > 1 and $pg > 1 and $pg <= $numPages) { $nextpg = ($pg - 1 == 1) ? 0 : ($pg - 1); // author urls should use RealName, rather than username if (!empty($pretext['author'])) { $author = safe_field('RealName', 'txp_users', "name = '".doSlash($pretext['author'])."'"); } else { $author = ''; } $url = pagelinkurl(array( 'month' => @$pretext['month'], 'pg' => $nextpg, 's' => @$pretext['s'], 'c' => @$pretext['c'], 'q' => @$pretext['q'], 'author' => $author )); if ($thing) { return ''.parse($thing).''; } return $url; } return ($showalways) ? parse($thing) : ''; } // ------------------------------------------------------------- function older($atts, $thing = NULL) { global $thispage, $pretext, $permlink_mode; extract(lAtts(array( 'showalways' => 0, ), $atts)); $numPages = $thispage['numPages']; $pg = $thispage['pg']; if ($numPages > 1 and $pg > 0 and $pg < $numPages) { $nextpg = $pg + 1; // author urls should use RealName, rather than username if (!empty($pretext['author'])) { $author = safe_field('RealName', 'txp_users', "name = '".doSlash($pretext['author'])."'"); } else { $author = ''; } $url = pagelinkurl(array( 'month' => @$pretext['month'], 'pg' => $nextpg, 's' => @$pretext['s'], 'c' => @$pretext['c'], 'q' => @$pretext['q'], 'author' => $author )); if ($thing) { return ''.parse($thing).''; } return $url; } return ($showalways) ? parse($thing) : ''; } // ------------------------------------------------------------- function text($atts) { extract(lAtts(array( 'item' => '', ),$atts)); return ($item) ? gTxt($item) : ''; } // ------------------------------------------------------------- function article_id() { global $thisarticle; assert_article(); return $thisarticle['thisid']; } // ------------------------------------------------------------- function article_url_title() { global $thisarticle; assert_article(); return $thisarticle['url_title']; } // ------------------------------------------------------------- function if_article_id($atts, $thing) { global $thisarticle, $pretext; assert_article(); extract(lAtts(array( 'id' => $pretext['id'], ), $atts)); if ($id) { return parse(EvalElse($thing, in_list($thisarticle['thisid'], $id))); } } // ------------------------------------------------------------- function posted($atts) { global $thisarticle, $id, $c, $pg, $dateformat, $archive_dateformat; assert_article(); extract(lAtts(array( 'class' => '', 'format' => '', 'gmt' => '', 'lang' => '', 'wraptag' => '' ), $atts)); if ($format) { $out = safe_strftime($format, $thisarticle['posted'], $gmt, $lang); } else { if ($id or $c or $pg) { $out = safe_strftime($archive_dateformat, $thisarticle['posted']); } else { $out = safe_strftime($dateformat, $thisarticle['posted']); } } return ($wraptag) ? doTag($out, $wraptag, $class) : $out; } // ------------------------------------------------------------- function expires($atts) { global $thisarticle, $id, $c, $pg, $dateformat, $archive_dateformat; assert_article(); if($thisarticle['expires'] == 0) { return; } extract(lAtts(array( 'class' => '', 'format' => '', 'gmt' => '', 'lang' => '', 'wraptag' => '', ), $atts)); if ($format) { $out = safe_strftime($format, $thisarticle['expires'], $gmt, $lang); } else { if ($id or $c or $pg) { $out = safe_strftime($archive_dateformat, $thisarticle['expires']); } else { $out = safe_strftime($dateformat, $thisarticle['expires']); } } return ($wraptag) ? doTag($out, $wraptag, '', $class) : $out; } // ------------------------------------------------------------- function if_expires($atts, $thing) { global $thisarticle; assert_article(); return parse(EvalElse($thing, $thisarticle['expires'])); } // ------------------------------------------------------------- function if_expired($atts, $thing) { global $thisarticle; assert_article(); return parse(EvalElse($thing, $thisarticle['expires'] && ($thisarticle['expires'] <= time() ))); } // ------------------------------------------------------------- function modified($atts) { global $thisarticle, $id, $c, $pg, $dateformat, $archive_dateformat; assert_article(); extract(lAtts(array( 'format' => '', 'gmt' => '', 'lang' => '' ), $atts)); if ($format) { return safe_strftime($format, $thisarticle['modified'], $gmt, $lang); } else { if ($id or $c or $pg) { return safe_strftime($archive_dateformat, $thisarticle['modified']); } else { return safe_strftime($dateformat, $thisarticle['modified']); } } } // ------------------------------------------------------------- function comments_count() { global $thisarticle; assert_article(); return $thisarticle['comments_count']; } // ------------------------------------------------------------- function comments_invite($atts) { global $thisarticle,$is_article_list; assert_article(); extract($thisarticle); global $comments_mode; if (!$comments_invite) $comments_invite = @$GLOBALS['prefs']['comments_default_invite']; extract(lAtts(array( 'class' => __FUNCTION__, 'showcount' => true, 'textonly' => false, 'showalways'=> false, //FIXME in crockery. This is only for BC. 'wraptag' => '', ), $atts)); $invite_return = ''; if (($annotate or $comments_count) && ($showalways or $is_article_list) ) { $ccount = ($comments_count && $showcount) ? ' ['.$comments_count.']' : ''; if ($textonly) $invite_return = $comments_invite.$ccount; else { if (!$comments_mode) { $invite_return = doTag($comments_invite, 'a', $class, ' href="'.permlinkurl($thisarticle).'#'.gTxt('comment').'" '). $ccount; } else { $invite_return = "'.$comments_invite.' '.$ccount; } } if ($wraptag) $invite_return = doTag($invite_return, $wraptag, $class); } return $invite_return; } // ------------------------------------------------------------- function comments_form($atts) { global $thisarticle, $has_comments_preview; extract(lAtts(array( 'class' => __FUNCTION__, 'form' => 'comment_form', 'isize' => '25', 'msgcols' => '25', 'msgrows' => '5', 'msgstyle' => '', 'show_preview' => empty($has_comments_preview), 'wraptag' => '', ), $atts)); assert_article(); extract($thisarticle); $out = ''; $ip = serverset('REMOTE_ADDR'); $blacklisted = is_blacklisted($ip); if (!checkCommentsAllowed($thisid)) { $out = graf(gTxt("comments_closed"), ' id="comments_closed"'); } elseif (!checkBan($ip)) { $out = graf(gTxt('you_have_been_banned'), ' id="comments_banned"'); } elseif ($blacklisted) { $out = graf(gTxt('your_ip_is_blacklisted_by'.' '.$blacklisted), ' id="comments_blacklisted"'); } elseif (gps('commented')!=='') { $out = gTxt("comment_posted"); if (gps('commented')==='0') $out .= " ". gTxt("comment_moderated"); $out = graf($out, ' id="txpCommentInputForm"'); } else { # display a comment preview if required if (ps('preview') and $show_preview) $out = comments_preview(array()); $out .= commentForm($thisid,$atts); } return (!$wraptag ? $out : doTag($out,$wraptag,$class) ); } // ------------------------------------------------------------- function comments_error($atts) { extract(lAtts(array( 'break' => 'br', 'class' => __FUNCTION__, 'wraptag' => 'div', ), $atts)); $evaluator =& get_comment_evaluator(); $errors = $evaluator->get_result_message(); if ($errors) { return doWrap($errors, $wraptag, $break, $class); } } // ------------------------------------------------------------- function if_comments_error($atts, $thing) { $evaluator =& get_comment_evaluator(); return parse(EvalElse($thing,(count($evaluator -> get_result_message()) > 0))); } // ------------------------------------------------------------- # DEPRECATED - provided only for backwards compatibility # this functionality will be merged into comments_invite # no point in having two tags for one functionality function comments_annotateinvite($atts, $thing) { trigger_error(gTxt('deprecated_tag'), E_USER_NOTICE); global $thisarticle, $pretext; extract(lAtts(array( 'class' => __FUNCTION__, 'wraptag' => 'h3', ),$atts)); assert_article(); extract($thisarticle); extract( safe_row( "Annotate,AnnotateInvite,unix_timestamp(Posted) as uPosted", "textpattern", 'ID = '.intval($thisid) ) ); if (!$thing) $thing = $AnnotateInvite; return (!$Annotate) ? '' : doTag($thing,$wraptag,$class,' id="'.gTxt('comment').'"'); } // ------------------------------------------------------------- function comments($atts) { global $thisarticle, $prefs; extract($prefs); extract(lAtts(array( 'form' => 'comments', 'wraptag' => ($comments_are_ol ? 'ol' : ''), 'break' => ($comments_are_ol ? 'li' : 'div'), 'class' => __FUNCTION__, 'breakclass' => '', 'limit' => 0, 'offset' => 0, 'sort' => 'posted ASC', ),$atts)); assert_article(); extract($thisarticle); if (!$comments_count) return ''; $qparts = array( 'parentid='.intval($thisid).' and visible='.VISIBLE, 'order by '.doSlash($sort), ($limit) ? 'limit '.intval($offset).', '.intval($limit) : '' ); $rs = safe_rows_start('*, unix_timestamp(posted) as time', 'txp_discuss', join(' ', $qparts)); $out = ''; if ($rs) { $comments = array(); while($vars = nextRow($rs)) { $GLOBALS['thiscomment'] = $vars; $comments[] = parse_form($form).n; unset($GLOBALS['thiscomment']); } $out .= doWrap($comments,$wraptag,$break,$class,$breakclass); } return $out; } // ------------------------------------------------------------- function comments_preview($atts) { global $has_comments_preview; if (!ps('preview')) return; extract(lAtts(array( 'form' => 'comments', 'wraptag' => '', 'class' => __FUNCTION__, ),$atts)); assert_article(); $preview = psa(array('name','email','web','message','parentid','remember')); $preview['time'] = time(); $preview['discussid'] = 0; $preview['name'] = strip_tags($preview['name']); $preview['email'] = clean_url($preview['email']); if ($preview['message'] == '') { $in = getComment(); $preview['message'] = $in['message']; } $preview['message'] = markup_comment(substr(trim($preview['message']), 0, 65535)); // it is called 'message', not 'novel' $preview['web'] = clean_url($preview['web']); $GLOBALS['thiscomment'] = $preview; $comments = parse_form($form).n; unset($GLOBALS['thiscomment']); $out = doTag($comments,$wraptag,$class); # set a flag, to tell the comments_form tag that it doesn't have to show a preview $has_comments_preview = true; return $out; } // ------------------------------------------------------------- function if_comments_preview($atts, $thing) { return parse(EvalElse($thing, ps('preview') && checkCommentsAllowed(gps('parentid')) )); } // ------------------------------------------------------------- function comment_permlink($atts, $thing) { global $thisarticle, $thiscomment; assert_article(); assert_comment(); extract($thiscomment); extract(lAtts(array( 'anchor' => empty($thiscomment['has_anchor_tag']), ),$atts)); $dlink = permlinkurl($thisarticle).'#c'.$discussid; $thing = parse($thing); $name = ($anchor ? ' id="c'.$discussid.'"' : ''); return tag($thing,'a',' href="'.$dlink.'"'.$name); } // ------------------------------------------------------------- function comment_id() { global $thiscomment; assert_comment(); return $thiscomment['discussid']; } // ------------------------------------------------------------- function comment_name($atts) { global $thiscomment, $prefs; assert_comment(); extract($prefs); extract($thiscomment); extract(lAtts(array( 'link' => 1, ), $atts)); $name = htmlspecialchars($name); if ($link) { $web = str_replace('http://', '', $web); $nofollow = (@$comment_nofollow ? ' rel="nofollow"' : ''); if ($web) { return ''.$name.''; } if ($email && !$never_display_email) { return ''.$name.''; } } return $name; } // ------------------------------------------------------------- function comment_email() { global $thiscomment; assert_comment(); return htmlspecialchars($thiscomment['email']); } // ------------------------------------------------------------- function comment_web() { global $thiscomment; assert_comment(); return htmlspecialchars($thiscomment['web']); } // ------------------------------------------------------------- function comment_time($atts) { global $thiscomment, $comments_dateformat; assert_comment(); extract(lAtts(array( 'format' => $comments_dateformat, 'gmt' => '', 'lang' => '', ), $atts)); return safe_strftime($format, $thiscomment['time'], $gmt, $lang); } // ------------------------------------------------------------- function comment_message() { global $thiscomment; assert_comment(); return $thiscomment['message']; } // ------------------------------------------------------------- function comment_anchor() { global $thiscomment; assert_comment(); $thiscomment['has_anchor_tag'] = 1; return ''; } // ------------------------------------------------------------- // DEPRECATED: the old comment message body tag function message($atts) { trigger_error(gTxt('deprecated_tag'), E_USER_NOTICE); return comment_message($atts); } // ------------------------------------------------------------- function author($atts) { global $thisarticle, $s; assert_article(); extract(lAtts(array( 'link' => '', 'section' => '', 'this_section' => 0, ), $atts)); $author_name = get_author_name($thisarticle['authorid']); $section = ($this_section) ? ( $s == 'default' ? '' : $s ) : $section; return ($link) ? href($author_name, pagelinkurl(array('s' => $section, 'author' => $author_name))) : $author_name; } // ------------------------------------------------------------- function if_author($atts, $thing) { global $author; extract(lAtts(array( 'name' => '', ), $atts)); if ($name) { return parse(EvalElse($thing, in_list($author, $name))); } return parse(EvalElse($thing, !empty($author))); } // ------------------------------------------------------------- function if_article_author($atts, $thing) { global $thisarticle; assert_article(); extract(lAtts(array( 'name' => '', ), $atts)); $author = $thisarticle['authorid']; if ($name) { return parse(EvalElse($thing, in_list($author, $name))); } return parse(EvalElse($thing, !empty($author))); } // ------------------------------------------------------------- function body() { global $thisarticle, $is_article_body; assert_article(); $is_article_body = 1; $out = parse($thisarticle['body']); $is_article_body = 0; return $out; } // ------------------------------------------------------------- function title($atts) { global $thisarticle, $prefs; assert_article(); extract(lAtts(array( 'no_widow' => @$prefs['title_no_widow'], ), $atts)); $t = escape_title($thisarticle['title']); if ($no_widow) $t = noWidow($t); return $t; } // ------------------------------------------------------------- function excerpt() { global $thisarticle, $is_article_body; assert_article(); $is_article_body = 1; $out = parse($thisarticle['excerpt']); $is_article_body = 0; return $out; } // ------------------------------------------------------------- function category1($atts, $thing = NULL) { global $thisarticle, $s, $permlink_mode; assert_article(); extract(lAtts(array( 'class' => '', 'link' => 0, 'title' => 0, 'section' => '', 'this_section' => 0, 'wraptag' => '', ), $atts)); if ($thisarticle['category1']) { $section = ($this_section) ? ( $s == 'default' ? '' : $s ) : $section; $category = $thisarticle['category1']; $label = htmlspecialchars(($title) ? fetch_category_title($category) : $category); if ($thing) { $out = '