Code Search for Developers
 
 
  

common.php from Gtk-Gnutella at Krugle


Show common.php syntax highlighted

<?php
/*
 * $Id: common.php 12581 2006-12-06 03:51:14Z cbiere $
 */

/*
 *
 * general configuration variables are in here
 *
 */
 
/* Uncomment this for debugging */
/* error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE); */

if (!defined(BASEDIR)) {
  define(BASEDIR, "/home/groups/g/gt/gtk-gnutella/htdocs/files/");
}

$news_items = null;

$pages = array(
  "banners",
  "bugreport_howto",
  "code101",
  "code101a",
  "current_version",
  "devel",
  "developers_howto",
  "docs",
  "donate",
  "faq",
  "features",
  "filtering_howto",
  "links",
  "mailing",
  "news_bridge",
  "news_header",
  "news_old",
  "news_old_header",
  "release_history",
  "searching_by_hash",
  "shots",
  "shots085",
  "shots090",
  "shots092",
  "shots096u"
);

/* NEWSNUM is the number of news items that appear on the front page. */
define("NEWSNUM", 7);
define("GENDIR",  "general/");
define("PAGE",    getpage());
define("LANG",    getlang());
define("BASEURL", $_SERVER['PHP_SELF']);

include(BASEDIR . "VERSION");

header("Content-Type: text/html; charset=utf-8");
/*
 * XXX: Please, explain why russian users should be given koi8-r instead
 *      of utf-8 as encoding. Disabled for now. --cbiere, 2005-07-01
 */
/*** hack ** fscking damn php won't use LANG in header() ** hack **
$ru = $CHARSET["ru"] = 'koi8-r';
if (isset($CHARSET[LANG]))
  header("Content-Type: text/html; charset=$ru");
*/

function getpage() {
  global $pages; /* so the included files know about it */

  $page = $_GET['page'];
  if (ereg('^[a-zA-Z0-9_]*$', $page) && in_array($page, $pages))
    return $page;
  else
    return 'news';
}

/* getdirlang sub - check the script path for a language hint */
function getdirlang() {
  $script = $_SERVER['PHP_SELF'];

  if (isset($script) && ereg('^/[a-z][a-z]/', $script)) {
    $lang = substr($script, 1, 2);
    if (file_exists(BASEDIR . '/../' . $lang . '/index.php'))
      return $lang;
  }

  /* Return "en" (English) by default just like getlang() */
  return null;
}

/* getlang sub - check which language the visitor wants */
function getlang() {
  $cooklang = $_COOKIE['cooklang'];
  $accept = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
  $lang = $_GET['lang'];
  $dirlang = getdirlang();

  if (!isset ($lang)) {
    /* no language selection in http request */

    
    if (isset($dirlang)) {
      /* Language taken from path e.g., /fr/index.php -> fr */
      $lang = $dirlang;
    } else if (isset($cooklang)) {
      /* Language taken from cookie */
      $lang = $cooklang;
    } else {
      /* not even a cookie. Choose from http_accept_language */
      while (
        empty($lang) &&
        ereg('([a-z][a-z](-[A-Z][A-Z])?)', $accept, $res)
      ) {
        $lang = $res[1];
        $accept = ereg_replace("$lang", '', $accept);
      }
    }
  }

  if (!isset($lang) || !file_exists(BASEDIR . '/../' . $lang . '/index.php')) {
    /* Use English as default */
    $lang = 'en';
  }

  /* Set the cookie only for the default path / but not e.g., /fr/ */
  if (!isset($dirlang))
    setcookie('cooklang', $lang, time() + 31536000);

  return $lang;
}

/*
 * icecontent:
 *
 * include the content files including pre and post files
 */
function icecontent($content) {
  iceinclude($content, 1);
}

/*
 * iceinclude:
 *
 * checks whether a file is available in the desired language
 */
function iceinclude($file, $box) {
  global $news_items; /* so the included files know about it */
  $incfile = BASEDIR . LANG . "/$file";
  if (!file_exists($incfile)) {
    $incfile = BASEDIR . "en/$file";
    if (file_exists($incfile)) {
      if ($box) {
        include(BASEDIR . GENDIR . "/cheader");
      }
      include("$incfile");
      if ($box) {
        include(BASEDIR . GENDIR . "/cfooter");
      }
    }
  } else {
    if ($box) {
      include(BASEDIR . GENDIR . "/cheader");
    }
    include("$incfile");
    if ($box) {
      include(BASEDIR . GENDIR . "/cfooter");
    }
  }
}

/*
 * maincontent:
 *
 * include the content
 */
function maincontent() {
  global $pages; /* so the included files know about it */
  
  if (
    in_array(PAGE, $pages) && (
      file_exists(BASEDIR . LANG . '/' . PAGE) ||
      file_exists(BASEDIR . 'en/' . PAGE)
    )
  ) {
    icecontent(PAGE);
  } else {
    iceinclude("news", 0);
  }
}

/*
 * sf_bug:
 *
 * create a link for gtk-gnutella bug with given number.
 */
 function sf_bug($number) {
   print("<a href=\"http://sourceforge.net/tracker/index.php?func=detail&amp;aid=$number&amp;group_id=4467&amp;atid=104467\">#$number</a>");
 }
 
