| [ Index ] | [ Index ] [ Classes ] [ Functions ] [ Variables ] [ Constants ] |
PHP Cross Reference of TXP stable 4.0.6 |
||
[Summary view] [Print] [Text view]
1 <?php 2 3 /* 4 This is Textpattern 5 Copyright 2005 by Dean Allen - all rights reserved. 6 7 Use of this software denotes acceptance of the Textpattern license agreement 8 9 $HeadURL: http://svn.textpattern.com/releases/4.0.6/source/textpattern/publish/taghandlers.php $ 10 $LastChangedRevision: 2774 $ 11 12 */ 13 14 // ------------------------------------------------------------- 15 16 function page_title($atts) 17 { 18 global $parentid, $thisarticle, $id, $q, $c, $s, $pg, $sitename; 19 20 extract(lAtts(array( 21 'separator' => ': ', 22 ), $atts)); 23 24 if ($parentid) { 25 $parent_id = (int) $parent_id; 26 $out = $sitename.$separator.gTxt('comments_on').' '.safe_field('Title', 'textpattern', "ID = $parentid"); 27 } elseif ($thisarticle['title']) { 28 $out = $sitename.$separator.$thisarticle['title']; 29 } elseif ($q) { 30 $out = $sitename.$separator.gTxt('search_results')."$separator $q"; 31 } elseif ($c) { 32 $out = $sitename.$separator.fetch_category_title($c); 33 } elseif ($s and $s != 'default') { 34 $out = $sitename.$separator.fetch_section_title($s); 35 } elseif ($pg) { 36 $out = $sitename.$separator.gTxt('page')." $pg"; 37 } else { 38 $out = $sitename; 39 } 40 41 return escape_title($out); 42 } 43 44 // ------------------------------------------------------------- 45 46 function css($atts) 47 { 48 global $s; 49 50 extract(lAtts(array( 51 'format' => 'url', 52 'media' => 'screen', 53 'n' => '', 54 'rel' => 'stylesheet', 55 'title' => '', 56 ), $atts)); 57 58 if ($n) { 59 $url = hu.'textpattern/css.php?n='.$n; 60 } elseif ($s) { 61 $url = hu.'textpattern/css.php?s='.$s; 62 } else { 63 $url = hu.'textpattern/css.php?n=default'; 64 } 65 66 if ($format == 'link') { 67 return '<link rel="'.$rel.'" type="text/css"'. 68 ($media ? ' media="'.$media.'"' : ''). 69 ($title ? ' title="'.$title.'"' : ''). 70 ' href="'.$url.'" />'; 71 } 72 73 return $url; 74 } 75 76 // ------------------------------------------------------------- 77 78 function image($atts) 79 { 80 global $img_dir; 81 82 static $cache = array(); 83 84 extract(lAtts(array( 85 'align' => '', // remove in crockery 86 'class' => '', 87 'escape' => '', 88 'html_id' => '', 89 'id' => '', 90 'name' => '', 91 'style' => '', // remove in crockery? 92 'wraptag' => '', 93 ), $atts)); 94 95 if ($name) 96 { 97 if (isset($cache['n'][$name])) 98 { 99 $rs = $cache['n'][$name]; 100 } 101 102 else 103 { 104 $name = doSlash($name); 105 106 $rs = safe_row('*', 'txp_image', "name = '$name' limit 1"); 107 108 $cache['n'][$name] = $rs; 109 } 110 } 111 112 elseif ($id) 113 { 114 if (isset($cache['i'][$id])) 115 { 116 $rs = $cache['i'][$id]; 117 } 118 119 else 120 { 121 $id = (int) $id; 122 123 $rs = safe_row('*', 'txp_image', "id = $id limit 1"); 124 125 $cache['i'][$id] = $rs; 126 } 127 } 128 129 else 130 { 131 trigger_error(gTxt('unknown_image')); 132 return; 133 } 134 135 if ($rs) 136 { 137 extract($rs); 138 139 if ($escape == 'html') 140 { 141 $alt = htmlspecialchars($alt); 142 $caption = htmlspecialchars($caption); 143 } 144 145 $out = '<img src="'.hu.$img_dir.'/'.$id.$ext.'" width="'.$w.'" height="'.$h.'" alt="'.$alt.'"'. 146 ($caption ? ' title="'.$caption.'"' : ''). 147 ( ($html_id and !$wraptag) ? ' id="'.$html_id.'"' : '' ). 148 ( ($class and !$wraptag) ? ' class="'.$class.'"' : '' ). 149 ($style ? ' style="'.$style.'"' : ''). 150 ($align ? ' align="'.$align.'"' : ''). 151 ' />'; 152 153 return ($wraptag) ? doTag($out, $wraptag, $class, '', $html_id) : $out; 154 } 155 156 trigger_error(gTxt('unknown_image')); 157 } 158 159 // ------------------------------------------------------------- 160 161 function thumbnail($atts) 162 { 163 global $img_dir; 164 165 extract(lAtts(array( 166 'align' => '', // remove in crockery 167 'class' => '', 168 'escape' => '', 169 'html_id' => '', 170 'id' => '', 171 'link' => 0, 172 'link_rel' => '', 173 'name' => '', 174 'poplink' => 0, // remove in crockery 175 'style' => '', // remove in crockery 176 'wraptag' => '' 177 ), $atts)); 178 179 if ($name) 180 { 181 $name = doSlash($name); 182 183 $rs = safe_row('*', 'txp_image', "name = '$name' limit 1"); 184 } 185 186 elseif ($id) 187 { 188 $id = (int) $id; 189 190 $rs = safe_row('*', 'txp_image', "id = $id limit 1"); 191 } 192 193 else 194 { 195 trigger_error(gTxt('unknown_image')); 196 return; 197 } 198 199 if ($rs) 200 { 201 extract($rs); 202 203 if ($thumbnail) 204 { 205 if ($escape == 'html') 206 { 207 $alt = htmlspecialchars($alt); 208 $caption = htmlspecialchars($caption); 209 } 210 211 $out = '<img src="'.hu.$img_dir.'/'.$id.'t'.$ext.'" alt="'.$alt.'"'. 212 ($caption ? ' title="'.$caption.'"' : ''). 213 ( ($html_id and !$wraptag) ? ' id="'.$html_id.'"' : '' ). 214 ( ($class and !$wraptag) ? ' class="'.$class.'"' : '' ). 215 ($style ? ' style="'.$style.'"' : ''). 216 ($align ? ' align="'.$align.'"' : ''). 217 ' />'; 218 219 if ($link) 220 { 221 $out = href($out, hu.$img_dir.'/'.$id.$ext, (!empty($link_rel) ? " rel='$link_rel'" : '')." title='$caption'"); 222 } 223 224 elseif ($poplink) 225 { 226 $out = '<a href="'.hu.$img_dir.'/'.$id.$ext.'"'. 227 ' onclick="window.open(this.href, \'popupwindow\', '. 228 '\'width='.$w.', height='.$h.', scrollbars, resizable\'); return false;">'.$out.'</a>'; 229 } 230 231 return ($wraptag) ? doTag($out, $wraptag, $class, '', $html_id) : $out; 232 } 233 234 } 235 236 trigger_error(gTxt('unknown_image')); 237 } 238 239 // ------------------------------------------------------------- 240 function output_form($atts) 241 { 242 extract(lAtts(array( 243 'form' => '', 244 ), $atts)); 245 246 if (!$form) 247 trigger_error(gTxt('form_not_specified')); 248 else 249 return parse_form($form); 250 251 } 252 253 // ------------------------------------------------------------- 254 255 function feed_link($atts, $thing=NULL) 256 { 257 global $s, $c; 258 259 extract(lAtts(array( 260 'category' => $c, 261 'flavor' => 'rss', 262 'format' => 'a', 263 'label' => '', 264 'limit' => '', 265 'section' => ( $s == 'default' ? '' : $s), 266 'title' => gTxt('rss_feed_title'), 267 'wraptag' => '', 268 ), $atts)); 269 270 $url = pagelinkurl(array( 271 $flavor => '1', 272 'section' => $section, 273 'category' => $category, 274 'limit' => $limit 275 )); 276 277 if ($flavor == 'atom') 278 { 279 $title = ($title == gTxt('rss_feed_title')) ? gTxt('atom_feed_title') : $title; 280 } 281 282 $title = htmlspecialchars($title); 283 284 if ($format == 'link') 285 { 286 $type = ($flavor == 'atom') ? 'application/atom+xml' : 'application/rss+xml'; 287 288 return '<link rel="alternate" type="'.$type.'" title="'.$title.'" href="'.$url.'" />'; 289 } 290 291 $txt = ($thing === NULL ? $label : parse($thing)); 292 $out = '<a href="'.$url.'" title="'.$title.'">'.$txt.'</a>'; 293 294 return ($wraptag) ? tag($out, $wraptag) : $out; 295 } 296 297 // ------------------------------------------------------------- 298 299 function link_feed_link($atts) 300 { 301 global $c; 302 303 extract(lAtts(array( 304 'category' => $c, 305 'flavor' => 'rss', 306 'format' => 'a', 307 'label' => '', 308 'title' => gTxt('rss_feed_title'), 309 'wraptag' => '', 310 ), $atts)); 311 312 $url = pagelinkurl(array( 313 $flavor => '1', 314 'area' =>'link', 315 'c' => $category 316 )); 317 318 if ($flavor == 'atom') 319 { 320 $title = ($title == gTxt('rss_feed_title')) ? gTxt('atom_feed_title') : $title; 321 } 322 323 $title = htmlspecialchars($title); 324 325 if ($format == 'link') 326 { 327 $type = ($flavor == 'atom') ? 'application/atom+xml' : 'application/rss+xml'; 328 329 return '<link rel="alternate" type="'.$type.'" title="'.$title.'" href="'.$url.'" />'; 330 } 331 332 $out = '<a href="'.$url.'" title="'.$title.'">'.$label.'</a>'; 333 334 return ($wraptag) ? tag($out, $wraptag) : $out; 335 } 336 337 // ------------------------------------------------------------- 338 339 function linklist($atts) 340 { 341 global $thislink; 342 343 extract(lAtts(array( 344 'break' => '', 345 'category' => '', 346 'class' => __FUNCTION__, 347 'form' => 'plainlinks', 348 'label' => '', 349 'labeltag' => '', 350 'limit' => 0, 351 'offset' => 0, 352 'sort' => 'linksort asc', 353 'wraptag' => '', 354 ), $atts)); 355 356 $qparts = array( 357 ($category) ? "category IN ('".join("','", doSlash(do_list($category)))."')" : '1=1', 358 'order by '.doSlash($sort), 359 ($limit) ? 'limit '.intval($offset).', '.intval($limit) : '' 360 ); 361 362 $rs = safe_rows_start('*, unix_timestamp(date) as uDate', 'txp_link', join(' ', $qparts)); 363 364 if ($rs) 365 { 366 $out = array(); 367 368 while ($a = nextRow($rs)) 369 { 370 extract($a); 371 372 $thislink = array( 373 'id' => $id, 374 'linkname' => $linkname, 375 'url' => $url, 376 'description' => $description, 377 'date' => $uDate, 378 'category' => $category, 379 ); 380 381 $out[] = parse_form($form); 382 383 $thislink = ''; 384 } 385 386 if ($out) 387 { 388 return doLabel($label, $labeltag).doWrap($out, $wraptag, $break, $class); 389 } 390 } 391 392 return false; 393 } 394 395 // ------------------------------------------------------------- 396 397 function tpt_link($atts) 398 { 399 global $thislink; 400 assert_link(); 401 402 extract(lAtts(array( 403 'rel' => '', 404 ), $atts)); 405 406 return tag( 407 htmlspecialchars($thislink['linkname']), 'a', 408 ($rel ? ' rel="'.$rel.'"' : ''). 409 ' href="'.doSpecial($thislink['url']).'"' 410 ); 411 } 412 413 // ------------------------------------------------------------- 414 415 function linkdesctitle($atts) 416 { 417 global $thislink; 418 assert_link(); 419 420 extract(lAtts(array( 421 'rel' => '', 422 ), $atts)); 423 424 $description = ($thislink['description']) ? 425 ' title="'.htmlspecialchars($thislink['description']).'"' : 426 ''; 427 428 return tag( 429 htmlspecialchars($thislink['linkname']), 'a', 430 ($rel ? ' rel="'.$rel.'"' : ''). 431 ' href="'.doSpecial($thislink['url']).'"'.$description 432 ); 433 } 434 435 // ------------------------------------------------------------- 436 437 function link_name($atts) 438 { 439 global $thislink; 440 assert_link(); 441 442 extract(lAtts(array( 443 'escape' => '', 444 ), $atts)); 445 446 return ($escape == 'html') ? 447 htmlspecialchars($thislink['linkname']) : 448 $thislink['linkname']; 449 } 450 451 // ------------------------------------------------------------- 452 453 function link_url($atts) 454 { 455 global $thislink; 456 assert_link(); 457 458 return $thislink['url']; 459 } 460 461 // ------------------------------------------------------------- 462 463 function link_description($atts) 464 { 465 global $thislink; 466 assert_link(); 467 468 extract(lAtts(array( 469 'class' => '', 470 'escape' => '', 471 'label' => '', 472 'labeltag' => '', 473 'wraptag' => '', 474 ), $atts)); 475 476 if ($thislink['description']) 477 { 478 $description = ($escape == 'html') ? 479 htmlspecialchars($thislink['description']) : 480 $thislink['description']; 481 482 return doLabel($label, $labeltag).doTag($description, $wraptag, $class); 483 } 484 } 485 486 // ------------------------------------------------------------- 487 488 function link_date($atts) 489 { 490 global $thislink, $dateformat; 491 assert_link(); 492 493 extract(lAtts(array( 494 'format' => $dateformat, 495 'gmt' => '', 496 'lang' => '', 497 ), $atts)); 498 499 return safe_strftime($format, $thislink['date'], $gmt, $lang); 500 } 501 502 // ------------------------------------------------------------- 503 504 function link_category($atts) 505 { 506 global $thislink; 507 assert_link(); 508 509 extract(lAtts(array( 510 'class' => '', 511 'label' => '', 512 'labeltag' => '', 513 'title' => 0, 514 'wraptag' => '', 515 ), $atts)); 516 517 if ($thislink['category']) 518 { 519 $category = ($title) ? 520 fetch_category_title($thislink['category'], 'link') : 521 $thislink['category']; 522 523 return doLabel($label, $labeltag).doTag($category, $wraptag, $class); 524 } 525 } 526 527 // ------------------------------------------------------------- 528 function eE($txt) // convert email address into unicode entities 529 { 530 for ($i=0;$i<strlen($txt);$i++) { 531 $ent[] = "&#".ord(substr($txt,$i,1)).";"; 532 } 533 if (!empty($ent)) return join('',$ent); 534 } 535 536 // ------------------------------------------------------------- 537 function email($atts, $thing='') // simple contact link 538 { 539 extract(lAtts(array( 540 'email' => '', 541 'linktext' => gTxt('contact'), 542 'title' => '', 543 ),$atts)); 544 545 if($email) { 546 $out = array( 547 '<a href="'.eE('mailto:'.$email).'"', 548 ($title) ? ' title="'.$title.'"' : '', 549 '>', 550 ($thing) ? parse($thing) : $linktext, 551 '</a>' 552 ); 553 return join('',$out); 554 } 555 return ''; 556 } 557 558 // ------------------------------------------------------------- 559 function password_protect($atts) 560 { 561 ob_start(); 562 563 extract(lAtts(array( 564 'login' => '', 565 'pass' => '', 566 ),$atts)); 567 568 $au = serverSet('PHP_AUTH_USER'); 569 $ap = serverSet('PHP_AUTH_PW'); 570 //For php as (f)cgi, two rules in htaccess often allow this workaround 571 $ru = serverSet('REDIRECT_REMOTE_USER'); 572 if ($ru && !$au && !$ap && substr( $ru,0,5) == 'Basic' ) { 573 list ( $au, $ap ) = explode( ':', base64_decode( substr( $ru,6))); 574 } 575 if ($login && $pass) { 576 if (!$au || !$ap || $au!= $login || $ap!= $pass) { 577 header('WWW-Authenticate: Basic realm="Private"'); 578 txp_die(gTxt('auth_required'), '401'); 579 } 580 } 581 } 582 583 // ------------------------------------------------------------- 584 585 function recent_articles($atts) 586 { 587 global $prefs; 588 extract(lAtts(array( 589 'break' => br, 590 'category' => '', 591 'class' => __FUNCTION__, 592 'label' => gTxt('recent_articles'), 593 'labeltag' => '', 594 'limit' => 10, 595 'section' => '', 596 'sort' => 'Posted desc', 597 'sortby' => '', 598 'sortdir' => '', 599 'wraptag' => '', 600 'no_widow' => @$prefs['title_no_widow'], 601 ), $atts)); 602 603 // for backwards compatibility 604 // sortby and sortdir are deprecated 605 if ($sortby) 606 { 607 if (!$sortdir) 608 { 609 $sortdir = 'desc'; 610 } 611 612 $sort = "$sortby $sortdir"; 613 } 614 615 elseif ($sortdir) 616 { 617 $sort = "Posted $sortdir"; 618 } 619 620 $category = join("','", doSlash(do_list($category))); 621 $categories = ($category) ? "and (Category1 IN ('".$category."') or Category2 IN ('".$category."'))" : ''; 622 $section = ($section) ? " and Section IN ('".join("','", doSlash(do_list($section)))."')" : ''; 623 624 $rs = safe_rows_start('*, id as thisid, unix_timestamp(Posted) as posted', 'textpattern', 625 "Status = 4 $section $categories and Posted <= now() order by ".doSlash($sort).' limit 0,'.intval($limit)); 626 627 if ($rs) 628 { 629 $out = array(); 630 631 while ($a = nextRow($rs)) 632 { 633 $a['Title'] = ($no_widow) ? noWidow(escape_title($a['Title'])) : escape_title($a['Title']); 634 $out[] = href($a['Title'], permlinkurl($a)); 635 } 636 637 if ($out) 638 { 639 return doLabel($label, $labeltag).doWrap($out, $wraptag, $break, $class); 640 } 641 } 642 643 return ''; 644 } 645 646 // ------------------------------------------------------------- 647 648 function recent_comments($atts) 649 { 650 extract(lAtts(array( 651 'break' => br, 652 'class' => __FUNCTION__, 653 'label' => '', 654 'labeltag' => '', 655 'limit' => 10, 656 'sort' => 'posted desc', 657 'wraptag' => '', 658 ), $atts)); 659 660 $sort = preg_replace('/\bposted\b/', 'd.posted', $sort); 661 662 $rs = startRows('select d.name, d.discussid, t.ID as thisid, unix_timestamp(t.Posted) as posted, t.Title as title, t.Section as section, t.url_title '. 663 'from '. safe_pfx('txp_discuss') .' as d inner join '. safe_pfx('textpattern') .' as t on d.parentid = t.ID '. 664 'where t.Status >= 4 and d.visible = '.VISIBLE.' order by '.doSlash($sort).' limit 0,'.intval($limit)); 665 666 if ($rs) 667 { 668 $out = array(); 669 while ($c = nextRow($rs)) 670 { 671 $out[] = href( 672 $c['name'].' ('.escape_title($c['title']).')', 673 permlinkurl($c).'#c'.$c['discussid'] 674 ); 675 } 676 677 if ($out) 678 { 679 return doLabel($label, $labeltag).doWrap($out, $wraptag, $break, $class); 680 } 681 } 682 683 return ''; 684 } 685 686 // ------------------------------------------------------------- 687 688 function related_articles($atts) 689 { 690 global $thisarticle, $prefs; 691 692 assert_article(); 693 694 extract(lAtts(array( 695 'break' => br, 696 'class' => __FUNCTION__, 697 'label' => '', 698 'labeltag' => '', 699 'limit' => 10, 700 'match' => 'Category1,Category2', 701 'no_widow' => @$prefs['title_no_widow'], 702 'section' => '', 703 'sort' => 'Posted desc', 704 'wraptag' => '', 705 ), $atts)); 706 707 if (empty($thisarticle['category1']) and empty($thisarticle['category2'])) 708 { 709 return; 710 } 711 712 $match = do_list($match); 713 714 if (!in_array('Category1', $match) and !in_array('Category2', $match)) 715 { 716 return; 717 } 718 719 $id = $thisarticle['thisid']; 720 721 $cats = array(); 722 723 if ($thisarticle['category1']) 724 { 725 $cats[] = doSlash($thisarticle['category1']); 726 } 727 728 if ($thisarticle['category2']) 729 { 730 $cats[] = doSlash($thisarticle['category2']); 731 } 732 733 $cats = join("','", $cats); 734 735 $categories = array(); 736 737 if (in_array('Category1', $match)) 738 { 739 $categories[] = "Category1 in('$cats')"; 740 } 741 742 if (in_array('Category2', $match)) 743 { 744 $categories[] = "Category2 in('$cats')"; 745 } 746 747 $categories = 'and ('.join(' or ', $categories).')'; 748 749 $section = ($section) ? " and Section IN ('".join("','", doSlash(do_list($section)))."')" : ''; 750 751 $rs = safe_rows_start('*, unix_timestamp(Posted) as posted', 'textpattern', 752 'ID != '.intval($id)." and Status = 4 and Posted <= now() $categories $section order by ".doSlash($sort).' limit 0,'.intval($limit)); 753 754 if ($rs) 755 { 756 $out = array(); 757 758 while ($a = nextRow($rs)) 759 { 760 $a['Title'] = ($no_widow) ? noWidow(escape_title($a['Title'])) : escape_title($a['Title']); 761 762 $out[] = href($a['Title'], permlinkurl($a)); 763 } 764 765 if ($out) 766 { 767 return doLabel($label, $labeltag).doWrap($out, $wraptag, $break, $class); 768 } 769 } 770 771 return ''; 772 } 773 774 // ------------------------------------------------------------- 775 776 function popup($atts) 777 { 778 global $s, $c; 779 780 extract(lAtts(array( 781 'label' => gTxt('browse'), 782 'wraptag' => '', 783 'section' => '', 784 'this_section' => 0, 785 'type' => 'c', 786 ), $atts)); 787 788 if ($type == 's') 789 { 790 $rs = safe_rows_start('name, title', 'txp_section', "name != 'default' order by name"); 791 } 792 793 else 794 { 795 $rs = safe_rows_start('name, title', 'txp_category', "type = 'article' and name != 'root' order by name"); 796 } 797 798 if ($rs) 799 { 800 $out = array(); 801 802 $current = ($type == 's') ? $s : $c; 803 804 $sel = ''; 805 $selected = false; 806 807 while ($a = nextRow($rs)) 808 { 809 extract($a); 810 811 if ($name == $current) 812 { 813 $sel = ' selected="selected"'; 814 $selected = true; 815 } 816 817 $out[] = '<option value="'.$name.'"'.$sel.'>'.htmlspecialchars($title).'</option>'; 818 819 $sel = ''; 820 } 821 822 if ($out) 823 { 824 $section = ($this_section) ? ( $s == 'default' ? '' : $s) : $section; 825 826 $out = n.'<select name="'.$type.'" onchange="submit(this.form);">'. 827 n.t.'<option value=""'.($selected ? '' : ' selected="selected"').'> </option>'. 828 n.t.join(n.t, $out). 829 n.'</select>'; 830 831 if ($label) 832 { 833 $out = $label.br.$out; 834 } 835 836 if ($wraptag) 837 { 838 $out = tag($out, $wraptag); 839 } 840 841 return '<form method="get" action="'.hu.'">'. 842 '<div>'. 843 ( ($type != 's' and $section and $s) ? n.hInput('s', $section) : ''). 844 n.$out. 845 n.'<noscript><div><input type="submit" value="'.gTxt('go').'" /></div></noscript>'. 846 n.'</div>'. 847 n.'</form>'; 848 } 849 } 850 } 851 852 // ------------------------------------------------------------- 853 // output href list of site categories 854 855 function category_list($atts) 856 { 857 global $s, $c; 858 859 extract(lAtts(array( 860 'active_class' => '', 861 'break' => br, 862 'categories' => '', 863 'class' => __FUNCTION__, 864 'exclude' => '', 865 'label' => '', 866 'labeltag' => '', 867 'parent' => '', 868 'section' => '', 869 'sort' => '', 870 'this_section' => 0, 871 'type' => 'article', 872 'wraptag' => '', 873 ), $atts)); 874 875 $sort = doSlash($sort); 876 877 if ($categories) 878 { 879 $categories = do_list($categories); 880 $categories = join("','", doSlash($categories)); 881 882 $rs = safe_rows_start('name, title', 'txp_category', 883 "type = '".doSlash($type)."' and name in ('$categories') order by ".($sort ? $sort : "field(name, '$categories')")); 884 } 885 886 else 887 { 888 if ($exclude) 889 { 890 $exclude = do_list($exclude); 891 892 $exclude = join("','", doSlash($exclude)); 893 894 $exclude = "and name not in('$exclude')"; 895 } 896 897 if ($parent) 898 { 899 $qs = safe_row('lft, rgt', 'txp_category', "type = '".doSlash($type)."' and name = '".doSlash($parent)."'"); 900 901 if ($qs) 902 { 903 extract($qs); 904 905 $rs = safe_rows_start('name, title', 'txp_category', 906 "(lft between $lft and $rgt) and type = '".doSlash($type)."' and name != 'default' $exclude order by ".($sort ? $sort : 'lft ASC')); 907 } 908 } 909 910 else 911 { 912 $rs = safe_rows_start('name, title', 'txp_category', 913 "type = '".doSlash($type)."' and name not in('default','root') $exclude order by ".($sort ? $sort : 'name ASC')); 914 } 915 } 916 917 if ($rs) 918 { 919 $out = array(); 920 921 while ($a = nextRow($rs)) 922 { 923 extract($a); 924 925 if ($name) 926 { 927 $section = ($this_section) ? ( $s == 'default' ? '' : $s ) : $section; 928 929 $out[] = tag(str_replace('& ', '& ', $title), 'a', 930 ( ($active_class and (0 == strcasecmp($c, $name))) ? ' class="'.$active_class.'"' : '' ). 931 ' href="'.pagelinkurl(array('s' => $section, 'c' => $name)).'"' 932 ); 933 } 934 } 935 936 if ($out) 937 { 938 return doLabel($label, $labeltag).doWrap($out, $wraptag, $break, $class); 939 } 940 } 941 942 return ''; 943 } 944 945 // ------------------------------------------------------------- 946 // output href list of site sections 947 948 function section_list($atts) 949 { 950 global $sitename, $s; 951 952 extract(lAtts(array( 953 'active_class' => '', 954 'break' => br, 955 'class' => __FUNCTION__, 956 'default_title' => $sitename, 957 'exclude' => '', 958 'include_default' => '', 959 'label' => '', 960 'labeltag' => '', 961 'sections' => '', 962 'sort' => '', 963 'wraptag' => '', 964 ), $atts)); 965 966 $sort = doSlash($sort); 967 968 if ($sections) 969 { 970 $sections = do_list($sections); 971 972 $sections = join("','", doSlash($sections)); 973 974 $rs = safe_rows_start('name, title', 'txp_section', "name in ('$sections') order by ".($sort ? $sort : "field(name, '$sections')")); 975 } 976 977 else 978 { 979 if ($exclude) 980 { 981 $exclude = do_list($exclude); 982 983 $exclude = join("','", doSlash($exclude)); 984 985 $exclude = "and name not in('$exclude')"; 986 } 987 988 $rs = safe_rows_start('name, title', 'txp_section', "name != 'default' $exclude order by ".($sort ? $sort : 'name ASC')); 989 } 990 991 if ($rs) 992 { 993 $out = array(); 994 995 while ($a = nextRow($rs)) 996 { 997 extract($a); 998 999 $url = pagelinkurl(array('s' => $name)); 1000 1001 $out[] = tag($title, 'a', 1002 ( ($active_class and (0 == strcasecmp($s, $name))) ? ' class="'.$active_class.'"' : '' ). 1003 ' href="'.$url.'"' 1004 ); 1005 } 1006 1007 if ($out) 1008 { 1009 if ($include_default) 1010 { 1011 $out = array_merge(array( 1012 tag($default_title,'a', 1013 ( ($active_class and ($s == 'default')) ? ' class="'.$active_class.'"' : '' ). 1014 ' href="'.hu.'"' 1015 ) 1016 ), $out); 1017 } 1018 1019 return doLabel($label, $labeltag).doWrap($out, $wraptag, $break, $class); 1020 } 1021 } 1022 1023 return ''; 1024 } 1025 1026 // ------------------------------------------------------------- 1027 function search_input($atts) // input form for search queries 1028 { 1029 global $q, $permlink_mode; 1030 extract(lAtts(array( 1031 'form' => 'search_input', 1032 'wraptag' => 'p', 1033 'size' => '15', 1034 'label' => gTxt('search'), 1035 'button' => '', 1036 'section' => '', 1037 ),$atts)); 1038 1039 if ($form) { 1040 $rs = fetch('form','txp_form','name',$form); 1041 if ($rs) { 1042 return $rs; 1043 } 1044 } 1045 1046 $sub = (!empty($button)) ? '<input type="submit" value="'.$button.'" />' : ''; 1047 $out = fInput('text','q',$q,'','','',$size); 1048 $out = (!empty($label)) ? $label.br.$out.$sub : $out.$sub; 1049 $out = ($wraptag) ? tag($out,$wraptag) : $out; 1050 1051 if (!$section) { 1052 return '<form method="get" action="'.hu.'">'. 1053 n.$out. 1054 n.'</form>'; 1055 } 1056 1057 if ($permlink_mode != 'messy') { 1058 return '<form method="get" action="'.pagelinkurl(array('s' => $section)).'">'. 1059 n.$out. 1060 n.'</form>'; 1061 } 1062 1063 return '<form method="get" action="'.hu.'">'. 1064 n.hInput('s', $section). 1065 n.$out. 1066 n.'</form>'; 1067 } 1068 1069 // ------------------------------------------------------------- 1070 function search_term($atts) 1071 { 1072 global $q; 1073 if(empty($q)) return ''; 1074 1075 extract(lAtts(array( 1076 'escape' => 'html' 1077 ),$atts)); 1078 1079 return ($escape == 'html' ? htmlspecialchars($q) : $q); 1080 } 1081 1082 // ------------------------------------------------------------- 1083 // link to next article, if it exists 1084 1085 function link_to_next($atts, $thing) 1086 { 1087 global $id, $next_id, $next_title; 1088 1089 extract(lAtts(array( 1090 'showalways' => 0, 1091 ), $atts)); 1092 1093 if (intval($id) == 0) 1094 { 1095 global $thisarticle, $s; 1096 1097 assert_article(); 1098 1099 extract(getNextPrev( 1100 @$thisarticle['thisid'], 1101 @strftime('%Y-%m-%d %H:%M:%S', $thisarticle['posted']), 1102 @$s 1103 )); 1104 } 1105 1106 if ($next_id) 1107 { 1108 $url = permlinkurl_id($next_id); 1109 1110 if ($thing) 1111 { 1112 $thing = parse($thing); 1113 1114 return '<a rel="next" href="'.$url.'"'. 1115 ($next_title != $thing ? ' title="'.$next_title.'"' : ''). 1116 '>'.$thing.'</a>'; 1117 } 1118 1119 return $url; 1120 } 1121 1122 return ($showalways) ? parse($thing) : ''; 1123 } 1124 1125 // ------------------------------------------------------------- 1126 // link to next article, if it exists 1127 1128 function link_to_prev($atts, $thing) 1129 { 1130 global $id, $prev_id, $prev_title; 1131 1132 extract(lAtts(array( 1133 'showalways' => 0, 1134 ), $atts)); 1135 1136 if (intval($id) == 0) 1137 { 1138 global $thisarticle, $s; 1139 1140 assert_article(); 1141 1142 extract(getNextPrev( 1143 $thisarticle['thisid'], 1144 @strftime('%Y-%m-%d %H:%M:%S', $thisarticle['posted']), 1145 @$s 1146 )); 1147 } 1148 1149 if ($prev_id) 1150 { 1151 $url = permlinkurl_id($prev_id); 1152 1153 if ($thing) 1154 { 1155 $thing = parse($thing); 1156 1157 return '<a rel="prev" href="'.$url.'"'. 1158 ($prev_title != $thing ? ' title="'.$prev_title.'"' : ''). 1159 '>'.$thing.'</a>'; 1160 } 1161 1162 return $url; 1163 } 1164 1165 return ($showalways) ? parse($thing) : ''; 1166 } 1167 1168 // ------------------------------------------------------------- 1169 1170 function next_title() 1171 { 1172 return $GLOBALS['next_title']; 1173 } 1174 1175 // ------------------------------------------------------------- 1176 1177 function prev_title() 1178 { 1179 return $GLOBALS['prev_title']; 1180 } 1181 1182 // ------------------------------------------------------------- 1183 1184 function site_name() 1185 { 1186 return $GLOBALS['sitename']; 1187 } 1188 1189 // ------------------------------------------------------------- 1190 1191 function site_slogan() 1192 { 1193 return $GLOBALS['site_slogan']; 1194 } 1195 1196 // ------------------------------------------------------------- 1197 1198 function link_to_home($atts, $thing = false) 1199 { 1200 extract(lAtts(array( 1201 'class' => false, 1202 ), $atts)); 1203 1204 if ($thing) 1205 { 1206 $class = ($class) ? ' class="'.$class.'"' : ''; 1207 return '<a rel="home" href="'.hu.'"'.$class.'>'.parse($thing).'</a>'; 1208 } 1209 1210 return hu; 1211 } 1212 1213 // ------------------------------------------------------------- 1214 1215 function newer($atts, $thing = false, $match = '') 1216 { 1217 global $thispage, $pretext, $permlink_mode; 1218 1219 extract(lAtts(array( 1220 'showalways' => 0, 1221 ), $atts)); 1222 1223 $numPages = $thispage['numPages']; 1224 $pg = $thispage['pg']; 1225 1226 if ($numPages > 1 and $pg > 1 and $pg <= $numPages) 1227 { 1228 $nextpg = ($pg - 1 == 1) ? 0 : ($pg - 1); 1229 1230 // author urls should use RealName, rather than username 1231 if (!empty($pretext['author'])) { 1232 $author = safe_field('RealName', 'txp_users', "name = '".doSlash($pretext['author'])."'"); 1233 } else { 1234 $author = ''; 1235 } 1236 1237 $url = pagelinkurl(array( 1238 'month' => @$pretext['month'], 1239 'pg' => $nextpg, 1240 's' => @$pretext['s'], 1241 'c' => @$pretext['c'], 1242 'q' => @$pretext['q'], 1243 'author' => $author 1244 )); 1245 1246 if ($thing) 1247 { 1248 return '<a href="'.$url.'"'. 1249 (empty($title) ? '' : ' title="'.$title.'"'). 1250 '>'.parse($thing).'</a>'; 1251 } 1252 1253 return $url; 1254 } 1255 1256 return ($showalways) ? parse($thing) : ''; 1257 } 1258 1259 // ------------------------------------------------------------- 1260 1261 function older($atts, $thing = false, $match = '') 1262 { 1263 global $thispage, $pretext, $permlink_mode; 1264 1265 extract(lAtts(array( 1266 'showalways' => 0, 1267 ), $atts)); 1268 1269 $numPages = $thispage['numPages']; 1270 $pg = $thispage['pg']; 1271 1272 if ($numPages > 1 and $pg > 0 and $pg < $numPages) 1273 { 1274 $nextpg = $pg + 1; 1275 1276 // author urls should use RealName, rather than username 1277 if (!empty($pretext['author'])) { 1278 $author = safe_field('RealName', 'txp_users', "name = '".doSlash($pretext['author'])."'"); 1279 } else { 1280 $author = ''; 1281 } 1282 1283 $url = pagelinkurl(array( 1284 'month' => @$pretext['month'], 1285 'pg' => $nextpg, 1286 's' => @$pretext['s'], 1287 'c' => @$pretext['c'], 1288 'q' => @$pretext['q'], 1289 'author' => $author 1290 )); 1291 1292 if ($thing) 1293 { 1294 return '<a href="'.$url.'"'. 1295 (empty($title) ? '' : ' title="'.$title.'"'). 1296 '>'.parse($thing).'</a>'; 1297 } 1298 1299 return $url; 1300 } 1301 1302 return ($showalways) ? parse($thing) : ''; 1303 } 1304 1305 // ------------------------------------------------------------- 1306 function text($atts) 1307 { 1308 extract(lAtts(array( 1309 'item' => '', 1310 ),$atts)); 1311 return ($item) ? gTxt($item) : ''; 1312 } 1313 1314 // ------------------------------------------------------------- 1315 1316 function article_id() 1317 { 1318 global $thisarticle; 1319 1320 assert_article(); 1321 1322 return $thisarticle['thisid']; 1323 } 1324 1325 // ------------------------------------------------------------- 1326 1327 function article_url_title() 1328 { 1329 global $thisarticle; 1330 1331 assert_article(); 1332 1333 return $thisarticle['url_title']; 1334 } 1335 1336 // ------------------------------------------------------------- 1337 1338 function if_article_id($atts, $thing) 1339 { 1340 global $thisarticle; 1341 1342 assert_article(); 1343 1344 extract(lAtts(array( 1345 'id' => '', 1346 ), $atts)); 1347 1348 if ($id) 1349 { 1350 return parse(EvalElse($thing, in_list($thisarticle['thisid'], $id))); 1351 } 1352 } 1353 1354 // ------------------------------------------------------------- 1355 1356 function posted($atts) 1357 { 1358 global $thisarticle, $id, $c, $pg, $dateformat, $archive_dateformat; 1359 1360 assert_article(); 1361 1362 extract(lAtts(array( 1363 'class' => '', 1364 'format' => '', 1365 'gmt' => '', 1366 'lang' => '', 1367 'wraptag' => '', 1368 ), $atts)); 1369 1370 if ($format) 1371 { 1372 $out = safe_strftime($format, $thisarticle['posted'], $gmt, $lang); 1373 } 1374 1375 else 1376 { 1377 if ($id or $c or $pg) 1378 { 1379 $out = safe_strftime($archive_dateformat, $thisarticle['posted']); 1380 } 1381 1382 else 1383 { 1384 $out = safe_strftime($dateformat, $thisarticle['posted']); 1385 } 1386 } 1387 1388 return ($wraptag) ? doTag($out, $wraptag, $class) : $out; 1389 } 1390 1391 // ------------------------------------------------------------- 1392 1393 function comments_count($atts) 1394 { 1395 global $thisarticle; 1396 1397 assert_article(); 1398 1399 return $thisarticle['comments_count']; 1400 } 1401 1402 // ------------------------------------------------------------- 1403 function comments_invite($atts) 1404 { 1405 global $thisarticle,$is_article_list; 1406 1407 assert_article(); 1408 1409 extract($thisarticle); 1410 global $comments_mode; 1411 1412 if (!$comments_invite) 1413 $comments_invite = @$GLOBALS['prefs']['comments_default_invite']; 1414 1415 extract(lAtts(array( 1416 'class' => __FUNCTION__, 1417 'showcount' => true, 1418 'textonly' => false, 1419 'showalways'=> false, //FIXME in crockery. This is only for BC. 1420 'wraptag' => '', 1421 ), $atts)); 1422 1423 $invite_return = ''; 1424 if (($annotate or $comments_count) && ($showalways or $is_article_list) ) { 1425 1426 $ccount = ($comments_count && $showcount) ? ' ['.$comments_count.']' : ''; 1427 if ($textonly) 1428 $invite_return = $comments_invite.$ccount; 1429 else 1430 { 1431 if (!$comments_mode) { 1432 $invite_return = doTag($comments_invite, 'a', $class, ' href="'.permlinkurl($thisarticle).'#'.gTxt('comment').'" '). $ccount; 1433 } else { 1434 $invite_return = "<a href=\"".hu."?parentid=$thisid\" onclick=\"window.open(this.href, 'popupwindow', 'width=500,height=500,scrollbars,resizable,status'); return false;\"".(($class) ? ' class="'.$class.'"' : '').'>'.$comments_invite.'</a> '.$ccount; 1435 } 1436 } 1437 if ($wraptag) $invite_return = doTag($invite_return, $wraptag, $class); 1438 } 1439 1440 return $invite_return; 1441 } 1442 // ------------------------------------------------------------- 1443 1444 function comments_form($atts) 1445 { 1446 global $thisarticle, $has_comments_preview; 1447 1448 extract(lAtts(array( 1449 'class' => __FUNCTION__, 1450 'form' => 'comment_form', 1451 'isize' => '25', 1452 'msgcols' => '25', 1453 'msgrows' => '5', 1454 'msgstyle' => '', 1455 'show_preview' => empty($has_comments_preview), 1456 'wraptag' => '', 1457 ), $atts)); 1458 1459 assert_article(); 1460 1461 extract($thisarticle); 1462 1463 $out = ''; 1464 $ip = serverset('REMOTE_ADDR'); 1465 $blacklisted = is_blacklisted($ip); 1466 1467 if (!checkCommentsAllowed($thisid)) { 1468 $out = graf(gTxt("comments_closed"), ' id="comments_closed"'); 1469 } elseif (!checkBan($ip)) { 1470 $out = graf(gTxt('you_have_been_banned'), ' id="comments_banned"'); 1471 } elseif ($blacklisted) { 1472 $out = graf(gTxt('your_ip_is_blacklisted_by'.' '.$blacklisted), ' id="comments_blacklisted"'); 1473 } elseif (gps('commented')!=='') { 1474 $out = gTxt("comment_posted"); 1475 if (gps('commented')==='0') 1476 $out .= " ". gTxt("comment_moderated"); 1477 $out = graf($out, ' id="txpCommentInputForm"'); 1478 } else { 1479 # display a comment preview if required 1480 if (ps('preview') and $show_preview) 1481 $out = comments_preview(array()); 1482 $out .= commentForm($thisid,$atts); 1483 } 1484 1485 return (!$wraptag ? $out : doTag($out,$wraptag,$class) ); 1486 } 1487 1488 // ------------------------------------------------------------- 1489 1490 function comments_error($atts) 1491 { 1492 extract(lAtts(array( 1493 'break' => 'br', 1494 'class' => __FUNCTION__, 1495 'wraptag' => 'div', 1496 ), $atts)); 1497 1498 $evaluator =& get_comment_evaluator(); 1499 1500 $errors = $evaluator->get_result_message(); 1501 1502 if ($errors) 1503 { 1504 return doWrap($errors, $wraptag, $break, $class); 1505 } 1506 } 1507 1508 // ------------------------------------------------------------- 1509 function if_comments_error($atts, $thing) 1510 { 1511 $evaluator =& get_comment_evaluator(); 1512 return parse(EvalElse($thing,(count($evaluator -> get_result_message()) > 0))); 1513 } 1514 1515 // ------------------------------------------------------------- 1516 # DEPRECATED - provided only for backwards compatibility 1517 # this functionality will be merged into comments_invite 1518 # no point in having two tags for one functionality 1519 function comments_annotateinvite($atts,$thing=NULL) 1520 { 1521 trigger_error(gTxt('deprecated_tag'), E_USER_NOTICE); 1522 1523 global $thisarticle, $pretext; 1524 1525 extract(lAtts(array( 1526 'class' => __FUNCTION__, 1527 'wraptag' => 'h3', 1528 ),$atts)); 1529 1530 assert_article(); 1531 1532 extract($thisarticle); 1533 1534 extract( 1535 safe_row( 1536 "Annotate,AnnotateInvite,unix_timestamp(Posted) as uPosted", 1537 "textpattern", 'ID = '.intval($thisid) 1538 ) 1539 ); 1540 1541 if (!$thing) 1542 $thing = $AnnotateInvite; 1543 1544 return (!$Annotate) ? '' : doTag($thing,$wraptag,$class,' id="'.gTxt('comment').'"'); 1545 } 1546 1547 // ------------------------------------------------------------- 1548 function comments($atts) 1549 { 1550 global $thisarticle, $prefs; 1551 extract($prefs); 1552 1553 extract(lAtts(array( 1554 'form' => 'comments', 1555 'wraptag' => ($comments_are_ol ? 'ol' : ''), 1556 'break' => ($comments_are_ol ? 'li' : 'div'), 1557 'class' => __FUNCTION__, 1558 'breakclass' => '', 1559 'limit' => 0, 1560 'offset' => 0, 1561 'sort' => 'posted ASC', 1562 ),$atts)); 1563 1564 assert_article(); 1565 1566 extract($thisarticle); 1567 1568 if (!$comments_count) return ''; 1569 1570 $qparts = array( 1571 'parentid='.intval($thisid).' and visible='.VISIBLE, 1572 'order by '.doSlash($sort), 1573 ($limit) ? 'limit '.intval($offset).', '.intval($limit) : '' 1574 ); 1575 1576 $rs = safe_rows_start('*, unix_timestamp(posted) as time', 'txp_discuss', join(' ', $qparts)); 1577 1578 $out = ''; 1579 1580 if ($rs) { 1581 $comments = array(); 1582 1583 while($vars = nextRow($rs)) { 1584 $GLOBALS['thiscomment'] = $vars; 1585 $comments[] = parse_form($form).n; 1586 unset($GLOBALS['thiscomment']); 1587 } 1588 1589 $out .= doWrap($comments,$wraptag,$break,$class,$breakclass); 1590 } 1591 1592 return $out; 1593 } 1594 1595 // ------------------------------------------------------------- 1596 function comments_preview($atts, $thing='', $me='') 1597 { 1598 global $has_comments_preview; 1599 1600 if (!ps('preview')) 1601 return; 1602 1603 extract(lAtts(array( 1604 'form' => 'comments', 1605 'wraptag' => '', 1606 'class' => __FUNCTION__, 1607 ),$atts)); 1608 1609 assert_article(); 1610 1611 $preview = psa(array('name','email','web','message','parentid','remember')); 1612 $preview['time'] = time(); 1613 $preview['discussid'] = 0; 1614 $preview['name'] = strip_tags($preview['name']); 1615 $preview['email'] = clean_url($preview['email']); 1616 if ($preview['message'] == '') 1617 { 1618 $in = getComment(); 1619 $preview['message'] = $in['message']; 1620 1621 } 1622 $preview['message'] = markup_comment(substr(trim($preview['message']), 0, 65535)); // it is called 'message', not 'novel' 1623 $preview['web'] = clean_url($preview['web']); 1624 1625 $GLOBALS['thiscomment'] = $preview; 1626 $comments = parse_form($form).n; 1627 unset($GLOBALS['thiscomment']); 1628 $out = doTag($comments,$wraptag,$class); 1629 1630 # set a flag, to tell the comments_form tag that it doesn't have to show a preview 1631 $has_comments_preview = true; 1632 1633 return $out; 1634 } 1635 1636 // ------------------------------------------------------------- 1637 function if_comments_preview($atts, $thing) 1638 { 1639 return parse(EvalElse($thing, ps('preview') && checkCommentsAllowed(gps('parentid')) )); 1640 } 1641 1642 // ------------------------------------------------------------- 1643 function comment_permlink($atts,$thing) 1644 { 1645 global $thisarticle, $thiscomment; 1646 1647 assert_article(); 1648 assert_comment(); 1649 1650 extract($thiscomment); 1651 extract(lAtts(array( 1652 'anchor' => empty($thiscomment['has_anchor_tag']), 1653 ),$atts)); 1654 1655 $dlink = permlinkurl($thisarticle).'#c'.$discussid; 1656 1657 $thing = parse($thing); 1658 1659 $name = ($anchor ? ' id="c'.$discussid.'"' : ''); 1660 1661 return tag($thing,'a',' href="'.$dlink.'"'.$name); 1662 } 1663 1664 // ------------------------------------------------------------- 1665 function comment_id($atts) 1666 { 1667 global $thiscomment; 1668 1669 assert_comment(); 1670 1671 return $thiscomment['discussid']; 1672 } 1673 1674 // ------------------------------------------------------------- 1675 1676 function comment_name($atts) 1677 { 1678 global $thiscomment, $prefs; 1679 1680 assert_comment(); 1681 1682 extract($prefs); 1683 extract($thiscomment); 1684 1685 extract(lAtts(array( 1686 'link' => 1, 1687 ), $atts)); 1688 1689 if ($link) 1690 { 1691 $web = str_replace('http://', '', $web); 1692 $nofollow = (@$comment_nofollow ? ' rel="nofollow"' : ''); 1693 1694 if ($web) 1695 { 1696 return '<a href="http://'.htmlspecialchars($web).'"'.$nofollow.'>'.htmlspecialchars($name).'</a>'; 1697 } 1698 1699 if ($email && !$never_display_email) 1700 { 1701 return '<a href="'.eE('mailto:'.$email).'"'.$nofollow.'>'.htmlspecialchars($name).'</a>'; 1702 } 1703 } 1704 1705 return $name; 1706 } 1707 1708 // ------------------------------------------------------------- 1709 function comment_email($atts) 1710 { 1711 global $thiscomment; 1712 1713 assert_comment(); 1714 1715 return htmlspecialchars($thiscomment['email']); 1716 } 1717 1718 // ------------------------------------------------------------- 1719 function comment_web($atts) 1720 { 1721 global $thiscomment; 1722 1723 assert_comment(); 1724 1725 return htmlspecialchars($thiscomment['web']); 1726 } 1727 1728 // ------------------------------------------------------------- 1729 1730 function comment_time($atts) 1731 { 1732 global $thiscomment, $comments_dateformat; 1733 1734 assert_comment(); 1735 1736 extract(lAtts(array( 1737 'format' => $comments_dateformat, 1738 'gmt' => '', 1739 'lang' => '', 1740 ), $atts)); 1741 1742 return safe_strftime($format, $thiscomment['time'], $gmt, $lang); 1743 } 1744 1745 // ------------------------------------------------------------- 1746 function comment_message($atts) 1747 { 1748 global $thiscomment; 1749 1750 assert_comment(); 1751 1752 return $thiscomment['message']; 1753 } 1754 1755 // ------------------------------------------------------------- 1756 function comment_anchor($atts) 1757 { 1758 global $thiscomment; 1759 1760 assert_comment(); 1761 1762 $thiscomment['has_anchor_tag'] = 1; 1763 return '<a id="c'.$thiscomment['discussid'].'"></a>'; 1764 } 1765 1766 // ------------------------------------------------------------- 1767 // DEPRECATED: the old comment message body tag 1768 function message($atts) 1769 { 1770 trigger_error(gTxt('deprecated_tag'), E_USER_NOTICE); 1771 1772 return comment_message($atts); 1773 } 1774 1775 // ------------------------------------------------------------- 1776 1777 function author($atts) 1778 { 1779 global $thisarticle, $s; 1780 1781 assert_article(); 1782 1783 extract(lAtts(array( 1784 'link' => '', 1785 'section' => '', 1786 'this_section' => 0, 1787 ), $atts)); 1788 1789 $author_name = get_author_name($thisarticle['authorid']); 1790 1791 $section = ($this_section) ? ( $s == 'default' ? '' : $s ) : $section; 1792 1793 return ($link) ? 1794 href($author_name, pagelinkurl(array('s' => $section, 'author' => $author_name))) : 1795 $author_name; 1796 } 1797 1798 // ------------------------------------------------------------- 1799 1800 function if_author($atts, $thing) 1801 { 1802 global $author; 1803 1804 extract(lAtts(array( 1805 'name' => '', 1806 ), $atts)); 1807 1808 if ($name) 1809 { 1810 return parse(EvalElse($thing, in_list($author, $name))); 1811 } 1812 1813 return parse(EvalElse($thing, !empty($author))); 1814 } 1815 1816 // ------------------------------------------------------------- 1817 1818 function if_article_author($atts, $thing) 1819 { 1820 global $thisarticle; 1821 1822 assert_article(); 1823 1824 extract(lAtts(array( 1825 'name' => '', 1826 ), $atts)); 1827 1828 $author = $thisarticle['authorid']; 1829 1830 if ($name) 1831 { 1832 return parse(EvalElse($thing, in_list($author, $name))); 1833 } 1834 1835 return parse(EvalElse($thing, !empty($author))); 1836 } 1837 1838 // ------------------------------------------------------------- 1839 1840 function body($atts) 1841 { 1842 global $thisarticle, $is_article_body; 1843 assert_article(); 1844 1845 $is_article_body = 1; 1846 $out = parse($thisarticle['body']); 1847 $is_article_body = 0; 1848 return $out; 1849 } 1850 1851 // ------------------------------------------------------------- 1852 function title($atts) 1853 { 1854 global $thisarticle, $prefs; 1855 assert_article(); 1856 extract(lAtts(array( 1857 'no_widow' => @$prefs['title_no_widow'], 1858 ), $atts)); 1859 1860 $t = escape_title($thisarticle['title']); 1861 if ($no_widow) 1862 $t = noWidow($t); 1863 return $t; 1864 } 1865 1866 // ------------------------------------------------------------- 1867 function excerpt($atts) 1868 { 1869 global $thisarticle, $is_article_body; 1870 assert_article(); 1871 1872 $is_article_body = 1; 1873 $out = parse($thisarticle['excerpt']); 1874 $is_article_body = 0; 1875 return $out; 1876 } 1877 1878 // ------------------------------------------------------------- 1879 1880 function category1($atts, $thing = '') 1881 { 1882 global $thisarticle, $s, $permlink_mode; 1883 1884 assert_article(); 1885 1886 extract(lAtts(array( 1887 'class' => '', 1888 'link' => 0, 1889 'title' => 0, 1890 'section' => '', 1891 'this_section' => 0, 1892 'wraptag' => '', 1893 ), $atts)); 1894 1895 if ($thisarticle['category1']) 1896 { 1897 $section = ($this_section) ? ( $s == 'default' ? '' : $s ) : $section; 1898 $category = $thisarticle['category1']; 1899 1900 $label = ($title) ? fetch_category_title($category) : $category; 1901 1902 if ($thing) 1903 { 1904 $out = '<a'. 1905 ($permlink_mode != 'messy' ? ' rel="tag"' : ''). 1906 ( ($class and !$wraptag) ? ' class="'.$class.'"' : '' ). 1907 ' href="'.pagelinkurl(array('s' => $section, 'c' => $category)).'"'. 1908 ($title ? ' title="'.$label.'"' : ''). 1909 '>'.parse($thing).'</a>'; 1910 } 1911 1912 elseif ($link) 1913 { 1914 $out = '<a'. 1915 ($permlink_mode != 'messy' ? ' rel="tag"' : ''). 1916 ' href="'.pagelinkurl(array('s' => $section, 'c' => $category)).'">'.$label.'</a>'; 1917 } 1918 1919 else 1920 { 1921 $out = $label; 1922 } 1923 1924 return doTag($out, $wraptag, $class); 1925 } 1926 } 1927 1928 // ------------------------------------------------------------- 1929 1930 function category2($atts, $thing = '') 1931 { 1932 global $thisarticle, $s, $permlink_mode; 1933 1934 assert_article(); 1935 1936 extract(lAtts(array( 1937 'class' => '', 1938 'link' => 0, 1939 'title' => 0, 1940 'section' => '', 1941 'this_section' => 0, 1942 'wraptag' => '', 1943 ), $atts)); 1944 1945 if ($thisarticle['category2']) 1946 { 1947 $section = ($this_section) ? ( $s == 'default' ? '' : $s ) : $section; 1948 $category = $thisarticle['category2']; 1949 1950 $label = ($title) ? fetch_category_title($category) : $category; 1951 1952 if ($thing) 1953 { 1954 $out = '<a'. 1955 ($permlink_mode != 'messy' ? ' rel="tag"' : ''). 1956 ( ($class and !$wraptag) ? ' class="'.$class.'"' : '' ). 1957 ' href="'.pagelinkurl(array('s' => $section, 'c' => $category)).'"'. 1958 ($title ? ' title="'.$label.'"' : ''). 1959 '>'.parse($thing).'</a>'; 1960 } 1961 1962 elseif ($link) 1963 { 1964 $out = '<a'. 1965 ($permlink_mode != 'messy' ? ' rel="tag"' : ''). 1966 ' href="'.pagelinkurl(array('s' => $section, 'c' => $category)).'">'.$label.'</a>'; 1967 } 1968 1969 else 1970 { 1971 $out = $label; 1972 } 1973 1974 return doTag($out, $wraptag, $class); 1975 } 1976 } 1977 1978 // ------------------------------------------------------------- 1979 1980 function category($atts, $thing = '') 1981 { 1982 global $s, $c; 1983 1984 extract(lAtts(array( 1985 'class' => '', 1986 'link' => 0, 1987 'name' => '', 1988 'section' => $s, // fixme in crockery 1989 'this_section' => 0, 1990 'title' => 0, 1991 'type' => 'article', 1992 'wraptag' => '', 1993 ), $atts)); 1994 1995 $category = ($name) ? $name : $c; 1996 1997 if ($category) 1998 { 1999 $section = ($this_section) ? ( $s == 'default' ? '' : $s ) : $section; 2000 $label = ($title) ? fetch_category_title($category, $type) : $category; 2001 2002 if ($thing) 2003 { 2004 $out = '<a href="'.pagelinkurl(array('s' => $section, 'c' => $category,)).'"'. 2005 ( ($class and !$wraptag) ? ' class="'.$class.'"' : '' ). 2006 ($title ? ' title="'.$label.'"' : ''). 2007 '>'.parse($thing).'</a>'; 2008 } 2009 2010 elseif ($link) 2011 { 2012 $out = href($label, 2013 pagelinkurl(array('s' => $section, 'c' => $category)) 2014 ); 2015 } 2016 2017 else 2018 { 2019 $out = $label; 2020 } 2021 2022 return doTag($out, $wraptag, $class); 2023 } 2024 } 2025 2026 // ------------------------------------------------------------- 2027 2028 function section($atts, $thing = '') 2029 { 2030 global $thisarticle, $s; 2031 2032 extract(lAtts(array( 2033 'class' => '', 2034 'link' => 0, 2035 'name' => '', 2036 'title' => 0, 2037 'wraptag' => '', 2038 ), $atts)); 2039 2040 if ($name) 2041 { 2042 $sec = $name; 2043 } 2044 2045 elseif (!empty($thisarticle['section'])) 2046 { 2047 $sec = $thisarticle['section']; 2048 } 2049 2050 else 2051 { 2052 $sec = $s; 2053 } 2054 2055 if ($sec) 2056 { 2057 $label = ($title) ? fetch_section_title($sec) : $sec; 2058 2059 if ($thing) 2060 { 2061 $out = '<a href="'.pagelinkurl(array('s' => $sec)).'"'. 2062 ( ($class and !$wraptag) ? ' class="'.$class.'"' : '' ). 2063 ($title ? ' title="'.$label.'"' : ''). 2064 '>'.parse($thing).'</a>'; 2065 } 2066 2067 elseif ($link) 2068 { 2069 $out = href($label, 2070 pagelinkurl(array('s' => $sec)) 2071 ); 2072 } 2073 2074 else 2075 { 2076 $out = $label; 2077 } 2078 2079 return doTag($out, $wraptag, $class); 2080 } 2081 } 2082 2083 // ------------------------------------------------------------- 2084 function keywords($atts) 2085 { 2086 global $thisarticle; 2087 assert_article(); 2088 2089 return $thisarticle['keywords']; 2090 } 2091 2092 // ------------------------------------------------------------- 2093 2094 function article_image($atts) 2095 { 2096 global $thisarticle, $img_dir; 2097 2098 assert_article(); 2099 2100 extract(lAtts(array( 2101 'align' => '', // remove in crockery 2102 'class' => '', 2103 'escape' => '', 2104 'html_id' => '', 2105 'style' => '', // remove in crockery? 2106 'thumbnail' => 0, 2107 'wraptag' => '', 2108 ), $atts)); 2109 2110 if ($thisarticle['article_image']) 2111 { 2112 $image = $thisarticle['article_image']; 2113 } 2114 2115 else 2116 { 2117 return; 2118 } 2119 2120 if (is_numeric($image)) 2121 { 2122 $rs = safe_row('*', 'txp_image', 'id = '.intval($image)); 2123 2124 if ($rs) 2125 { 2126 if ($thumbnail) 2127 { 2128 if ($rs['thumbnail']) 2129 { 2130 extract($rs); 2131 2132 if ($escape == 'html') 2133 { 2134 $alt = htmlspecialchars($alt); 2135 $caption = htmlspecialchars($caption); 2136 } 2137 2138 $out = '<img src="'.hu.$img_dir.'/'.$id.'t'.$ext.'" alt="'.$alt.'"'. 2139 ($caption ? ' title="'.$caption.'"' : ''). 2140 ( ($html_id and !$wraptag) ? ' id="'.$html_id.'"' : '' ). 2141 ( ($class and !$wraptag) ? ' class="'.$class.'"' : '' ). 2142 ($style ? ' style="'.$style.'"' : ''). 2143 ($align ? ' align="'.$align.'"' : ''). 2144 ' />'; 2145 } 2146 2147 else 2148 { 2149 return ''; 2150 } 2151 } 2152 2153 else 2154 { 2155 extract($rs); 2156 2157 if ($escape == 'html') 2158 { 2159 $alt = htmlspecialchars($alt); 2160 $caption = htmlspecialchars($caption); 2161 } 2162 2163 $out = '<img src="'.hu.$img_dir.'/'.$id.$ext.'" width="'.$w.'" height="'.$h.'" alt="'.$alt.'"'. 2164 ($caption ? ' title="'.$caption.'"' : ''). 2165 ( ($html_id and !$wraptag) ? ' id="'.$html_id.'"' : '' ). 2166 ( ($class and !$wraptag) ? ' class="'.$class.'"' : '' ). 2167 ($style ? ' style="'.$style.'"' : ''). 2168 ($align ? ' align="'.$align.'"' : ''). 2169 ' />'; 2170 } 2171 } 2172 2173 else 2174 { 2175 trigger_error(gTxt('unknown_image')); 2176 return; 2177 } 2178 } 2179 2180 else 2181 { 2182 $out = '<img src="'.$image.'" alt=""'. 2183 ( ($html_id and !$wraptag) ? ' id="'.$html_id.'"' : '' ). 2184 ( ($class and !$wraptag) ? ' class="'.$class.'"' : '' ). 2185 ($style ? ' style="'.$style.'"' : ''). 2186 ($align ? ' align="'.$align.'"' : ''). 2187 ' />'; 2188 } 2189 2190 return ($wraptag) ? doTag($out, $wraptag, $class, '', $html_id) : $out; 2191 } 2192 2193 // ------------------------------------------------------------- 2194 function search_result_title($atts) 2195 { 2196 return permlink($atts, '<txp:title />'); 2197 } 2198 2199 // ------------------------------------------------------------- 2200 function search_result_excerpt($atts) 2201 { 2202 global $thisarticle, $pretext; 2203 2204 assert_article(); 2205 2206 extract(lAtts(array( 2207 'break' => ' …', 2208 'hilight' => 'strong', 2209 'limit' => 5, 2210 ), $atts)); 2211 2212 $q = $pretext['q']; 2213 2214 $result = preg_replace('/\s+/', ' ', strip_tags(str_replace('><', '> <', $thisarticle['body']))); 2215 preg_match_all("/\b.{1,50}".preg_quote($q).".{1,50}\b/iu", $result, $concat); 2216 2217 for ($i = 0, $r = array(); $i < min($limit, count($concat[0])); $i++) 2218 { 2219 $r[] = trim($concat[0][$i]); 2220 } 2221 2222 $concat = join($break.n, $r); 2223 $concat = preg_replace('/^[^>]+>/U', '', $concat); 2224 $concat = preg_replace('/('.preg_quote($q).')/i', "<$hilight>$1</$hilight>", $concat); 2225 2226 return ($concat) ? trim($break.$concat.$break) : ''; 2227 } 2228 2229 // ------------------------------------------------------------- 2230 function search_result_url($atts) 2231 { 2232 global $thisarticle; 2233 assert_article(); 2234 2235 $l = permlinkurl($thisarticle); 2236 return permlink($atts, $l); 2237 } 2238 2239 // ------------------------------------------------------------- 2240 function search_result_date($atts) 2241 { 2242 assert_article(); 2243 return posted($atts); 2244 } 2245 2246 // ------------------------------------------------------------- 2247 function search_result_count($atts) 2248 { 2249 global $thispage; 2250 $t = @$thispage['grand_total']; 2251 extract(lAtts(array( 2252 'text' => ($t == 1 ? gTxt('article_found') : gTxt('articles_found')), 2253 ),$atts)); 2254 2255 return $t . ($text ? ' ' . $text : ''); 2256 } 2257 2258 // ------------------------------------------------------------- 2259 function image_index($atts) 2260 { 2261 global $s,$c,$p,$img_dir,$path_to_site; 2262 extract(lAtts(array( 2263 'label' => '', 2264 'break' => br, 2265 'wraptag' => '', 2266 'class' => __FUNCTION__, 2267 'labeltag' => '', 2268 'c' => $c, // Keep the option to override categories due to backward compatiblity 2269 'limit' => 0, 2270 'offset' => 0, 2271 'sort' => 'name ASC', 2272 ),$atts)); 2273 2274 $qparts = array( 2275 "category = '".doSlash($c)."' and thumbnail = 1", 2276 'order by '.doSlash($sort), 2277 ($limit) ? 'limit '.intval($offset).', '.intval($limit) : '' 2278 ); 2279 2280 $rs = safe_rows_start('*', 'txp_image', join(' ', $qparts)); 2281 2282 if ($rs) { 2283 $out = array(); 2284 while ($a = nextRow($rs)) { 2285 extract($a); 2286 $impath = $img_dir.'/'.$id.'t'.$ext; 2287 $imginfo = getimagesize($path_to_site.'/'.$impath); 2288 $dims = (!empty($imginfo[3])) ? ' '.$imginfo[3] : ''; 2289 $url = pagelinkurl(array('c'=>$c, 's'=>$s, 'p'=>$id)); 2290 $out[] = '<a href="'.$url.'">'. 2291 '<img src="'.hu.$impath.'"'.$dims.' alt="'.$alt.'" />'.'</a>'; 2292 2293 } 2294 if (count($out)) { 2295 return doLabel($label, $labeltag).doWrap($out, $wraptag, $break, $class); 2296 } 2297 } 2298 return ''; 2299 } 2300 2301 // ------------------------------------------------------------- 2302 function image_display($atts) 2303 { 2304 if (is_array($atts)) extract($atts); 2305 global $s,$c,$p,$img_dir; 2306 if($p) { 2307 $rs = safe_row("*", "txp_image", 'id='.intval($p).' limit 1'); 2308 if ($rs) { 2309 extract($rs); 2310 $impath = hu.$img_dir.'/'.$id.$ext; 2311 return '<img src="'.$impath. 2312 '" style="height:'.$h.'px;width:'.$w.'px" alt="'.$alt.'" />'; 2313 } 2314 } 2315 } 2316 2317 // ------------------------------------------------------------- 2318 function if_comments($atts, $thing) 2319 { 2320 global $thisarticle; 2321 assert_article(); 2322 2323 return parse(EvalElse($thing, ($thisarticle['comments_count'] > 0))); 2324 } 2325 2326 // ------------------------------------------------------------- 2327 function if_comments_allowed($atts, $thing) 2328 { 2329 global $thisarticle; 2330 assert_article(); 2331 2332 return parse(EvalElse($thing, checkCommentsAllowed($thisarticle['thisid']))); 2333 } 2334 2335 // ------------------------------------------------------------- 2336 function if_comments_disallowed($atts, $thing) 2337 { 2338 global $thisarticle; 2339 assert_article(); 2340 2341 return parse(EvalElse($thing, !checkCommentsAllowed($thisarticle['thisid']))); 2342 } 2343 2344 // ------------------------------------------------------------- 2345 function if_individual_article($atts, $thing) 2346 { 2347 global $is_article_list; 2348 return parse(EvalElse($thing, ($is_article_list == false))); 2349 } 2350 2351 // ------------------------------------------------------------- 2352 function if_article_list($atts, $thing) 2353 { 2354 global $is_article_list; 2355 return parse(EvalElse($thing, ($is_article_list == true))); 2356 } 2357 2358 // ------------------------------------------------------------- 2359 function meta_keywords() 2360 { 2361 global $id_keywords; 2362 return ($id_keywords) 2363 ? '<meta name="keywords" content="'.$id_keywords.'" />' 2364 : ''; 2365 } 2366 2367 // ------------------------------------------------------------- 2368 function meta_author() 2369 { 2370 global $id_author; 2371 return ($id_author) 2372 ? '<meta name="author" content="'.$id_author.'" />' 2373 : ''; 2374 } 2375 2376 // ------------------------------------------------------------- 2377 2378 function doWrap($list, $wraptag, $break, $class = '', $breakclass = '', $atts = '', $breakatts = '', $id = '') 2379 { 2380 if (!$list) 2381 { 2382 return ''; 2383 } 2384 2385 if ($id) 2386 { 2387 $atts .= ' id="'.$id.'"'; 2388 } 2389 2390 if ($class) 2391 { 2392 $atts .= ' class="'.$class.'"'; 2393 } 2394 2395 if ($breakclass) 2396 { 2397 $breakatts.= ' class="'.$breakclass.'"'; 2398 } 2399 2400 // non-enclosing breaks 2401 if (!preg_match('/^\w+$/', $break) or $break == 'br' or $break == 'hr') 2402 { 2403 if ($break == 'br' or $break == 'hr') 2404 { 2405 $break = "<$break $breakatts/>".n; 2406 } 2407 2408 return ($wraptag) ? tag(join($break, $list), $wraptag, $atts) : join($break, $list); 2409 } 2410 2411 // enclosing breaks should be specified by name only, no '<' or '>' 2412 if (($wraptag == 'ul' or $wraptag == 'ol') and empty($break)) 2413 { 2414 $break = 'li'; 2415 } 2416 2417 return ($wraptag) ? 2418 tag(n.t.tag(join("</$break>".n.t."<{$break}{$breakatts}>", $list), $break, $breakatts).n, $wraptag, $atts) : 2419 tag(n.join("</$break>".n."<{$break}{$breakatts}>".n, $list).n, $break, $breakatts); 2420 } 2421 2422 // ------------------------------------------------------------- 2423 2424 function doTag($content, $tag, $class = '', $atts = '', $id = '') 2425 { 2426 if ($id) 2427 { 2428 $atts .= ' id="'.$id.'"'; 2429 } 2430 2431 if ($class) 2432 { 2433 $atts .= ' class="'.$class.'"'; 2434 } 2435 2436 if (!$tag) 2437 { 2438 return $content; 2439 } 2440 2441 return ($content) ? tag($content, $tag, $atts) : "<$tag $atts />"; 2442 } 2443 2444 // ------------------------------------------------------------- 2445 function doLabel($label='', $labeltag='') 2446 { 2447 if ($label) { 2448 return (empty($labeltag)? $label.'<br />' : tag($label, $labeltag)); 2449 } 2450 return ''; 2451 } 2452 2453 // ------------------------------------------------------------- 2454 2455 function permlink($atts, $thing = NULL) 2456 { 2457 global $thisarticle; 2458 2459 extract(lAtts(array( 2460 'class' => '', 2461 'id' => '', 2462 'style' => '', 2463 'title' => '', 2464 ), $atts)); 2465 2466 if (!$id) 2467 { 2468 assert_article(); 2469 } 2470 2471 $url = ($id) ? permlinkurl_id($id) : permlinkurl($thisarticle); 2472 2473 if ($url) 2474 { 2475 if ($thing === NULL) 2476 { 2477 return $url; 2478 } 2479 2480 return tag(parse($thing), 'a', ' rel="bookmark" href="'.$url.'"'. 2481 ($title ? ' title="'.$title.'"' : ''). 2482 ($style ? ' style="'.$style.'"' : ''). 2483 ($class ? ' class="'.$class.'"' : '') 2484 ); 2485 } 2486 } 2487 2488 // ------------------------------------------------------------- 2489 2490 function permlinkurl_id($id) 2491 { 2492 $id = (int) $id; 2493 2494 $rs = safe_row( 2495 "ID as thisid, Section as section, Title as title, url_title, unix_timestamp(Posted) as posted", 2496 'textpattern', 2497 "ID = $id" 2498 ); 2499 2500 return permlinkurl($rs); 2501 } 2502 2503 // ------------------------------------------------------------- 2504 function permlinkurl($article_array) 2505 { 2506 global $permlink_mode, $prefs; 2507 2508 if (isset($prefs['custom_url_func']) and is_callable($prefs['custom_url_func'])) 2509 return call_user_func($prefs['custom_url_func'], $article_array); 2510 2511 if (empty($article_array)) return; 2512 2513 extract($article_array); 2514 2515 if (!isset($title)) $title = $Title; 2516 if (empty($url_title)) $url_title = stripSpace($title); 2517 if (empty($section)) $section = $Section; // lame, huh? 2518 if (empty($posted)) $posted = $Posted; 2519 if (empty($thisid)) $thisid = $ID; 2520 2521 $section = urlencode($section); 2522 $url_title = urlencode($url_title); 2523 2524 switch($permlink_mode) { 2525 case 'section_id_title': 2526 if ($prefs['attach_titles_to_permalinks']) 2527 { 2528 return hu."$section/$thisid/$url_title"; 2529 }else{ 2530 return hu."$section/$thisid/"; 2531 } 2532 case 'year_month_day_title': 2533 list($y,$m,$d) = explode("-",date("Y-m-d",$posted)); 2534 return hu."$y/$m/$d/$url_title"; 2535 case 'id_title': 2536 if ($prefs['attach_titles_to_permalinks']) 2537 { 2538 return hu."$thisid/$url_title"; 2539 }else{ 2540 return hu."$thisid/"; 2541 } 2542 case 'section_title': 2543 return hu."$section/$url_title"; 2544 case 'title_only': 2545 return hu."$url_title"; 2546 case 'messy': 2547 return hu."index.php?id=$thisid"; 2548 } 2549 } 2550 2551 // ------------------------------------------------------------- 2552 function lang($atts) 2553 { 2554 return LANG; 2555 } 2556 2557 // ------------------------------------------------------------- 2558 # DEPRECATED - provided only for backwards compatibility 2559 function formatPermLink($ID,$Section) 2560 { 2561 trigger_error(gTxt('deprecated_tag'), E_USER_NOTICE); 2562 2563 return permlinkurl_id($ID); 2564 } 2565 2566 // ------------------------------------------------------------- 2567 # DEPRECATED - provided only for backwards compatibility 2568 function formatCommentsInvite($AnnotateInvite,$Section,$ID) 2569 { 2570 trigger_error(gTxt('deprecated_tag'), E_USER_NOTICE); 2571 2572 global $comments_mode; 2573 2574 $dc = safe_count('txp_discuss','parentid='.intval($ID).' and visible='.VISIBLE); 2575 2576 $ccount = ($dc) ? '['.$dc.']' : ''; 2577 if (!$comments_mode) { 2578 return '<a href="'.permlinkurl_id($ID).'/#'.gTxt('comment'). 2579 '">'.$AnnotateInvite.'</a>'. $ccount; 2580 } else { 2581 return "<a href=\"".hu."?parentid=$ID\" onclick=\"window.open(this.href, 'popupwindow', 'width=500,height=500,scrollbars,resizable,status'); return false;\">".$AnnotateInvite.'</a> '.$ccount; 2582 } 2583 2584 } 2585 // ------------------------------------------------------------- 2586 # DEPRECATED - provided only for backwards compatibility 2587 function doPermlink($text, $plink, $Title, $url_title) 2588 { 2589 trigger_error(gTxt('deprecated_tag'), E_USER_NOTICE); 2590 2591 global $url_mode; 2592 $Title = ($url_title) ? $url_title : stripSpace($Title); 2593 $Title = ($url_mode) ? $Title : ''; 2594 return preg_replace("/<(txp:permlink)>(.*)<\/\\1>/sU", 2595 "<a href=\"".$plink.$Title."\" title=\"".gTxt('permanent_link')."\">$2</a>",$text); 2596 } 2597 2598 // ------------------------------------------------------------- 2599 # DEPRECATED - provided only for backwards compatibility 2600 function doArticleHref($ID,$Title,$url_title,$Section) 2601 { 2602 trigger_error(gTxt('deprecated_tag'), E_USER_NOTICE); 2603 2604 $conTitle = ($url_title) ? $url_title : stripSpace($Title); 2605 return ($GLOBALS['url_mode']) 2606 ? tag($Title,'a',' href="'.hu.$Section.'/'.$ID.'/'.$conTitle.'"') 2607 : tag($Title,'a',' href="'.hu.'index.php?id='.$ID.'"'); 2608 } 2609 2610 // ------------------------------------------------------------- 2611 2612 function breadcrumb($atts) 2613 { 2614 global $pretext,$sitename; 2615 2616 extract(lAtts(array( 2617 'wraptag' => 'p', 2618 'sep' => ' » ', 2619 'link' => 1, 2620 'label' => $sitename, 2621 'title' => '', 2622 'class' => '', 2623 'linkclass' => 'noline', 2624 ),$atts)); 2625 2626 // bc, get rid of in crockery 2627 if ($link == 'y') { 2628 $linked = true; 2629 } elseif ($link == 'n') { 2630 $linked = false; 2631 } else { 2632 $linked = $link; 2633 } 2634 2635 if ($linked) $label = doTag($label,'a',$linkclass,' href="'.hu.'"'); 2636 2637 $content = array(); 2638 extract($pretext); 2639 if(!empty($s) && $s!= 'default') 2640 { 2641 $section_title = ($title) ? fetch_section_title($s) : $s; 2642 $section_title_html = escape_title($section_title); 2643 $content[] = ($linked)? ( 2644 doTag($section_title_html,'a',$linkclass,' href="'.pagelinkurl(array('s'=>$s)).'"') 2645 ):$section_title_html; 2646 } 2647 2648 $category = empty($c)? '': $c; 2649 2650 foreach (getTreePath($category, 'article') as $cat) { 2651 if ($cat['name'] != 'root') { 2652 $category_title_html = $title ? escape_title($cat['title']) : $cat['name']; 2653 $content[] = ($linked)? 2654 doTag($category_title_html,'a',$linkclass,' href="'.pagelinkurl(array('c'=>$cat['name'])).'"') 2655 :$category_title_html; 2656 } 2657 } 2658 2659 // add the label at the end, to prevent breadcrumb for home page 2660 if ($content) 2661 { 2662 $content = array_merge(array($label), $content); 2663 2664 return doTag(join($sep, $content), $wraptag, $class); 2665 } 2666 } 2667 2668 2669 //------------------------------------------------------------------------ 2670 2671 function if_excerpt($atts, $thing) 2672 { 2673 global $thisarticle; 2674 assert_article(); 2675 # eval condition here. example for article excerpt 2676 $excerpt = trim($thisarticle['excerpt']); 2677 $condition = (!empty($excerpt))? true : false; 2678 return parse(EvalElse($thing, $condition)); 2679 } 2680 2681 //-------------------------------------------------------------------------- 2682 // Searches use default page. This tag allows you to use different templates if searching 2683 //-------------------------------------------------------------------------- 2684 2685 function if_search($atts, $thing) 2686 { 2687 global $pretext; 2688 return parse(EvalElse($thing, !empty($pretext['q']))); 2689 } 2690 2691 //-------------------------------------------------------------------------- 2692 2693 function if_search_results($atts, $thing) 2694 { 2695 global $thispage, $pretext; 2696 2697 if(empty($pretext['q'])) return ''; 2698 2699 extract(lAtts(array( 2700 'min' => 1, 2701 'max' => 0, 2702 ),$atts)); 2703 2704 $results = (int)$thispage['grand_total']; 2705 return parse(EvalElse($thing, $results >= $min && (!$max || $results <= $max))); 2706 } 2707 2708 //-------------------------------------------------------------------------- 2709 function if_category($atts, $thing) 2710 { 2711 global $c; 2712 2713 extract(lAtts(array( 2714 'name' => '', 2715 ),$atts)); 2716 2717 if (trim($name)) { 2718 return parse(EvalElse($thing, in_list($c, $name))); 2719 } 2720 2721 return parse(EvalElse($thing, !empty($c))); 2722 } 2723 2724 //-------------------------------------------------------------------------- 2725 2726 function if_article_category($atts, $thing) 2727 { 2728 global $thisarticle; 2729 2730 assert_article(); 2731 2732 extract(lAtts(array( 2733 'name' => '', 2734 'number' => '', 2735 ), $atts)); 2736 2737 $cats = array(); 2738 2739 if ($number) { 2740 if (!empty($thisarticle['category'.$number])) { 2741 $cats = array($thisarticle['category'.$number]); 2742 } 2743 } else { 2744 if (!empty($thisarticle['category1'])) { 2745 $cats[] = $thisarticle['category1']; 2746 } 2747 2748 if (!empty($thisarticle['category2'])) { 2749 $cats[] = $thisarticle['category2']; 2750 } 2751 2752 $cats = array_unique($cats); 2753 } 2754 2755 if ($name) { 2756 return parse(EvalElse($thing, array_intersect(do_list($name), $cats))); 2757 } else { 2758 return parse(EvalElse($thing, ($cats))); 2759 } 2760 } 2761 2762 //-------------------------------------------------------------------------- 2763 function if_section($atts, $thing) 2764 { 2765 global $pretext; 2766 extract($pretext); 2767 2768 extract(lAtts(array( 2769 'name' => '', 2770 ),$atts)); 2771 2772 $section = ($s == 'default' ? '' : $s); 2773 2774 if ($section) 2775 return parse(EvalElse($thing, in_list($section, $name))); 2776 else 2777 return parse(EvalElse($thing, in_list('', $name) or in_list('default', $name))); 2778 2779 } 2780 2781 //-------------------------------------------------------------------------- 2782 function if_article_section($atts, $thing) 2783 { 2784 global $thisarticle; 2785 assert_article(); 2786 2787 extract(lAtts(array( 2788 'name' => '', 2789 ),$atts)); 2790 2791 $section = $thisarticle['section']; 2792 2793 return parse(EvalElse($thing, in_list($section, $name))); 2794 } 2795 2796 //-------------------------------------------------------------------------- 2797 function php($atts, $thing) 2798 { 2799 global $is_article_body, $thisarticle, $prefs; 2800 2801 ob_start(); 2802 if (empty($is_article_body)) { 2803 if (!empty($prefs['allow_page_php_scripting'])) 2804 eval($thing); 2805 else 2806 trigger_error(gTxt('php_code_disabled_page')); 2807 } 2808 else { 2809 if (!empty($prefs['allow_article_php_scripting'])) { 2810 if (has_privs('article.php', $thisarticle['authorid'])) 2811 eval($thing); 2812 else 2813 trigger_error(gTxt('php_code_forbidden_user')); 2814 } 2815 else 2816 trigger_error(gTxt('php_code_disabled_article')); 2817 } 2818 return ob_get_clean(); 2819 } 2820 2821 //-------------------------------------------------------------------------- 2822 function custom_field($atts) 2823 { 2824 global $thisarticle, $prefs; 2825 assert_article(); 2826 2827 extract(lAtts(array( 2828 'name' => @$prefs['custom_1_set'], 2829 'escape' => '', 2830 'default' => '', 2831 ),$atts)); 2832 2833 $name = strtolower($name); 2834 if (!empty($thisarticle[$name])) 2835 $out = $thisarticle[$name]; 2836 else 2837 $out = $default; 2838 2839 return ($escape == 'html' ? htmlspecialchars($out) : $out); 2840 } 2841 2842 //-------------------------------------------------------------------------- 2843 function if_custom_field($atts, $thing) 2844 { 2845 global $thisarticle, $prefs; 2846 assert_article(); 2847 2848 extract(lAtts(array( 2849 'name' => @$prefs['custom_1_set'], 2850 'val' => NULL, 2851 ),$atts)); 2852 2853 $name = strtolower($name); 2854 if ($val !== NULL) 2855 $cond = (@$thisarticle[$name] == $val); 2856 else 2857 $cond = !empty($thisarticle[$name]); 2858 2859 return parse(EvalElse($thing, $cond)); 2860 } 2861 2862 // ------------------------------------------------------------- 2863 function site_url($atts) 2864 { 2865 return hu; 2866 } 2867 2868 // ------------------------------------------------------------- 2869 function img($atts) 2870 { 2871 extract(lAtts(array( 2872 'src' => '', 2873 ), $atts)); 2874 2875 $img = rtrim(hu, '/').'/'.ltrim($src, '/'); 2876 2877 $out = '<img src="'.$img.'" />'; 2878 2879 return $out; 2880 } 2881 2882 // ------------------------------------------------------------- 2883 function error_message($atts) 2884 { 2885 return @$GLOBALS['txp_error_message']; 2886 } 2887 2888 // ------------------------------------------------------------- 2889 function error_status($atts) 2890 { 2891 return @$GLOBALS['txp_error_status']; 2892 } 2893 2894 // ------------------------------------------------------------- 2895 function if_status($atts, $thing='') 2896 { 2897 global $pretext; 2898 2899 extract(lAtts(array( 2900 'status' => '200', 2901 ), $atts)); 2902 2903 $page_status = !empty($GLOBALS['txp_error_code']) 2904 ? $GLOBALS['txp_error_code'] 2905 : $pretext['status']; 2906 2907 return parse(EvalElse($thing, $status == $page_status)); 2908 } 2909 2910 // ------------------------------------------------------------- 2911 function page_url($atts) 2912 { 2913 global $pretext; 2914 2915 extract(lAtts(array( 2916 'type' => 'request_uri', 2917 ), $atts)); 2918 2919 return @htmlspecialchars($pretext[$type]); 2920 } 2921 2922 // ------------------------------------------------------------- 2923 function if_different($atts, $thing) 2924 { 2925 static $last; 2926 2927 $key = md5($thing); 2928 2929 $cond = EvalElse($thing, 1); 2930 2931 $out = parse($cond); 2932 if (empty($last[$key]) or $out != $last[$key]) { 2933 return $last[$key] = $out; 2934 } 2935 else 2936 return parse(EvalElse($thing, 0)); 2937 } 2938 2939 // ------------------------------------------------------------- 2940 function if_first_article($atts, $thing) 2941 { 2942 global $thisarticle; 2943 assert_article(); 2944 return parse(EvalElse($thing, !empty($thisarticle['is_first']))); 2945 } 2946 2947 // ------------------------------------------------------------- 2948 function if_last_article($atts, $thing) 2949 { 2950 global $thisarticle; 2951 assert_article(); 2952 return parse(EvalElse($thing, !empty($thisarticle['is_last']))); 2953 } 2954 2955 // ------------------------------------------------------------- 2956 function if_plugin($atts, $thing) 2957 { 2958 global $plugins, $plugins_ver; 2959 extract(lAtts(array( 2960 'name' => '', 2961 'ver' => '', 2962 ),$atts)); 2963 2964 return parse(EvalElse($thing, @in_array($name, $plugins) and (!$ver or version_compare($plugins_ver[$name], $ver) >= 0))); 2965 } 2966 2967 //-------------------------------------------------------------------------- 2968 2969 function file_download_list($atts) 2970 { 2971 global $thisfile; 2972 2973 extract(lAtts(array( 2974 'break' => br, 2975 'category' => '', 2976 'class' => __FUNCTION__, 2977 'form' => 'files', 2978 'label' => '', 2979 'labeltag' => '', 2980 'limit' => 10, 2981 'offset' => 0, 2982 'sort' => 'filename asc', 2983 'wraptag' => '', 2984 'status' => '4', 2985 ), $atts)); 2986 2987 if (!is_numeric($status)) 2988 $status = getStatusNum($status); 2989 2990 $where = array('1=1'); 2991 if ($category) $where[] = "category IN ('".join("','", doSlash(do_list($category)))."')"; 2992 if ($status) $where[] = "status = '".doSlash($status)."'"; 2993 2994 $qparts = array( 2995 'order by '.doSlash($sort), 2996 ($limit) ? 'limit '.intval($offset).', '.intval($limit) : '', 2997 ); 2998 2999 $rs = safe_rows_start('*', 'txp_file', join(' and ', $where).' '.join(' ', $qparts)); 3000 3001 if ($rs) 3002 { 3003 $out = array(); 3004 3005 while ($a = nextRow($rs)) 3006 { 3007 $thisfile = file_download_format_info($a); 3008 3009 $out[] = parse_form($form); 3010 3011 $thisfile = ''; 3012 } 3013 3014 if ($out) 3015 { 3016 if ($wraptag == 'ul' or $wraptag == 'ol') 3017 { 3018 return doLabel($label, $labeltag).doWrap($out, $wraptag, $break, $class); 3019 } 3020 3021 return ($wraptag) ? tag(join($break, $out), $wraptag) : join(n, $out); 3022 } 3023 } 3024 return ''; 3025 } 3026 3027 //-------------------------------------------------------------------------- 3028 3029 function file_download($atts) 3030 { 3031 global $thisfile; 3032 3033 extract(lAtts(array( 3034 'filename' => '', 3035 'form' => 'files', 3036 'id' => '', 3037 ), $atts)); 3038 3039 $from_form = false; 3040 3041 if ($id) 3042 { 3043 $thisfile = fileDownloadFetchInfo('id = '.intval($id)); 3044 } 3045 3046 elseif ($filename) 3047 { 3048 $thisfile = fileDownloadFetchInfo("filename = '".doSlash($filename)."'"); 3049 } 3050 3051 else 3052 { 3053 assert_file(); 3054 3055 $from_form = true; 3056 } 3057 3058 if ($thisfile) 3059 { 3060 $out = parse_form($form); 3061 3062 // cleanup: this wasn't called from a form, 3063 // so we don't want this value remaining 3064 if (!$from_form) 3065 { 3066 $thisfile = ''; 3067 } 3068 3069 return $out; 3070 } 3071 } 3072 3073 //-------------------------------------------------------------------------- 3074 3075 function file_download_link($atts, $thing) 3076 { 3077 global $thisfile, $permlink_mode; 3078 3079 extract(lAtts(array( 3080 'filename' => '', 3081 'id' => '', 3082 ), $atts)); 3083 3084 $from_form = false; 3085 3086 if ($id) 3087 { 3088 $thisfile = fileDownloadFetchInfo('id = '.intval($id)); 3089 } 3090 3091 elseif ($filename) 3092 { 3093 $thisfile = fileDownloadFetchInfo("filename = '".doSlash($filename)."'"); 3094 } 3095 3096 else 3097 { 3098 assert_file(); 3099 3100 $from_form = true; 3101 } 3102 3103 if ($thisfile) 3104 { 3105 $url = filedownloadurl($thisfile['id'], $thisfile['filename']); 3106 3107 $out = ($thing) ? href(parse($thing), $url) : $url; 3108 3109 // cleanup: this wasn't called from a form, 3110 // so we don't want this value remaining 3111 if (!$from_form) 3112 { 3113 $thisfile = ''; 3114 } 3115 3116 return $out; 3117 } 3118 } 3119 3120 //-------------------------------------------------------------------------- 3121 3122 function fileDownloadFetchInfo($where) 3123 { 3124 $rs = safe_row('*', 'txp_file', $where); 3125 3126 if ($rs) 3127 { 3128 return file_download_format_info($rs); 3129 } 3130 3131 return false; 3132 } 3133 3134 //-------------------------------------------------------------------------- 3135 3136 function file_download_format_info($file) 3137 { 3138 if (($unix_ts = @strtotime($file['created'])) > 0) 3139 $file['created'] = $unix_ts; 3140 if (($unix_ts = @strtotime($file['modified'])) > 0) 3141 $file['modified'] = $unix_ts; 3142 3143 return $file; 3144 } 3145 3146 //-------------------------------------------------------------------------- 3147 3148 function file_download_size($atts) 3149 { 3150 global $thisfile; 3151 assert_file(); 3152 3153 extract(lAtts(array( 3154 'decimals' => 2, 3155 'format' => '', 3156 ), $atts)); 3157 3158 if (is_numeric($decimals) and $decimals >= 0) 3159 { 3160 $decimals = intval($decimals); 3161 } 3162 3163 else 3164 { 3165 $decimals = 2; 3166 } 3167 3168 if (@$thisfile['size']) 3169 { 3170 $size = $thisfile['size']; 3171 3172 if (!in_array($format, array('B','KB','MB','GB','PB'))) 3173 { 3174 $divs = 0; 3175 3176 while ($size >= 1024) 3177 { 3178 $size /= 1024; 3179 $divs++; 3180 } 3181 3182 switch ($divs) 3183 { 3184 case 1: 3185 $format = 'KB'; 3186 break; 3187 3188 case 2: 3189 $format = 'MB'; 3190 break; 3191 3192 case 3: 3193 $format = 'GB'; 3194 break; 3195 3196 case 4: 3197 $format = 'PB'; 3198 break; 3199 3200 case 0: 3201 default: 3202 $format = 'B'; 3203 break; 3204 } 3205 } 3206 3207 $size = $thisfile['size']; 3208 3209 switch ($format) 3210 { 3211 case 'KB': 3212 $size /= 1024; 3213 break; 3214 3215 case 'MB': 3216 $size /= (1024*1024); 3217 break; 3218 3219 case 'GB': 3220 $size /= (1024*1024*1024); 3221 break; 3222 3223 case 'PB': 3224 $size /= (1024*1024*1024*1024); 3225 break; 3226 3227 case 'B': 3228 default: 3229 // do nothing 3230 break; 3231 } 3232 3233 return number_format($size, $decimals).$format; 3234 } 3235 3236 else 3237 { 3238 return ''; 3239 } 3240 } 3241 3242 //-------------------------------------------------------------------------- 3243 3244 function file_download_created($atts) 3245 { 3246 global $thisfile; 3247 assert_file(); 3248 3249 extract(lAtts(array( 3250 'format' => '', 3251 ), $atts)); 3252 3253 if ($thisfile['created']) { 3254 return fileDownloadFormatTime(array( 3255 'ftime' => $thisfile['created'], 3256 'format' => $format 3257 )); 3258 } 3259 } 3260 3261 //-------------------------------------------------------------------------- 3262 3263 function file_download_modified($atts) 3264 { 3265 global $thisfile; 3266 assert_file(); 3267 3268 extract(lAtts(array( 3269 'format' => '', 3270 ), $atts)); 3271 3272 if ($thisfile['modified']) { 3273 return fileDownloadFormatTime(array( 3274 'ftime' => $thisfile['modified'], 3275 'format' => $format 3276 )); 3277 } 3278 } 3279 3280 //------------------------------------------------------------------------- 3281 // All the time related file_download tags in one 3282 // One Rule to rule them all... now using safe formats 3283 3284 function fileDownloadFormatTime($params) 3285 { 3286 global $prefs; 3287 3288 extract($params); 3289 3290 if (!empty($ftime)) 3291 { 3292 return !empty($format) ? 3293 safe_strftime($format, $ftime) : safe_strftime($prefs['archive_dateformat'], $ftime); 3294 } 3295 return ''; 3296 } 3297 3298 //-------------------------------------------------------------------------- 3299 3300 function file_download_id($atts) 3301 { 3302 global $thisfile; 3303 assert_file(); 3304 return $thisfile['id']; 3305 } 3306 3307 //-------------------------------------------------------------------------- 3308 3309 function file_download_name($atts) 3310 { 3311 global $thisfile; 3312 assert_file(); 3313 return $thisfile['filename']; 3314 } 3315 3316 //-------------------------------------------------------------------------- 3317 3318 function file_download_category($atts) 3319 { 3320 global $thisfile; 3321 assert_file(); 3322 3323 extract(lAtts(array( 3324 'class' => '', 3325 'title' => 0, 3326 'wraptag' => '', 3327 ), $atts)); 3328 3329 if ($thisfile['category']) 3330 { 3331 $category = ($title) ? 3332 fetch_category_title($thisfile['category'], 'file') : 3333 $thisfile['category']; 3334 3335 return ($wraptag) ? doTag($category, $wraptag, $class) : $category; 3336 } 3337 } 3338 3339 //-------------------------------------------------------------------------- 3340 3341 function file_download_downloads($atts) 3342 { 3343 global $thisfile; 3344 assert_file(); 3345 return $thisfile['downloads']; 3346 } 3347 3348 //-------------------------------------------------------------------------- 3349 3350 function file_download_description($atts) 3351 { 3352 global $thisfile; 3353 assert_file(); 3354 3355 extract(lAtts(array( 3356 'class' => '', 3357 'escape' => '', 3358 'wraptag' => '', 3359 ), $atts)); 3360 3361 if ($thisfile['description']) 3362 { 3363 $description = ($escape == 'html') ? 3364 htmlspecialchars($thisfile['description']) : $thisfile['description']; 3365 3366 return ($wraptag) ? doTag($description, $wraptag, $class) : $description; 3367 } 3368 } 3369 3370 // ------------------------------------------------------------- 3371 function hide($atts, $thing) 3372 { 3373 return ''; 3374 } 3375 3376 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Feb 18 03:42:45 2008 | Cross-referenced by PHPXref 0.7 |