Warning: Undefined variable $mode in /var/www/virtual/qbnz.com/htdocs/highlighter/examples/php/phpbb-index.php on line 6
GeSHi - Generic Syntax Highlighter :: Examples
 
Navigation
Home News Examples Demo Downloads FAQ Documentation Mailing Lists License
Support GeSHi!
If you're using GeSHi, why not help GeSHi out? You can link to GeSHi with this image:
Powered by GeSHi
Get the HTML

Project Status
The latest stable version of GeSHi is 1.0.8.11, released on the 19th of Aug, 2012.

Supported Languages:
*ABAP
*Actionscript
*ADA
*Apache Log
*AppleScript
*APT sources.list
*ASM (m68k)
*ASM (pic16)
*ASM (x86)
*ASM (z80)
*ASP
*AutoIT
*Backus-Naur form
*Bash
*Basic4GL
*BlitzBasic
*Brainfuck
*C
*C for Macs
*C#
*C++
*C++ (with QT)
*CAD DCL
*CadLisp
*CFDG
*CIL / MSIL
*COBOL
*ColdFusion
*CSS
*D
*Delphi
*Diff File Format
*DIV
*DOS
*DOT language
*Eiffel
*Fortran
*FourJ's Genero
*FreeBasic
*GetText
*glSlang
*GML
*gnuplot
*Groovy
*Haskell
*HQ9+
*HTML
*INI (Config Files)
*Inno
*INTERCAL
*IO
*Java
*Java 5
*Javascript
*KiXtart
*KLone C & C++
*LaTeX
*Lisp
*LOLcode
*LotusScript
*LScript
*Lua
*Make
*mIRC
*MXML
*MySQL
*NSIS
*Objective C
*OCaml
*OpenOffice BASIC
*Oracle 8 & 11 SQL
*Pascal
*Perl
*PHP
*Pixel Bender
*PL/SQL
*POV-Ray
*PowerShell
*Progress (OpenEdge ABL)
*Prolog
*ProvideX
*Python
*Q(uick)BASIC
*robots.txt
*Ruby
*Ruby on Rails
*SAS
*Scala
*Scheme
*Scilab
*SDLBasic
*Smalltalk
*Smarty
*SQL
*T-SQL
*TCL
*thinBasic
*TypoScript
*Uno IDL
*VB.NET
*Verilog
*VHDL
*VIM Script
*Visual BASIC
*Visual Fox Pro
*Visual Prolog
*Whitespace
*Winbatch
*Windows Registry Files
*X++
*XML
*Xorg.conf

GeSHi 1.0.8.11 is the current stable release, with eighteen new languages and bug fixes over the last release.

GeSHi 1.1.2alpha5 is the current latest version from the development branch, with full C support (see the GeSHi development website).
Subscribe
RSS 2
Mailing Lists
HomeNewsExamplesDemoDownloadsFAQDocumentationMailing ListsLicense 
6:37 pm GMT

Examples