/*
 * newsfiles:
 *
 * Fill the array $news_items with the news_nn filenames,
 * sort them in natural order, and then reverse the order.
 * Then we can suck out however many we want.
 */
function newsfiles() {
	global $news_items;

	$news_items = array();
	$handle = opendir(BASEDIR . "en");
	while (false !== ($file = readdir($handle))) {
		if (ereg('^news_([0-9]{1,3})$', $file)) {
			$news_items[] = $file;
		}
	}
	closedir($handle);
	usort($news_items, "strnatcmp");
	$news_items = array_reverse($news_items);
/*
	for ($i = 0; $i < count($news_items); $i++) {
		echo '<!-- ' . $news_items[$i] . ' -->';
	}
 */
}





See more files for this project here

Gtk-Gnutella

A GTK+ Gnutella client for Unix, efficient, reliable and fast, written in C. It has been optimized for speed and scalability, with low-memory consumption. It is meant to be left running 24x7, using little CPU and only the configured bandwidth.

Project homepage: http://sourceforge.net/projects/gtk-gnutella
Programming language(s): C
License: other

  de/
    current_version
    donate
    faq
    features
    intro
    links
    mailing
    news_44
    news_45
    news_46
    news_47
    news_48
    news_49
    news_bridge
    news_header
    news_old_header
    searching_by_hash
    sections
    shots085
    shots090
    shots092
    sidenav
    sidenav_conform
    sidenav_copyright
    sidenav_glade
    sidenav_hosted
    special_news
    title
  el/
    bugreport_howto
    code101
    code101a
    current_version
    docs
    donate
    faq
    features
    intro
    links
    mailing
    news_43
    news_44
    news_45
    news_bridge
    news_header
    news_old_header
    searching_by_hash
    shots085
    shots090
    shots096u
    sidenav
    sidenav_conform
    sidenav_copyright
    sidenav_glade
    sidenav_hosted
    special_news
    title
  en/
    banners
    bugreport_howto
    code101
    code101a
    content.template
    current_version
    devel
    developers_howto
    docs
    donate
    faq
    features
    filtering_howto
    footer
    intro
    links
    mailing
    news
    news_0
    news_1
    news_10
    news_11
    news_12
    news_13
    news_14
    news_15
    news_16
    news_17
    news_18
    news_19
    news_2
    news_20
    news_21
    news_22
    news_23
    news_24
    news_25
    news_26
    news_27
    news_28
    news_29
    news_3
    news_30
    news_31
    news_32
    news_33
    news_34
    news_35
    news_36
    news_37
    news_38
    news_39
    news_4
    news_40
    news_41
    news_42
    news_43
    news_44
    news_45
    news_46
    news_47
    news_48
    news_49
    news_5
    news_50
    news_51
    news_52
    news_53
    news_6
    news_7
    news_8
    news_9
    news_bridge
    news_header
    news_old
    news_old_header
    news_template
    release_history
    searching_by_hash
    sections
    shots085
    shots090
    shots092
    shots096u
    sidenav
    sidenav_conform
    sidenav_copyright
    sidenav_glade
    sidenav_hosted
    special_news
    title
  fr/
    current_version
    docs
    donate
    features
    intro
    links
    mailing
    news_45
    news_46
    news_49
    news_bridge
    news_header
    news_old_header
    searching_by_hash
    sections
    shots085
    shots090
    shots092
    shots096u
    sidenav
    sidenav_conform
    sidenav_copyright
    sidenav_glade
    sidenav_hosted
    special_news
    title
  general/
    cfooter
    cheader
  ja/
    banners
    bugreport_howto
    code101
    code101a
    current_version
    devel
    developers_howto
    docs
    donate
    faq
    features
    filtering_howto
    intro
    links
    mailing
    news_0
    news_1
    news_10
    news_11
    news_12
    news_13
    news_14
    news_15
    news_16
    news_17
    news_18
    news_19
    news_2
    news_20
    news_21
    news_22
    news_23
    news_24
    news_25
    news_26
    news_27
    news_28
    news_29
    news_3
    news_30
    news_31
    news_32
    news_33
    news_34
    news_35
    news_36
    news_37
    news_38
    news_39
    news_4
    news_40
    news_41
    news_42
    news_43
    news_44
    news_45
    news_46
    news_47
    news_48
    news_49
    news_5
    news_50
    news_51
    news_52
    news_53
    news_6
    news_7
    news_8
    news_9
    news_bridge
    news_header
    news_old_header
    news_template
    release_history
    searching_by_hash
    sections
    shots085
    shots090
    shots092
    shots096u
    sidenav
    sidenav_conform
    sidenav_copyright
    sidenav_glade
    sidenav_hosted
    special_news
    title
  nl/
    current_version
    faq
    intro
    news_44
    news_45
    news_46
    news_47
    news_48
    news_49
    news_50
    news_bridge
    news_header
    sections
    sidenav
    sidenav_conform
    sidenav_copyright
    sidenav_glade
    sidenav_hosted
  uk/
    current_version
    donate
    intro
    links
    sidenav
    sidenav_conform
    sidenav_glade
    sidenav_hosted
  zh/
    intro
    news_45
    news_header
    sections
    sidenav
  .htaccess
  VERSION
  common.php