timer = $this->GetMicroTime();
$this->config = $config;
$this->dblink = connect($this->config["database_host"], $this->config["database_user"], $this->config["database_password"], $this->config["database_database"], $this->config["db_collation"], $this->config["database_driver"], $this->config["database_port"]);
$this->VERSION = WAKKA_VERSION;
$this->WVERSION = WACKO_VERSION;
}
// DATABASE
function Query($query, $debug=0)
{
if($this->GetConfigValue("debug")>=1) $start = $this->GetMicroTime();
$result = query($this->dblink, $query);
if($this->GetConfigValue("debug")>=1)
{
$time = $this->GetMicroTime() - $start;
$this->queryLog[] = array(
"query" => $query,
"time" => $time);
}
return $result;
}
function LoadSingle($query) { if ($data = $this->LoadAll($query)) return $data[0]; }
function LoadAll($query)
{
$data = array();
if ($r = $this->Query($query))
{
while ($row = fetch_assoc($r)) $data[] = $row;
free_result($r);
}
return $data;
}
// MISC
function GetMicroTime() { list($usec, $sec) = explode(" ",microtime()); return ((float)$usec + (float)$sec); }
function IncludeBuffered($filename, $notfoundText = "", $vars = "", $path = "")
{
if ($path) $dirs = explode(":", $path);
else $dirs = array("");
foreach($dirs as $dir)
{
if ($dir) $dir .= "/";
$fullfilename = $dir.$filename;
$fullfilename = trim($fullfilename, "./");
if (@file_exists($fullfilename))
{
if (is_array($vars)) extract($vars, EXTR_SKIP);
ob_start();
include($fullfilename);
$output = ob_get_contents();
ob_end_clean();
return $output;
}
}
if ($notfoundText) return $notfoundText;
else return false;
}
// VARIABLES
function GetPageTag() { return $this->tag; }
function GetPageSuperTag() { return $this->supertag; }
function GetPageTime() { return $this->page["time"]; }
function GetPageLastWriter() { return $this->page["user"]; }
function GetMethod() { return $this->method; }
function GetConfigValue($name) { return isset( $this->config[$name] ) ? $this->config[$name] : ''; }
function SetResource($lang) {$this->resource=&$this->resources[$lang];}
function SetLanguage($lang)
{
// echo "SetLanguage: ".$lang."
";
$this->LoadResource($lang);
$this->language = &$this->languages[$lang];
setlocale(LC_CTYPE,$this->language["locale"]);
$this->language["locale"] = setlocale(LC_CTYPE,0);
$this->language["UPPER"] = "[".$this->language["UPPER_P"]."]";
$this->language["UPPERNUM"] = "[0-9".$this->language["UPPER_P"]."]";
$this->language["LOWER"] = "[".$this->language["LOWER_P"]."]";
$this->language["ALPHA"] = "[".$this->language["ALPHA_P"]."]";
$this->language["ALPHANUM"] = "[0-9".$this->language["ALPHA_P"]."]";
$this->language["ALPHANUM_P"]= "0-9".$this->language["ALPHA_P"];
}
function LoadResource($lang)
{
if (!$this->resources[$lang])
{
$resourcefile = "lang/wakka.".$lang.".php";
if (@file_exists($resourcefile)) include($resourcefile);
// wakka.all
$resourcefile = "lang/wakka.all.php";
if (!$this->resources["all"])
{
if (@file_exists($resourcefile)) include($resourcefile);
$this->resources["all"] =& $wackoAllResource;
}
$wackoResource = array_merge($wakkaResource, $this->resources["all"]);
// theme
$resourcefile = "themes/".$this->config["theme"]."/lang/wakka.".$lang.".php";
if (@file_exists($resourcefile)) include($resourcefile);
$wackoResource = array_merge((array)$wackoResource, (array)$themeResource);
// wakka.all theme
$resourcefile = "themes/".$this->config["theme"]."/lang/wakka.all.php";
if (@file_exists($resourcefile)) include($resourcefile);
$wackoResource = array_merge((array)$wackoResource, (array)$themeResource);
$this->resources[$lang] = $wackoResource;
$this->LoadLang($lang);
}
}
function LoadLang($lang)
{
if (!isset( $this->languages[$lang] ))
{
$resourcefile = "lang/lang.".$lang.".php";
if (@file_exists($resourcefile)) include($resourcefile);
$this->languages[$lang] = $wackoLanguage;
$ue = @array_flip($wackoLanguage["unicode_entities"]);
$this->unicode_entities = array_merge($this->unicode_entities, $ue);
unset($this->unicode_entities[0]);
}
}
function LoadAllLanguages()
{
if (!$this->GetConfigValue("multilanguage")) return;
$langs = $this->AvailableLanguages();
foreach ($langs as $lang)
$this->LoadLang($lang);
}
function AvailableLanguages()
{
if (!$this->_langlist)
{
$handle=opendir("lang");
while (false!==($file = readdir($handle))) {
if ($file != "." && $file != ".." && $file != "wakka.all.php" && !is_dir("lang/".$file) && 1==preg_match("/^wakka\.(.*?)\.php$/",$file,$match)) {
$langlist[] = $match[1];
}
}
closedir($handle);
$this->_langlist = $langlist;
}
return $this->_langlist;
}
function GetResourceValue($name, $lang="", $dounicode=true)
{
if (!$this->GetConfigValue("multilanguage")) return $this->resource[$name];
//echo "GetResourceValue: $lang + $name + $this->userlang + $this->pagelang
";
if (!$lang && $this->userlang!=$this->pagelang) $lang = $this->userlang;
if ($lang!="")
{
$this->LoadResource($lang);
return (is_array($this->resources[$lang][$name]))?$this->resources[$lang][$name]:($dounicode?$this->DoUnicodeEntities($this->resources[$lang][$name], $lang):$this->resources[$lang][$name]);
}
return $this->resource[$name];
}
function FormatResourceValue($name, $lang="")
{
$string = $this->GetResourceValue($name, $lang, false);
$this->format_safe = false;
$string = $this->Format($string);
$this->format_safe = true;
return $string;
}
function DetermineLang()
{
$langlist = $this->AvailableLanguages();
//!!!! wrong code, maybe!
if ($this->GetMethod()=="edit" && $_GET["add"]==1)
if ($_REQUEST["lang"] && in_array($_REQUEST["lang"], $langlist))
$lang = $_REQUEST["lang"];
else
$lang = $this->userlang;
else
$lang = $this->pagelang;
return $lang;
}
function SetPageLang($lang)
{
if (!$lang) return false;
$this->pagelang = $lang;
$this->SetLanguage($lang);
return true;
}
function GetCharset()
{
$lang = $this->DetermineLang();
$this->LoadResource($lang);
return $this->languages[$lang]["charset"];
}
function DoUnicodeEntities($string, $lang)
{
if (!$this->GetConfigValue("multilanguage")) return $string;
$_lang = $this->DetermineLang();
if ($lang==$_lang) return $string;
// die("
"; if (!preg_match("/\&\#[0-9]+\;/", $t2)) $string = $t2; return $string; } function utf8ToUnicodeEntities ($source) { // array used to figure what number to decrement from character order value // according to number of characters used to map unicode to ascii by utf-8 $decrement[4] = 240; $decrement[3] = 224; $decrement[2] = 192; $decrement[1] = 0; // the number of bits to shift each charNum by $shift[1][0] = 0; $shift[2][0] = 6; $shift[2][1] = 0; $shift[3][0] = 12; $shift[3][1] = 6; $shift[3][2] = 0; $shift[4][0] = 18; $shift[4][1] = 12; $shift[4][2] = 6; $shift[4][3] = 0; $pos = 0; $len = strlen ($source); $encodedString = ''; while ($pos < $len) { $asciiPos = ord (substr ($source, $pos, 1)); if (($asciiPos >= 240) && ($asciiPos <= 255)) {// 4 chars representing one unicode character $thisLetter = substr ($source, $pos, 4); $pos += 4; } else if (($asciiPos >= 224) && ($asciiPos <= 239)) {// 3 chars representing one unicode character $thisLetter = substr ($source, $pos, 3); $pos += 3; } else if (($asciiPos >= 192) && ($asciiPos <= 223)) {// 2 chars representing one unicode character $thisLetter = substr ($source, $pos, 2); $pos += 2; } else {// 1 char (lower ascii) $thisLetter = substr ($source, $pos, 1); $pos += 1; } // process the string representing the letter to a unicode entity $thisLen = strlen ($thisLetter); if ($thisLen>1) { $thisPos = 0; $decimalCode = 0; while ($thisPos < $thisLen) { $thisCharOrd = ord (substr ($thisLetter, $thisPos, 1)); if ($thisPos == 0) { $charNum = intval ($thisCharOrd - $decrement[$thisLen]); $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); } else { $charNum = intval ($thisCharOrd - 128); $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); } $thisPos++; } $encodedLetter = "". $decimalCode . ';'; } else $encodedLetter = $thisLetter; $encodedString .= $encodedLetter; } return $encodedString; } function GetWakkaName() { return $this->GetConfigValue("wakka_name"); } function GetWakkaVersion() { return $this->VERSION; } function GetWackoVersion() { return $this->WVERSION; } // PAGES // NpjTranslit var $NpjMacros = array( "����" => "wiki", "����" => "wacko", "�����" => "shwacko", "���" => "web", "����" => "lance", "�����" => "kukutz", "���������" => "mendokusee", "������" => "iaremko", "�������" => "nikolai", "�������" => "aleksey", "��������" => "anatoly" ); function NpjTranslit($tag, $strtolow = TRAN_LOWERCASE, $donotload=TRAN_LOAD) { $_lang = null; if (!$this->GetConfigValue("multilanguage")) $donotload = 1; if (!$donotload) if ($page = $this->LoadPage($tag, "", LOAD_CACHE, LOAD_META)) { $_lang = $this->language["code"]; if ($page["lang"]) $lang = $page["lang"]; else $lang = $this->GetConfigValue("language"); $this->SetLanguage($lang); } $tag = str_replace( "//", "/", $tag ); $tag = str_replace( "-", "", $tag ); $tag = str_replace( " ", "", $tag ); $tag = str_replace( "'", "_", $tag ); $_tag = strtolower( $tag ); if ($strtolow) $tag = @strtr( $_tag, $this->NpjMacros ); else foreach( $this->NpjMacros as $macro=>$value ) while (($pos = strpos($_tag, $macro)) !== false) { $_tag = substr_replace( $_tag, $value, $pos, strlen($macro) ); $tag = substr_replace( $tag, ucfirst($value), $pos, strlen($macro) ); } $tag = @strtr( $tag, $this->language["NpjLettersFrom"], $this->language["NpjLettersTo"] ); $tag = @strtr( $tag, $this->language["NpjBiLetters"] ); if ($strtolow) $tag = strtolower( $tag ); if ($_lang) $this->SetLanguage($_lang); return rtrim($tag, "/"); } function Translit($tag, $direction=1) { //deprecated return $tag; } function LoadPage($tag, $time = "", $cache = LOAD_CACHE, $metadataonly = LOAD_ALL) { $supertag = $this->NpjTranslit($tag, TRAN_LOWERCASE, TRAN_DONTLOAD); if ($this->GetCachedWantedPage($supertag)==1) return ""; $page = $this->OldLoadPage($supertag,$time,$cache, true, $metadataonly); // 1. search for supertag if (!$page) // 2. if not found, search for tag // { $page = $this->OldLoadPage($tag,$time,$cache, false, $metadataonly); /* if ($page) // 3. if found, update supertag { $this->Query( "update ".$this->config["table_prefix"]."pages ". "set supertag='".$supertag."' where tag = '".$tag."';" ); } } */ if (!$page) $this->CacheWantedPage($supertag); return $page; } function OldLoadPage($tag, $time = "", $cache = 1, $supertagged = false, $metadataonly = 0) { $page = null; if (!$supertagged) $supertag = $this->NpjTranslit($tag, TRAN_LOWERCASE, TRAN_DONTLOAD); else $supertag=$tag; // retrieve from cache if (!$time && $cache && ($cachedPage = $this->GetCachedPage($supertag, $metadataonly))) $page = $cachedPage; // load page if ($metadataonly) $what = $this->pages_meta; else $what = "*"; if (!$page) { if ($supertagged) { $page = $this->LoadSingle("select ".$what." from ".$this->config["table_prefix"]."pages where supertag='".quote($this->dblink, $tag)."' and latest = 'Y' limit 1"); if ($time && $time!=$page["time"]) { $this->CachePage($page, $metadataonly); $page = $this->LoadSingle("select ".$what." from ".$this->config["table_prefix"]."revisions where supertag='".quote($this->dblink, $tag)."' and time = '".quote($this->dblink, $time)."' limit 1"); } } else { $page = $this->LoadSingle("select ".$what." from ".$this->config["table_prefix"]."pages where tag='".quote($this->dblink, $tag)."' and latest = 'Y' limit 1"); if ($time && $time!=$page["time"]) { $this->CachePage($page, $metadataonly); $page = $this->LoadSingle("select ".$what." from ".$this->config["table_prefix"]."revisions where tag='".quote($this->dblink, $tag)."' and time = '".quote($this->dblink, $time)."' limit 1"); } } }// cache result if (!$time && !$cachedPage) $this->CachePage($page, $metadataonly); return $page; } function GetCachedPage($tag, $metadataonly=0) { if (isset( $this->pageCache[$tag] )) if ($this->pageCache[$tag]["mdonly"]==0 || $metadataonly==$this->pageCache[$tag]["mdonly"]) return $this->pageCache[$tag]; return false; } function CachePage($page, $metadataonly=0) { $page["supertag"] = $this->NpjTranslit($page["supertag"], TRAN_LOWERCASE, TRAN_DONTLOAD); $this->pageCache[$page["supertag"]] = $page; $this->pageCache[$page["supertag"]]["mdonly"] = $metadataonly; } function CacheWantedPage($tag, $check = 0) { if ($check==0) $this->wantedCache[$this->language["code"]][$tag] = 1; else if ($this->OldLoadPage($tag, "", 1, false, 1)=="") $this->wantedCache[$this->language["code"]][$tag] = 1; } function ClearCacheWantedPage($tag){ $this->wantedCache[$this->language["code"]][$tag] = 0; } function GetCachedWantedPage($tag) { if (isset( $this->wantedCache[$this->language["code"]][$tag] )) return $this->wantedCache[$this->language["code"]][$tag]; else return ''; } function GetCachedACL($tag, $privilege, $useDefaults) { if (isset( $this->aclCache[$tag."#".$privilege."#".$useDefaults] )) return $this->aclCache[$tag."#".$privilege."#".$useDefaults]; else return ''; } function CacheACL($tag, $privilege, $useDefaults, $acl) { $this->aclCache[$tag."#".$privilege."#".$useDefaults] = $acl; } function CacheLinks() { if ($links = $this->LoadAll("select * from ".$this->config["table_prefix"]."links where from_tag='".quote($this->dblink, $this->GetPageTag())."'")) { $cl = count($links); for ($i=0; $i<$cl; $i++) $pages[$i] = $links[$i]["to_tag"]; } $user = $this->GetUser(); $pages[$cl] = $user["name"]; $bookm = $this->GetDefaultBookmarks($user["lang"], "site")."\n".($user["bookmarks"] ? $user["bookmarks"] : $this->GetDefaultBookmarks($user["lang"])); $bookmarks = explode("\n", $bookm); for ($i=0; $i<=count($bookmarks); $i++) $pages[$cl+$i] = preg_replace("/^(.*?)\s.*$/","\\1",preg_replace("/[\[\]\(\)]/","",$bookmarks[$i])); $pages[]=$this->GetPageTag(); $spages_str = ''; $pages_str = ''; for ($i=0; $i".$string."|".$t1."|".$t2."
| "; else echo " | ";
echo " ".$text." ";
echo " | ";
echo "
]+)>(.+?)
)!is", array( &$this, "NumerateTocCallbackP"), $what ); } return $what; } function NumerateTocCallbackToc( $matches ) { return ''. $style["before"].$matches[4].$style["after"]. '
'.$style["_after"]; } // BREADCRUMBS -- additional navigation added with WackoClusters function GetPagePath() { $steps = explode("/", $this->tag); $result = ""; $links = array(); $_links = array(); for ($i=0;$i