Examples » PHP
  1. <?php
  2. /***************************************************************************
  3.  *                                index.php
  4.  *                            -------------------
  5.  *   begin                : Saturday, Feb 13, 2001
  6.  *   copyright            : (C) 2001 The phpBB Group
  7.  *   email                : support@phpbb.com
  8.  *
  9.  *   $Id: index.php,v 1.99.2.1 2002/12/19 17:17:40 psotfx Exp $
  10.  *
  11.  *
  12.  ***************************************************************************/
  13.  
  14. /***************************************************************************
  15.  *
  16.  *   This program is free software; you can redistribute it and/or modify
  17.  *   it under the terms of the GNU General Public License as published by
  18.  *   the Free Software Foundation; either version 2 of the License, or
  19.  *   (at your option) any later version.
  20.  *
  21.  ***************************************************************************/
  22.  
  23. define('IN_PHPBB', true);
  24. $phpbb_root_path = './';
  25. include($phpbb_root_path . 'extension.inc');
  26. include($phpbb_root_path . 'common.'.$phpEx);
  27.  
  28. //
  29. // Start session management
  30. //
  31. $userdata = session_pagestart($user_ip, PAGE_INDEX);
  32. init_userprefs($userdata);
  33. //
  34. // End session management
  35. //
  36.  
  37. $viewcat = ( !empty($HTTP_GET_VARS[POST_CAT_URL]) ) ? $HTTP_GET_VARS[POST_CAT_URL] : -1;
  38.  
  39. if( isset($HTTP_GET_VARS['mark']) || isset($HTTP_POST_VARS['mark']) )
  40. {
  41.   $mark_read = ( isset($HTTP_POST_VARS['mark']) ) ? $HTTP_POST_VARS['mark'] : $HTTP_GET_VARS['mark'];
  42. }
  43. else
  44. {
  45.   $mark_read = '';
  46. }
  47.  
  48. //
  49. // Handle marking posts
  50. //
  51. if( $mark_read == 'forums' )
  52. {
  53.   if( $userdata['session_logged_in'] )
  54.   {
  55.     setcookie($board_config['cookie_name'] . '_f_all', time(), 0, $board_config['cookie_path'], $board_config['cookie_domain'], $board_config['cookie_secure']);
  56.   }
  57.  
  58.   $template->assign_vars(array(
  59.     "META" => '<meta http-equiv="refresh" content="3;url='  .append_sid("index.$phpEx") . '">')
  60.   );
  61.  
  62.   $message = $lang['Forums_marked_read'] . '<br /><br />' . sprintf($lang['Click_return_index'], '<a href="' . append_sid("index.$phpEx") . '">', '</a> ');
  63.  
  64.   message_die(GENERAL_MESSAGE, $message);
  65. }
  66. //
  67. // End handle marking posts
  68. //
  69.  
  70. $tracking_topics = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . "_t"]) : array();
  71. $tracking_forums = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . "_f"]) : array();
  72.  
  73. //
  74. // If you don't use these stats on your index you may want to consider
  75. // removing them
  76. //
  77. $total_posts = get_db_stat('postcount');
  78. $total_users = get_db_stat('usercount');
  79. $newest_userdata = get_db_stat('newestuser');
  80. $newest_user = $newest_userdata['username'];
  81. $newest_uid = $newest_userdata['user_id'];
  82.  
  83. if( $total_posts == 0 )
  84. {
  85.   $l_total_post_s = $lang['Posted_articles_zero_total'];
  86. }
  87. else if( $total_posts == 1 )
  88. {
  89.   $l_total_post_s = $lang['Posted_article_total'];
  90. }
  91. else
  92. {
  93.   $l_total_post_s = $lang['Posted_articles_total'];
  94. }
  95.  
  96. if( $total_users == 0 )
  97. {
  98.   $l_total_user_s = $lang['Registered_users_zero_total'];
  99. }
  100. else if( $total_users == 1 )
  101. {
  102.   $l_total_user_s = $lang['Registered_user_total'];
  103. }
  104. else
  105. {
  106.   $l_total_user_s = $lang['Registered_users_total'];
  107. }
  108.  
  109.  
  110. //
  111. // Start page proper
  112. //
  113. $sql = "SELECT c.cat_id, c.cat_title, c.cat_order
  114.   FROM " . CATEGORIES_TABLE . " c
  115.   ORDER BY c.cat_order";
  116. if( !($result = $db->sql_query($sql)) )
  117. {
  118.   message_die(GENERAL_ERROR, 'Could not query categories list', '', __LINE__, __FILE__, $sql);
  119. }
  120.  
  121. while( $category_rows[] = $db->sql_fetchrow($result) );
  122.  
  123. if( ( $total_categories = count($category_rows) ) )
  124. {
  125.   //
  126.   // Define appropriate SQL
  127.   //
  128.   switch(SQL_LAYER)
  129.   {
  130.     case 'postgresql':
  131.       $sql = "SELECT f.*, p.post_time, p.post_username, u.username, u.user_id
  132.         FROM " . FORUMS_TABLE . " f, " . POSTS_TABLE . " p, " . USERS_TABLE . " u
  133.         WHERE p.post_id = f.forum_last_post_id
  134.           AND u.user_id = p.poster_id  
  135.           UNION (
  136.             SELECT f.*, NULL, NULL, NULL, NULL
  137.             FROM " . FORUMS_TABLE . " f
  138.             WHERE NOT EXISTS (
  139.               SELECT p.post_time
  140.               FROM " . POSTS_TABLE . " p
  141.               WHERE p.post_id = f.forum_last_post_id  
  142.             )
  143.           )
  144.           ORDER BY cat_id, forum_order";
  145.       break;
  146.  
  147.     case 'oracle':
  148.       $sql = "SELECT f.*, p.post_time, p.post_username, u.username, u.user_id
  149.         FROM " . FORUMS_TABLE . " f, " . POSTS_TABLE . " p, " . USERS_TABLE . " u
  150.         WHERE p.post_id = f.forum_last_post_id(+)
  151.           AND u.user_id = p.poster_id(+)
  152.         ORDER BY f.cat_id, f.forum_order";
  153.       break;
  154.  
  155.     default:
  156.       $sql = "SELECT f.*, p.post_time, p.post_username, u.username, u.user_id
  157.         FROM (( " . FORUMS_TABLE . " f
  158.         LEFT JOIN " . POSTS_TABLE . " p ON p.post_id = f.forum_last_post_id )
  159.         LEFT JOIN " . USERS_TABLE . " u ON u.user_id = p.poster_id )
  160.         ORDER BY f.cat_id, f.forum_order";
  161.       break;
  162.   }
  163.   if ( !($result = $db->sql_query($sql)) )
  164.   {
  165.     message_die(GENERAL_ERROR, 'Could not query forums information', '', __LINE__, __FILE__, $sql);
  166.   }
  167.  
  168.   $forum_data = array();
  169.   while( $row = $db->sql_fetchrow($result) )
  170.   {
  171.     $forum_data[] = $row;
  172.   }
  173.  
  174.   if ( !($total_forums = count($forum_data)) )
  175.   {
  176.     message_die(GENERAL_MESSAGE, $lang['No_forums']);
  177.   }
  178.  
  179.   //
  180.   // Obtain a list of topic ids which contain
  181.   // posts made since user last visited
  182.   //
  183.   if ( $userdata['session_logged_in'] )
  184.   {
  185.     $sql = "SELECT t.forum_id, t.topic_id, p.post_time
  186.       FROM " . TOPICS_TABLE . " t, " . POSTS_TABLE . " p
  187.       WHERE p.post_id = t.topic_last_post_id
  188.         AND p.post_time > " . $userdata['user_lastvisit'] . "
  189.         AND t.topic_moved_id = 0";
  190.     if ( !($result = $db->sql_query($sql)) )
  191.     {
  192.       message_die(GENERAL_ERROR, 'Could not query new topic information', '', __LINE__, __FILE__, $sql);
  193.     }
  194.  
  195.     $new_topic_data = array();
  196.     while( $topic_data = $db->sql_fetchrow($result) )
  197.     {
  198.       $new_topic_data[$topic_data['forum_id']][$topic_data['topic_id']] = $topic_data['post_time'];
  199.     }
  200.   }
  201.  
  202.   //
  203.   // Obtain list of moderators of each forum
  204.   // First users, then groups ... broken into two queries
  205.   //
  206.   $sql = "SELECT aa.forum_id, u.user_id, u.username
  207.     FROM " . AUTH_ACCESS_TABLE . " aa, " . USER_GROUP_TABLE . " ug, " . GROUPS_TABLE . " g, " . USERS_TABLE . " u
  208.     WHERE aa.auth_mod = " . TRUE . "
  209.       AND g.group_single_user = 1
  210.       AND ug.group_id = aa.group_id
  211.       AND g.group_id = aa.group_id
  212.       AND u.user_id = ug.user_id
  213.     GROUP BY u.user_id, u.username, aa.forum_id
  214.     ORDER BY aa.forum_id, u.user_id";
  215.   if ( !($result = $db->sql_query($sql)) )
  216.   {
  217.     message_die(GENERAL_ERROR, 'Could not query forum moderator information', '', __LINE__, __FILE__, $sql);
  218.   }
  219.  
  220.   $forum_moderators = array();
  221.   while( $row = $db->sql_fetchrow($result) )
  222.   {
  223.     $forum_moderators[$row['forum_id']][] = '<a href="' . append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . "=" . $row['user_id']) . '">' . $row['username'] . '</a>';
  224.   }
  225.  
  226.   $sql = "SELECT aa.forum_id, g.group_id, g.group_name
  227.     FROM " . AUTH_ACCESS_TABLE . " aa, " . USER_GROUP_TABLE . " ug, " . GROUPS_TABLE . " g
  228.     WHERE aa.auth_mod = " . TRUE . "
  229.       AND g.group_single_user = 0
  230.       AND g.group_type <> " . GROUP_HIDDEN . "
  231.       AND ug.group_id = aa.group_id
  232.       AND g.group_id = aa.group_id
  233.     GROUP BY g.group_id, g.group_name, aa.forum_id
  234.     ORDER BY aa.forum_id, g.group_id";
  235.   if ( !($result = $db->sql_query($sql)) )
  236.   {
  237.     message_die(GENERAL_ERROR, 'Could not query forum moderator information', '', __LINE__, __FILE__, $sql);
  238.   }
  239.  
  240.   while( $row = $db->sql_fetchrow($result) )
  241.   {
  242.     $forum_moderators[$row['forum_id']][] = '<a href="' . append_sid("groupcp.$phpEx?" . POST_GROUPS_URL . "=" . $row['group_id']) . '">' . $row['group_name'] . '</a>';
  243.   }
  244.  
  245.   //
  246.   // Find which forums are visible for this user
  247.   //
  248.   $is_auth_ary = array();
  249.   $is_auth_ary = auth(AUTH_VIEW, AUTH_LIST_ALL, $userdata, $forum_data);
  250.  
  251.   //
  252.   // Start output of page
  253.   //
  254.   define('SHOW_ONLINE', true);
  255.   $page_title = $lang['Index'];
  256.   include($phpbb_root_path . 'includes/page_header.'.$phpEx);
  257.  
  258.   $template->set_filenames(array(
  259.     'body' => 'index_body.tpl')
  260.   );
  261.  
  262.   $template->assign_vars(array(
  263.     'TOTAL_POSTS' => sprintf($l_total_post_s, $total_posts),
  264.     'TOTAL_USERS' => sprintf($l_total_user_s, $total_users),
  265.     'NEWEST_USER' => sprintf($lang['Newest_user'], '<a href="' . append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . "=$newest_uid") . '">', $newest_user, '</a>'),
  266.  
  267.     'FORUM_IMG' => $images['forum'],
  268.     'FORUM_NEW_IMG' => $images['forum_new'],
  269.     'FORUM_LOCKED_IMG' => $images['forum_locked'],
  270.  
  271.     'L_FORUM' => $lang['Forum'],
  272.     'L_TOPICS' => $lang['Topics'],
  273.     'L_REPLIES' => $lang['Replies'],
  274.     'L_VIEWS' => $lang['Views'],
  275.     'L_POSTS' => $lang['Posts'],
  276.     'L_LASTPOST' => $lang['Last_Post'],
  277.     'L_NO_NEW_POSTS' => $lang['No_new_posts'],
  278.     'L_NEW_POSTS' => $lang['New_posts'],
  279.     'L_NO_NEW_POSTS_LOCKED' => $lang['No_new_posts_locked'],
  280.     'L_NEW_POSTS_LOCKED' => $lang['New_posts_locked'],
  281.     'L_ONLINE_EXPLAIN' => $lang['Online_explain'],
  282.  
  283.     'L_MODERATOR' => $lang['Moderators'],
  284.     'L_FORUM_LOCKED' => $lang['Forum_is_locked'],
  285.     'L_MARK_FORUMS_READ' => $lang['Mark_all_forums'],
  286.  
  287.     'U_MARK_READ' => append_sid("index.$phpEx?mark=forums"))
  288.   );
  289.  
  290.   //
  291.   // Okay, let's build the index
  292.   //
  293.   for($i = 0; $i < $total_categories; $i++)
  294.   {
  295.     $cat_id = $category_rows[$i]['cat_id'];
  296.  
  297.     //
  298.     // Should we display this category/forum set?
  299.     //
  300.     $display_forums = false;
  301.     for($j = 0; $j < $total_forums; $j++)
  302.     {
  303.       if ( $is_auth_ary[$forum_data[$j]['forum_id']]['auth_view'] && $forum_data[$j]['cat_id'] == $cat_id )
  304.       {
  305.         $display_forums = true;
  306.       }
  307.     }
  308.  
  309.     //
  310.     // Yes, we should, so first dump out the category
  311.     // title, then, if appropriate the forum list
  312.     //
  313.     if ( $display_forums )
  314.     {
  315.       $template->assign_block_vars('catrow', array(
  316.         'CAT_ID' => $cat_id,
  317.         'CAT_DESC' => $category_rows[$i]['cat_title'],
  318.         'U_VIEWCAT' => append_sid("index.$phpEx?" . POST_CAT_URL . "=$cat_id"))
  319.       );
  320.  
  321.       if ( $viewcat == $cat_id || $viewcat == -1 )
  322.       {
  323.         for($j = 0; $j < $total_forums; $j++)
  324.         {
  325.           if ( $forum_data[$j]['cat_id'] == $cat_id )
  326.           {
  327.             $forum_id = $forum_data[$j]['forum_id'];
  328.  
  329.             if ( $is_auth_ary[$forum_id]['auth_view'] )
  330.             {
  331.               if ( $forum_data[$j]['forum_status'] == FORUM_LOCKED )
  332.               {
  333.                 $folder_image = $images['forum_locked'];
  334.                 $folder_alt = $lang['Forum_locked'];
  335.               }
  336.               else
  337.               {
  338.                 $unread_topics = false;
  339.                 if ( $userdata['session_logged_in'] )
  340.                 {
  341.                   if ( !empty($new_topic_data[$forum_id]) )
  342.                   {
  343.                     $forum_last_post_time = 0;
  344.  
  345.                     while( list($check_topic_id, $check_post_time) = @each($new_topic_data[$forum_id]) )
  346.                     {
  347.                       if ( empty($tracking_topics[$check_topic_id]) )
  348.                       {
  349.                         $unread_topics = true;
  350.                         $forum_last_post_time = max($check_post_time, $forum_last_post_time);
  351.  
  352.                       }
  353.                       else
  354.                       {
  355.                         if ( $tracking_topics[$check_topic_id] < $check_post_time )
  356.                         {
  357.                           $unread_topics = true;
  358.                           $forum_last_post_time = max($check_post_time, $forum_last_post_time);
  359.                         }
  360.                       }
  361.                     }
  362.  
  363.                     if ( !empty($tracking_forums[$forum_id]) )
  364.                     {
  365.                       if ( $tracking_forums[$forum_id] > $forum_last_post_time )
  366.                       {
  367.                         $unread_topics = false;
  368.                       }
  369.                     }
  370.  
  371.                     if ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f_all']) )
  372.                     {
  373.                       if ( $HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f_all'] > $forum_last_post_time )
  374.                       {
  375.                         $unread_topics = false;
  376.                       }
  377.                     }
  378.  
  379.                   }
  380.                 }
  381.  
  382.                 $folder_image = ( $unread_topics ) ? $images['forum_new'] : $images['forum'];
  383.                 $folder_alt = ( $unread_topics ) ? $lang['New_posts'] : $lang['No_new_posts'];
  384.               }
  385.  
  386.               $posts = $forum_data[$j]['forum_posts'];
  387.               $topics = $forum_data[$j]['forum_topics'];
  388.  
  389.               if ( $forum_data[$j]['forum_last_post_id'] )
  390.               {
  391.                 $last_post_time = create_date($board_config['default_dateformat'], $forum_data[$j]['post_time'], $board_config['board_timezone']);
  392.  
  393.                 $last_post = $last_post_time . '<br />';
  394.  
  395.                 $last_post .= ( $forum_data[$j]['user_id'] == ANONYMOUS ) ? ( ($forum_data[$j]['post_username'] != '' ) ? $forum_data[$j]['post_username'] . ' ' : $lang['Guest'] . ' ' ) : '<a href="' . append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . '='  . $forum_data[$j]['user_id']) . '">' . $forum_data[$j]['username'] . '</a> ';
  396.                
  397.                 $last_post .= '<a href="' . append_sid("viewtopic.$phpEx?"  . POST_POST_URL . '=' . $forum_data[$j]['forum_last_post_id']) . '#' . $forum_data[$j]['forum_last_post_id'] . '"><img src="' . $images['icon_latest_reply'] . '" border="0" alt="' . $lang['View_latest_post'] . '" title="' . $lang['View_latest_post'] . '" /></a>';
  398.               }
  399.               else
  400.               {
  401.                 $last_post = $lang['No_Posts'];
  402.               }
  403.  
  404.               if ( count($forum_moderators[$forum_id]) > 0 )
  405.               {
  406.                 $l_moderators = ( count($forum_moderators[$forum_id]) == 1 ) ? $lang['Moderator'] : $lang['Moderators'];
  407.                 $moderator_list = implode(', ', $forum_moderators[$forum_id]);
  408.               }
  409.               else
  410.               {
  411.                 $l_moderators = '&nbsp;';
  412.                 $moderator_list = '&nbsp;';
  413.               }
  414.  
  415.               $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
  416.               $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
  417.  
  418.               $template->assign_block_vars('catrow.forumrow', array(
  419.                 'ROW_COLOR' => '#' . $row_color,
  420.                 'ROW_CLASS' => $row_class,
  421.                 'FORUM_FOLDER_IMG' => $folder_image,
  422.                 'FORUM_NAME' => $forum_data[$j]['forum_name'],
  423.                 'FORUM_DESC' => $forum_data[$j]['forum_desc'],
  424.                 'POSTS' => $forum_data[$j]['forum_posts'],
  425.                 'TOPICS' => $forum_data[$j]['forum_topics'],
  426.                 'LAST_POST' => $last_post,
  427.                 'MODERATORS' => $moderator_list,
  428.  
  429.                 'L_MODERATOR' => $l_moderators,
  430.                 'L_FORUM_FOLDER_ALT' => $folder_alt,
  431.  
  432.                 'U_VIEWFORUM' => append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id"))
  433.               );
  434.             }
  435.           }
  436.         }
  437.       }
  438.     }
  439.   } // for ... categories
  440.  
  441. }// if ... total_categories
  442. else
  443. {
  444.   message_die(GENERAL_MESSAGE, $lang['No_forums']);
  445. }
  446.  
  447. //
  448. // Generate the page
  449. //
  450. $template->pparse('body');
  451.  
  452. include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
  453.  
  454. ?>

This category contains 2 examples, and has been viewed 204701 times.

  • Index of phpBB - The source to the index page of phpBB (64177 views)
  • Coffee!! - A simple PHP example (33480 views)