Location: PHPKode > projects > sips > sipssys/code/site.inc.php
<?
/* sips -- the simple, integrated publishing system
 * Copyright (C) 2000 Haakon Nilsen <hide@address.com>
 *
 * $Id: site.inc.php,v 1.14 2002/02/09 17:32:20 haakon Exp $
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

function cleanStr($s) {
   // returns a "clean" string stripped for slashes and HTML tags
   return htmlentities(stripslashes(ereg_replace("<([^>]|\n)*>", "", $s)));
}

function deleteUserCache($username) {
   global $config;
   $cachefile = $config["sipssys"] ."/users/$username[0]/$username/cache";
   if (file_exists($cachefile)) {
      unlink($cachefile);
   }
}

function getUserValues($username) {
   global $config;
   $lines = file($config["sipssys"] ."/users/$username[0]/$username/user");
   for ($i = 0; $i < count($lines); $i++) {
      $keyval = explode("::", $lines[$i]);
      $val[$keyval[0]] = chop($keyval[1]);
   }
   return $val;
}

function getUserValue($username, $key) {
   global $config;
   $lines = file($config["sipssys"] ."/users/$username[0]/$username/user");
  	for ($i=0; ($i<count($lines)) && (!isset($val)); $i++) {
      $keyval = explode("::", $lines[$i]);
  	   if ($keyval[0] == $key) {
         $val = chop($keyval[1]);
      }
   }
   return $val;
}

function setUserValue($username, $key, $value) {
   global $config;
   $fn = $config["sipssys"] ."/users/$username[0]/$username/user";
   $lines = file($fn);
   $fp = fopen($fn, "w");
   for ($i=0; $i<count($lines); $i++) {
      $keyval = explode("::", $lines[$i]);
      if ($keyval[0] != $key) {
        fwrite($fp, chop($lines[$i]) ."\n");
      }
   }
   if ($value != "") {
        fwrite($fp, "$key::" .str_replace("\n", "", $value));
   }
   fclose($fp);
}

function i18n($s, $param1 = "", $param2 = "", $param3 = "", $param4 = "") {
   global $trans, $config;
   $out = translate($s);

   /*if (isset($trans[$s]))
      $out = $trans[$s];
   else
      $out = $s;*/
   $out = ereg_replace("#SITENAME#", $config["sitename"], $out);
   $out = ereg_replace("#1#", $param1, $out);
   $out = ereg_replace("#2#", $param2, $out);
   $out = ereg_replace("#3#", $param3, $out);
   $out = ereg_replace("#4#", $param4, $out);
   $out = ereg_replace("#I#", "<i>", $out);
   $out = ereg_replace("#/I#", "</i>", $out);
   $out = ereg_replace("#B#", "<b>", $out);
   $out = ereg_replace("#/B#", "</b>", $out);
   return $out;
}

$VERSION = "0.3.1";
error_reporting(1); // <- remove this line when debugging
include($config["sipssys"] ."/lang/" .$config["lang"] .".lang");

$cryptuser = $HTTP_COOKIE_VARS["user"];
if ($cryptuser == "") {
   $usrname = "default";
} else {
   $auth = explode(":", $cryptuser);
   $u = $auth[0];
   if (file_exists($config["sipssys"] ."/users/$u[0]/$u/user")) {
      $usr = getUserValues($u);
      if ($usr["Password"] == $auth[1]) {
         $usrname = $auth[0]; // we're in!
         if ($usr["Timezone"] == "") { // temp code to ease transition to timezone system. This code will be removed eventually...
            $t = getUserValue("default", "Timezone");
            setUserValue($usrname, "Timezone", $t);
            $usr["Timezone"] = $t;
         }
      } else {
         setcookie("user");
         $usrname = "default"; // password in cookie is incorrect, resigning to default
      }
   } else { // account has been deleted from somewhere else, this cookie is obsolete, resigning to default
      setcookie("user");
      $usrname = "default";
   }
}
if ($usrname == "default") $usr = getUserValues("default");
else {
   if (($usr["Theme"] == "") || (!file_exists($config["sipssys"] ."/themes/" .$usr["Theme"])))  {
      $t = getUserValue("default", "Theme");
      setUserValue($usrname, "Theme", $t);
      $usr["Theme"] = $t;
   }
}

$themeconfig = $config["sipssys"] ."/themes/" .$usr["Theme"] ."/.themeconfig.php";
if (file_exists($themeconfig)) include $themeconfig;


function printTop($pagetitle) {
   //prints the top html
   global $config, $usr, $bottom;
   $full = implode("", file($config["sipssys"] ."/themes/" .$usr["Theme"] ."/site"));
   $full = str_replace("#TITLE#", $config["sitename"] ." | $pagetitle", $full);
   $full = str_replace("#DATE#", strftime($config["date-format"]), $full);
   $h = split("#CONTENT#", $full);
   print($h[0]);
   $bottom = $h[1];
}

function printBottom() {
   //prints the bottom html
   global $bottom;
   print($bottom);
}

?>
Return current item: sips