<?php
function ShowPage($pagename) {
global $g_dbhost, $g_dbuser, $g_dbname, $g_dbpwd, $g_admin_name, $g_admin_pwd, $g_cookie_prefix, $g_language, $g_template, $g_sitename, $g_site_url;
include ("templates/".$g_template."/".$pagename.".htm");
}
function DirToTemplate() {
global $g_dbhost, $g_dbuser, $g_dbname, $g_dbpwd, $g_admin_name, $g_admin_pwd, $g_cookie_prefix, $g_language, $g_template, $g_sitename, $g_site_url;
echo $g_site_url."/templates/".$g_template."/";
}
function GetDirToTemplate() {
global $g_dbhost, $g_dbuser, $g_dbname, $g_dbpwd, $g_admin_name, $g_admin_pwd, $g_cookie_prefix, $g_language, $g_template, $g_sitename, $g_site_url;
return $g_site_url."/templates/".$g_template."/";
}
function SQLFilter($String)
{
return stripslashes(strip_tags(htmlspecialchars($String, ENT_QUOTES)));
}
function limpiar_acentos($s)
{
$s = ereg_replace("[áàâãª]","a",$s);
$s = ereg_replace("[ÁÀÂÃ]","A",$s);
$s = ereg_replace("[ÍÌÎ]","I",$s);
$s = ereg_replace("[íìî]","i",$s);
$s = ereg_replace("[éèê]","e",$s);
$s = ereg_replace("[ÉÈÊ]","E",$s);
$s = ereg_replace("[óòôõº]","o",$s);
$s = ereg_replace("[ÓÒÔÕ]","O",$s);
$s = ereg_replace("[úùû]","u",$s);
$s = ereg_replace("[ÚÙÛ]","U",$s);
$s = str_replace("ç","c",$s);
$s = str_replace("Ç","C",$s);
$s = str_replace("[ñ]","n",$s);
$s = str_replace("[Ñ]","N",$s);
return $s;
}
function GenerateConfig($admin_user,$admin_password,$language,$site_name,$site_url,$template,$db_host,$db_user,$db_pwd,$db_name,$db_prefix,$search_numr) {
global $g_dbhost, $g_dbuser, $g_dbname, $g_dbpwd, $g_admin_name, $g_admin_pwd, $g_cookie_prefix, $g_language, $g_template, $g_sitename, $g_site_url, $g_dbprefix;
if ( ! $file=fopen("config.php", "w")) {
errpage (_CONFIGPHP);
die();
}
if ( ! $file2=fopen("lang.php", "w")) {
errpage (_LANGPHP);
die();
}
fputs ($file,"<?php \r\n\r\ninclude \"lang.php\";\r\n\r\nglobal \$g_dbprefix, \$g_dbhost, \$g_dbuser, \$g_dbname, \$g_dbpwd, \$g_admin_name, \$g_admin_pwd, \$g_cookie_prefix, \$g_template, \$g_sitename, \$g_site_url, \$g_search_numr; \r\n");
fputs ($file,"\$g_dbhost='".$db_host."';\r\n\$g_dbuser='".$db_user."';\r\n\$g_dbname='".$db_name."';\r\n\$g_dbpwd='".$db_pwd."';\r\n\$g_dbprefix='".$db_prefix."';");
fputs ($file,"\$g_admin_name='".$admin_user."';\r\n");
fputs ($file,"\$g_admin_pwd='".$admin_password."';\r\n");
fputs ($file,"\$g_sitename='".$site_name."';\r\n");
fputs ($file,"\$g_cookie_prefix='nooms_cms_'.md5(\$g_sitename);\r\n");
fputs ($file,"\$g_template='".$template."';\r\n");
fputs ($file,"\$g_site_url='".$site_url."';\r\n");
fputs ($file,"\$g_search_numr='".$search_numr."';\r\n");
fputs ($file,"include 'lang/'.\$g_language.'.php';\r\n");
fputs ($file,"include 'db.php';\r\n");
fputs ($file,"?>");
fclose($file);
fputs ($file2,"<?php global \$g_language; \$g_language='".$language."'; ?>");
}
function PageIndexReplace($buffer,$title) {
global $g_dbprefix, $g_site_url;
////////// NAVIGATION ///////////
while (strpos($buffer,"{NAVIGATION_START}")!==false) {
if (strpos($buffer,"{NAVIGATION_START}")===false) {}else{
$aux_buffer=substr($buffer,0,strpos($buffer,"{NAVIGATION_START}"));
if (strpos($buffer,"{NAVIGATION_END}")===false) {}else{
$nav_block=substr($buffer,strpos($buffer,"{NAVIGATION_START}")+strlen("{NAVIGATION_START}"),strpos($buffer,"{NAVIGATION_END}")-strpos($buffer,"{NAVIGATION_START}")-strlen("{NAVIGATION_START}"));
$aux_buffer=$aux_buffer.str_replace("{NAVIGATION_NAME}",_HOME,str_replace("{NAVIGATION_LINK}","index.php",str_replace("{NAVIGATION_TARGET}","",$nav_block)));
$result=mysql_query("SELECT * FROM ".$g_dbprefix."sections WHERE parent_id=0 AND show_menu=1 ORDER BY pref ASC");
while ($row=mysql_fetch_array($result)) {
if ($row['sectionlink']=='') {
$link="index.php?section=".$row['id'];
}else{
$link=$row['sectionlink'];
}
$name=$row['name'];
$aux_buffer=$aux_buffer.str_replace("{NAVIGATION_NAME}",$name,str_replace("{NAVIGATION_LINK}",$link,str_replace("{NAVIGATION_TARGET}",$row['sectionlinkt'],$nav_block)));
}
$buffer=$aux_buffer.substr($buffer,strpos($buffer,"{NAVIGATION_END}")+strlen("{NAVIGATION_END}"));
}
}
}
////////// PAGE ///////////
if (strpos($buffer,"{PAGE_START}")===false) {}else{
$aux_buffer=substr($buffer,0,strpos($buffer,"{PAGE_START}"));
if (strpos($buffer,"{PAGE_END}")===false) {}else{
$pag_block=substr($buffer,strpos($buffer,"{PAGE_START}")+strlen("{PAGE_START}"),strpos($buffer,"{PAGE_END}")-strpos($buffer,"{PAGE_START}")-strlen("{PAGE_START}"));
$result=mysql_query("SELECT * FROM ".$g_dbprefix."pages WHERE home=1 ORDER BY home_pref ASC");
while ($row=mysql_fetch_array($result)) {
$minibuffer=str_replace("{PAGE_CONTENT}",base64_decode($row['content']),$pag_block);
$minibuffer=str_replace("{PAGE_TITLE}",$row['title'],$minibuffer);
$minibuffer=str_replace("{PAGE_ID}",$row['id'],$minibuffer);
$minibuffer=CommentReplace($minibuffer,$row['comment'],$row['id'],1);
$aux_buffer=$aux_buffer.$minibuffer;
}
$buffer=$aux_buffer.substr($buffer,strpos($buffer,"{PAGE_END}")+strlen("{PAGE_END}"));
}
}
$buffer=str_replace("{THIS_PAGE}",$g_site_url."/index.php",$buffer);
return SimpleReplace($buffer,$title);
}
function SectionReplace($buffer,$title,$sectionid,$page) {
global $g_dbprefix,$g_site_url;
CheckSectionExists($sectionid);
////////// NAVIGATION ///////////
while (strpos($buffer,"{NAVIGATION_START}")!==false) {
if (strpos($buffer,"{NAVIGATION_START}")===false) {}else{
$aux_buffer=substr($buffer,0,strpos($buffer,"{NAVIGATION_START}"));
if (strpos($buffer,"{NAVIGATION_END}")===false) {}else{
$nav_block=substr($buffer,strpos($buffer,"{NAVIGATION_START}")+strlen("{NAVIGATION_START}"),strpos($buffer,"{NAVIGATION_END}")-strpos($buffer,"{NAVIGATION_START}")-strlen("{NAVIGATION_START}"));
$aux_buffer=$aux_buffer.str_replace("{NAVIGATION_NAME}",_HOME,str_replace("{NAVIGATION_LINK}","index.php",str_replace("{NAVIGATION_TARGET}","",$nav_block)));
$result=mysql_query("SELECT * FROM ".$g_dbprefix."sections WHERE parent_id=0 AND show_menu=1 ORDER BY pref ASC");
while ($row=mysql_fetch_array($result)) {
if ($row['sectionlink']=='') {
$link="index.php?section=".$row['id'];
}else{
$link=$row['sectionlink'];
}
$name=$row['name'];
$aux_buffer=$aux_buffer.str_replace("{NAVIGATION_NAME}",$name,str_replace("{NAVIGATION_LINK}",$link,str_replace("{NAVIGATION_TARGET}",$row['sectionlinkt'],$nav_block)));
}
$buffer=$aux_buffer.substr($buffer,strpos($buffer,"{NAVIGATION_END}")+strlen("{NAVIGATION_END}"));
}
}
}
////////// (SUB)SECTION MENU ///////////
while (strpos($buffer,"{SECTION_START}")!==false) {
if (strpos($buffer,"{SECTION_START}")===false) {}else{
$aux_buffer=substr($buffer,0,strpos($buffer,"{SECTION_START}"));
if (strpos($buffer,"{SECTION_END}")===false) {}else{
$nav_block=substr($buffer,strpos($buffer,"{SECTION_START}")+strlen("{SECTION_START}"),strpos($buffer,"{SECTION_END}")-strpos($buffer,"{SECTION_START}")-strlen("{SECTION_START}"));
$result=mysql_query("SELECT * FROM ".$g_dbprefix."sections WHERE parent_id=".$sectionid." AND show_menu=1 ORDER BY pref ASC");
while ($row=mysql_fetch_array($result)) {
if ($row['sectionlink']=='') {
$link="index.php?section=".$row['id'];
}else{
$link=$row['sectionlink'];
}
$name=$row['name'];
$aux_buffer=$aux_buffer.str_replace("{SECTION_NAME}",$name,str_replace("{SECTION_LINK}",$link,str_replace("{SECTION_TARGET}",$row['sectionlinkt'],$nav_block)));
}
$buffer=$aux_buffer.substr($buffer,strpos($buffer,"{SECTION_END}")+strlen("{SECTION_END}"));
}
}
}
$result=mysql_query("SELECT * FROM ".$g_dbprefix."sections WHERE id=".$sectionid);
$row=mysql_fetch_array($result);
$parent_name=$row['name'];
$perpage=$row['page_list'];
$typeo=$row['type_order'];
////////// PAGE ///////////
$pag=$page;
if ($pag<1) {$pag=1;}
if (strpos($buffer,"{PAGE_START}")===false) {}else{
$aux_buffer=substr($buffer,0,strpos($buffer,"{PAGE_START}"));
if (strpos($buffer,"{PAGE_END}")===false) {}else{
$pag_block=substr($buffer,strpos($buffer,"{PAGE_START}")+strlen("{PAGE_START}"),strpos($buffer,"{PAGE_END}")-strpos($buffer,"{PAGE_START}")-strlen("{PAGE_START}"));
if ($typeo==0) {
$result=mysql_query("SELECT * FROM ".$g_dbprefix."pages WHERE section_id=".$sectionid." ORDER BY date DESC");
}elseif ($typeo==1) {
$result=mysql_query("SELECT * FROM ".$g_dbprefix."pages WHERE section_id=".$sectionid." ORDER BY date ASC");
}else{
$result=mysql_query("SELECT * FROM ".$g_dbprefix."pages WHERE section_id=".$sectionid." ORDER BY pref ASC");
}
if ($perpage!=0) {
if (mysql_num_rows($result)%$perpage==0) {
$numpages=mysql_num_rows($result)/$perpage;
}else{
$numpages=intval(mysql_num_rows($result)/$perpage)+1;
}
}
if ($numpages==0) {$numpages=1;}
$pagecount=0;
while ($row=mysql_fetch_array($result)) {
$pagecount++;
if ($perpage==0) {
$minibuffer=str_replace("{PAGE_CONTENT}",base64_decode($row['content']),$pag_block);
$minibuffer=str_replace("{PAGE_TITLE}",$row['title'],$minibuffer);
$minibuffer=str_replace("{PAGE_ID}",$row['id'],$minibuffer);
$minibuffer=CommentReplace($minibuffer,$row['comment'],$row['id'],0);
$aux_buffer=$aux_buffer.$minibuffer;
}else{
if ($pagecount>$perpage*($pag-1)) {
if ($pagecount<$perpage*$pag+1) {
$minibuffer=str_replace("{PAGE_CONTENT}",base64_decode($row['content']),$pag_block);
$minibuffer=str_replace("{PAGE_TITLE}",$row['title'],$minibuffer);
$minibuffer=str_replace("{PAGE_ID}",$row['id'],$minibuffer);
$minibuffer=CommentReplace($minibuffer,$row['comment'],$row['id'],0);
$aux_buffer=$aux_buffer.$minibuffer;
}}
}
}
$buffer=$aux_buffer.substr($buffer,strpos($buffer,"{PAGE_END}")+strlen("{PAGE_END}"));
}
}
if (strpos($buffer,"{NAV_PREV_START}")===false) {}else{
$aux_buffer=substr($buffer,0,strpos($buffer,"{NAV_PREV_START}"));
if (strpos($buffer,"{NAV_PREV_END}")===false) {}else{
$block1=substr($buffer,strpos($buffer,"{NAV_PREV_START}")+strlen("{NAV_PREV_START}"),strpos($buffer,"{NAV_PREV_END}")-strpos($buffer,"{NAV_PREV_START}")-strlen("{NAV_PREV_START}"));
if (($pag==1) || ($perpage==0)) {
$buffer=$aux_buffer.substr($buffer,strpos($buffer,"{NAV_PREV_END}")+strlen("{NAV_PREV_END}"));
}else{
$buffer=$aux_buffer.$block1.substr($buffer,strpos($buffer,"{NAV_PREV_END}")+strlen("{NAV_PREV_END}"));
}
}
}
if (strpos($buffer,"{NAV_NEXT_START}")===false) {}else{
$aux_buffer=substr($buffer,0,strpos($buffer,"{NAV_NEXT_START}"));
if (strpos($buffer,"{NAV_NEXT_END}")===false) {}else{
$block1=substr($buffer,strpos($buffer,"{NAV_NEXT_START}")+strlen("{NAV_NEXT_START}"),strpos($buffer,"{NAV_NEXT_END}")-strpos($buffer,"{NAV_NEXT_START}")-strlen("{NAV_NEXT_START}"));
if (($pag==$numpages) || ($perpage==0)) {
$buffer=$aux_buffer.substr($buffer,strpos($buffer,"{NAV_NEXT_END}")+strlen("{NAV_NEXT_END}"));
}else{
$buffer=$aux_buffer.$block1.substr($buffer,strpos($buffer,"{NAV_NEXT_END}")+strlen("{NAV_NEXT_END}"));
}
}
}
$buffer=str_replace("{PARENT_SECTION_NAME}",$parent_name,$buffer);
$buffer=str_replace("{NAV_PREV}",_PREVIOUS_PAGE,$buffer);
$buffer=str_replace("{NAV_NEXT}",_NEXT_PAGE,$buffer);
$buffer=str_replace("{NAV_PREV_LINK}","index.php?section=".$sectionid."&pag=".($pag-1),$buffer);
$buffer=str_replace("{NAV_NEXT_LINK}","index.php?section=".$sectionid."&pag=".($pag+1),$buffer);
$buffer=str_replace("{THIS_PAGE}",$g_site_url."/index.php?section=".$sectionid."&pag=".$page,$buffer);
return SimpleReplace($buffer,$title);
}
function PageReplace($buffer,$title,$pageid) {
global $g_dbprefix,$g_site_url;
CheckPageExists($pageid);
////////// NAVIGATION ///////////
while (strpos($buffer,"{NAVIGATION_START}")!==false) {
if (strpos($buffer,"{NAVIGATION_START}")===false) {}else{
$aux_buffer=substr($buffer,0,strpos($buffer,"{NAVIGATION_START}"));
if (strpos($buffer,"{NAVIGATION_END}")===false) {}else{
$nav_block=substr($buffer,strpos($buffer,"{NAVIGATION_START}")+strlen("{NAVIGATION_START}"),strpos($buffer,"{NAVIGATION_END}")-strpos($buffer,"{NAVIGATION_START}")-strlen("{NAVIGATION_START}"));
$aux_buffer=$aux_buffer.str_replace("{NAVIGATION_NAME}",_HOME,str_replace("{NAVIGATION_LINK}","index.php",str_replace("{NAVIGATION_TARGET}","",$nav_block)));
$result=mysql_query("SELECT * FROM ".$g_dbprefix."sections WHERE parent_id=0 AND show_menu=1 ORDER BY pref ASC");
while ($row=mysql_fetch_array($result)) {
if ($row['sectionlink']=='') {
$link="index.php?section=".$row['id'];
}else{
$link=$row['sectionlink'];
}
$name=$row['name'];
$aux_buffer=$aux_buffer.str_replace("{NAVIGATION_NAME}",$name,str_replace("{NAVIGATION_LINK}",$link,str_replace("{NAVIGATION_TARGET}",$row['sectionlinkt'],$nav_block)));
}
$buffer=$aux_buffer.substr($buffer,strpos($buffer,"{NAVIGATION_END}")+strlen("{NAVIGATION_END}"));
}
}
}
////////// (SUB)SECTION MENU ///////////
$result5=mysql_query("SELECT * FROM ".$g_dbprefix."pages WHERE id=".$pageid);
$row5=mysql_fetch_array($result5);
////////// PAGE ///////////
$pag=$page;
if ($pag<1) {$pag=1;}
if (strpos($buffer,"{PAGE_START}")===false) {}else{
$aux_buffer=substr($buffer,0,strpos($buffer,"{PAGE_START}"));
if (strpos($buffer,"{PAGE_END}")===false) {}else{
$pag_block=substr($buffer,strpos($buffer,"{PAGE_START}")+strlen("{PAGE_START}"),strpos($buffer,"{PAGE_END}")-strpos($buffer,"{PAGE_START}")-strlen("{PAGE_START}"));
$minibuffer=str_replace("{PAGE_CONTENT}",base64_decode($row5['content']),$pag_block);
$minibuffer=str_replace("{PAGE_TITLE}",$row5['title'],$minibuffer);
$minibuffer=str_replace("{PAGE_ID}",$row5['id'],$minibuffer);
$minibuffer=CommentReplace($minibuffer,$row5['comment'],$row5['id'],0);
$aux_buffer=$aux_buffer.$minibuffer;
}
$buffer=$aux_buffer.substr($buffer,strpos($buffer,"{PAGE_END}")+strlen("{PAGE_END}"));
}
$buffer=str_replace("{PARENT_SECTION_NAME}",$parent_name,$buffer);
$buffer=str_replace("{THIS_PAGE}",$g_site_url."/index.php?page=".$pageid,$buffer);
return SimpleReplace($buffer,$title);
}
function SearchReplace($buffer,$title,$numresults,$resarray,$page) {
global $g_dbprefix;
////////// NAVIGATION ///////////
while (strpos($buffer,"{NAVIGATION_START}")!==false) {
if (strpos($buffer,"{NAVIGATION_START}")===false) {}else{
$aux_buffer=substr($buffer,0,strpos($buffer,"{NAVIGATION_START}"));
if (strpos($buffer,"{NAVIGATION_END}")===false) {}else{
$nav_block=substr($buffer,strpos($buffer,"{NAVIGATION_START}")+strlen("{NAVIGATION_START}"),strpos($buffer,"{NAVIGATION_END}")-strpos($buffer,"{NAVIGATION_START}")-strlen("{NAVIGATION_START}"));
$aux_buffer=$aux_buffer.str_replace("{NAVIGATION_NAME}",_HOME,str_replace("{NAVIGATION_LINK}","index.php",str_replace("{NAVIGATION_TARGET}","",$nav_block)));
$result=mysql_query("SELECT * FROM ".$g_dbprefix."sections WHERE parent_id=0 AND show_menu=1 ORDER BY pref ASC");
while ($row=mysql_fetch_array($result)) {
if ($row['sectionlink']=='') {
$link="index.php?section=".$row['id'];
}else{
$link=$row['sectionlink'];
}
$name=$row['name'];
$aux_buffer=$aux_buffer.str_replace("{NAVIGATION_NAME}",$name,str_replace("{NAVIGATION_LINK}",$link,str_replace("{NAVIGATION_TARGET}",$row['sectionlinkt'],$nav_block)));
}
$buffer=$aux_buffer.substr($buffer,strpos($buffer,"{NAVIGATION_END}")+strlen("{NAVIGATION_END}"));
}
}
}
global $g_search_numr;
$perpage=$g_search_numr;
////////// PAGE ///////////
$pag=$page;
if ($pag<1) {$pag=1;}
if (strpos($buffer,"{SEARCH_RESULT_START}")===false) {}else{
$aux_buffer=substr($buffer,0,strpos($buffer,"{SEARCH_RESULT_START}"));
if (strpos($buffer,"{SEARCH_RESULT_END}")===false) {}else{
$pag_block=substr($buffer,strpos($buffer,"{SEARCH_RESULT_START}")+strlen("{SEARCH_RESULT_START}"),strpos($buffer,"{SEARCH_RESULT_END}")-strpos($buffer,"{SEARCH_RESULT_START}")-strlen("{SEARCH_RESULT_START}"));
if ($numresults%$perpage==0) {
$numpages=$numresults/$perpage;
}else{
$numpages=intval($numresults/$perpage)+1;
}
if ($numpages==0) {$numpages=1;}
$x=0;
if ($numpages==0) {
$aux_buffer.="<font class='noresults'>"._NO_SEARCH_RESULT."</font>";
}
while ($x<$numresults) {
$pagecount++;
if ($pagecount>$perpage*($pag-1)) {
if ($pagecount<$perpage*$pag+1) {
//$minibuffer=str_replace("{SEARCH_RESULT_SECTION}",base64_decode($row['content']),$pag_block);
$minibuffer=str_replace("{SEARCH_TITLE}",$resarray[$x]['title'],$pag_block);
$result8=mysql_query("SELECT * FROM ".$g_dbprefix."sections WHERE id=".$resarray[$x]['section']);
$row8=mysql_fetch_array($result8);
$minibuffer=str_replace("{SEARCH_SECTION}",$row8['name'],$minibuffer);
$minibuffer=str_replace("{SEARCH_SECTION_LINK}","index.php?section=".$row8['id'],$minibuffer);
$minibuffer=str_replace("{SEARCH_LINK}","index.php?page=".$resarray[$x]['id'],$minibuffer);
$aux_buffer=$aux_buffer.$minibuffer;
}
}
$x++;
}
$buffer=$aux_buffer.substr($buffer,strpos($buffer,"{SEARCH_RESULT_END}")+strlen("{SEARCH_RESULT_END}"));
}
}
if (strpos($buffer,"{NAV_PREV_START}")===false) {}else{
$aux_buffer=substr($buffer,0,strpos($buffer,"{NAV_PREV_START}"));
if (strpos($buffer,"{NAV_PREV_END}")===false) {}else{
$block1=substr($buffer,strpos($buffer,"{NAV_PREV_START}")+strlen("{NAV_PREV_START}"),strpos($buffer,"{NAV_PREV_END}")-strpos($buffer,"{NAV_PREV_START}")-strlen("{NAV_PREV_START}"));
if ($pag==1) {
$buffer=$aux_buffer.substr($buffer,strpos($buffer,"{NAV_PREV_END}")+strlen("{NAV_PREV_END}"));
}else{
$buffer=$aux_buffer.$block1.substr($buffer,strpos($buffer,"{NAV_PREV_END}")+strlen("{NAV_PREV_END}"));
}
}
}
if (strpos($buffer,"{NAV_NEXT_START}")===false) {}else{
$aux_buffer=substr($buffer,0,strpos($buffer,"{NAV_NEXT_START}"));
if (strpos($buffer,"{NAV_NEXT_END}")===false) {}else{
$block1=substr($buffer,strpos($buffer,"{NAV_NEXT_START}")+strlen("{NAV_NEXT_START}"),strpos($buffer,"{NAV_NEXT_END}")-strpos($buffer,"{NAV_NEXT_START}")-strlen("{NAV_NEXT_START}"));
if (($pag==$numpages) || ($numpages==0)) {
$buffer=$aux_buffer.substr($buffer,strpos($buffer,"{NAV_NEXT_END}")+strlen("{NAV_NEXT_END}"));
}else{
$buffer=$aux_buffer.$block1.substr($buffer,strpos($buffer,"{NAV_NEXT_END}")+strlen("{NAV_NEXT_END}"));
}
}
}
$buffer=str_replace("{PARENT_SECTION_NAME}",$parent_name,$buffer);
$buffer=str_replace("{NAV_PREV}",_PREVIOUS_PAGE,$buffer);
$buffer=str_replace("{NAV_NEXT}",_NEXT_PAGE,$buffer);
$buffer=str_replace("{NAV_PREV_LINK}","search.php?q=".$_GET['q']."&pag=".($pag-1),$buffer);
$buffer=str_replace("{NAV_NEXT_LINK}","search.php?q=".$_GET['q']."&pag=".($pag+1),$buffer);
$buffer=str_replace("{SEARCH_QUERY}",$_GET['q'],$buffer);
return SimpleReplace($buffer,$title);
}
function SimpleReplace($buffer,$title) {
global $g_language;
$buffer=str_replace("{PATH_TO_TEMPLATE}",GetDirToTemplate(),$buffer);
$buffer=str_replace("{TITLE}",$title,$buffer);
$buffer=str_replace("{VAR_SECTIONS}",_SECTIONS,$buffer);
$buffer=str_replace("{VAR_SECTION}",_SECTION,$buffer);
$buffer=str_replace("{VAR_HOME}",_HOME,$buffer);
$buffer=str_replace("{VAR_SEARCH}",_SEARCH,$buffer);
$buffer=str_replace("{VAR_SEARCH_RESULT}",_SEARCH_RESULT,$buffer);
$buffer=str_replace("{VAR_PAGE}",_PAGE,$buffer);
$buffer=str_replace("{VAR_PAGES}",_PAGES,$buffer);
$buffer=str_replace("{VAR_OF}",_OF,$buffer);
$buffer=str_replace("{VAR_SEARCH_NOW}",_SEARCH_NOW,$buffer);
$buffer=str_replace("{VAR_YOU_ARE_IN}",_YOU_ARE_IN,$buffer);
$buffer=str_replace("{VAR_NEXT_PAGE}",_NEXT_PAGE,$buffer);
$buffer=str_replace("{VAR_PREVIOUS_PAGE}",_PREVIOUS_PAGE,$buffer);
$buffer=str_replace("{VAR_ERROR_OCCURRED}",_ERROR_OCCURRED,$buffer);
$buffer=str_replace("{VAR_COMMENT_POSTED_BY}",_COMMENT_POSTED_BY,$buffer);
$buffer=str_replace("{VAR_COMMENT_IN}",_COMMENT_ON,$buffer);
$buffer=str_replace("{VAR_COMMENT_NAME}",_COMMENT_NAME,$buffer);
$buffer=str_replace("{VAR_COMMENT_EMAIL}",_COMMENT_EMAIL,$buffer);
$buffer=str_replace("{VAR_COMMENT_NAME_CHECK}",_COMMENT_NAME_CHECK,$buffer);
$buffer=str_replace("{VAR_COMMENT_EMAIL_CHECK}",_COMMENT_EMAIL_CHECK,$buffer);
$buffer=str_replace("{VAR_COMMENT_CONTENT_CHECK}",_COMMENT_CONTENT_CHECK,$buffer);
$buffer=str_replace("{VAR_COMMENT_SUBMIT}",_COMMENT_SUBMIT,$buffer);
$buffer=str_replace("{VAR_COMMENTS_HIDE}",_COMMENTS_HIDE,$buffer);
$buffer=str_replace("{VAR_POST_COMMENT}",_POST_COMMENT,$buffer);
$buffer=str_replace("{VAR_COMMENT_ON}",_COMMENT_ON,$buffer);
$buffer=str_replace("{VAR_INSERT_SMILEY}",_INSERT_SMILEY,$buffer);
$buffer=str_replace("{LANG}",$g_language,$buffer);
return $buffer;
}
function SmileyReplace($buffer) {
global $g_dbprefix,$buffer2;
$buffer2=$buffer;
$result=mysql_query("SELECT * FROM ".$g_dbprefix."smileys");
while ($row=mysql_fetch_array($result)) {
$buffer2=str_replace($row['code'],"<img border=0 src='".GetDirToTemplate()."smileys/".$row['img']."'>",$buffer2);
}
return $buffer2;
}
function ErrorPage ($code) {
switch ($code) {
case 1:
$err_var=_ERR_1;
break;
case 2:
$err_var=_ERR_2;
break;
default:
$err_var=_ERR_99;
break;
}
global $g_template, $g_sitename;
if (!$buffer=file_get_contents("templates/".$g_template."/error.htm")) {
echo _ERR_2;die();
}
$buffer=PageIndexReplace($buffer,$g_sitename);
$buffer=str_replace("{ERR_DESC}",$err_var,$buffer);
echo $buffer;
die(); // ;)
}
function CheckSectionExists($id) {
global $g_dbprefix;
$result=mysql_query("SELECT * FROM ".$g_dbprefix."sections WHERE id=".intval($id));
if (mysql_num_rows($result)==0) {
ErrorPage (1);
}
}
function CheckPageExists($id) {
global $g_dbprefix;
$result=mysql_query("SELECT * FROM ".$g_dbprefix."pages WHERE id=".intval($id));
if (mysql_num_rows($result)==0) {
ErrorPage (1);
}
}
function CheckSectionExistsAdmin($id) {
global $g_dbprefix;
$result=mysql_query("SELECT * FROM ".$g_dbprefix."sections WHERE id=".intval($id));
if (mysql_num_rows($result)==0) {
ErrPage (_ERR_SECTION_NO_EXISTS);
}
}
function CheckCommentExistsAdmin($id) {
global $g_dbprefix;
$result=mysql_query("SELECT * FROM ".$g_dbprefix."comments WHERE id=".intval($id));
if (mysql_num_rows($result)==0) {
ErrPage (_ERR_COMMENT_NO_EXISTS);
}
}
function CheckSmileyExistsAdmin($id) {
global $g_dbprefix;
$result=mysql_query("SELECT * FROM ".$g_dbprefix."smileys WHERE id=".intval($id));
if (mysql_num_rows($result)==0) {
ErrPage (_ERR_SMILEY_NO_EXISTS);
}
}
function CheckPageExistsAdmin($id) {
global $g_dbprefix;
$result=mysql_query("SELECT * FROM ".$g_dbprefix."pages WHERE id=".intval($id));
if (mysql_num_rows($result)==0) {
ErrPage (_ERR_PAGE_NO_EXISTS);
}
}
function ErrPage($var) {
showpage("admin_header");
echo "<br /><br /><b>"._ERR."</b>";
echo "<br /><br />".$var."<br /><br />";
showpage("admin_footer");
die();
}
function CommentReplace($buffer,$comment_flag,$page_id, $ishome) {
if (strpos($buffer,"{COMMENT_START}")===false) {}else{
$aux_buffer=substr($buffer,0,strpos($buffer,"{COMMENT_START}"));
if (strpos($buffer,"{COMMENT_END}")===false) {}else{
$pag_block=substr($buffer,strpos($buffer,"{COMMENT_START}")+strlen("{COMMENT_START}"),strpos($buffer,"{COMMENT_END}")-strpos($buffer,"{COMMENT_START}")-strlen("{COMMENT_START}"));
if ($ishome==1) {
if ($comment_flag==2) {
$minibuffer=CommentReplace2($pag_block,$page_id);
}else{
$minibuffer="";
}
}else{
if ($comment_flag!=0) {
$minibuffer=CommentReplace2($pag_block,$page_id);
}else{
$minibuffer="";
}
}
$minibuffer=str_replace("{PAGE_ID}",$page_id,$minibuffer);
global $g_dbprefix;
$result=mysql_query ("SELECT * FROM ".$g_dbprefix."comments WHERE page_id=".$page_id);
if (mysql_num_rows($result)==1) {
$minibuffer=str_replace("{COMMENTS_NUM}",mysql_num_rows($result)." "._COMMENT,$minibuffer);
}else{
$minibuffer=str_replace("{COMMENTS_NUM}",mysql_num_rows($result)." "._COMMENTS,$minibuffer);
}
return $aux_buffer.$minibuffer.substr($buffer,strpos($buffer,"{COMMENT_END}")+strlen("{COMMENT_END}"));
}
}
return $buffer;
}
function CommentReplace2($buffer,$page_id) {
global $g_dbprefix;
$result=mysql_query ("SELECT * FROM ".$g_dbprefix."comments WHERE page_id=".$page_id." ORDER BY postdate DESC");
if (strpos($buffer,"{COMMENT_BLOCK_START}")===false) {}else{
$aux_buffer=substr($buffer,0,strpos($buffer,"{COMMENT_BLOCK_START}"));
if (strpos($buffer,"{COMMENT_BLOCK_END}")===false) {}else{
$pag_block=substr($buffer,strpos($buffer,"{COMMENT_BLOCK_START}")+strlen("{COMMENT_BLOCK_START}"),strpos($buffer,"{COMMENT_BLOCK_END}")-strpos($buffer,"{COMMENT_BLOCK_START}")-strlen("{COMMENT_BLOCK_START}"));
while ($row=mysql_fetch_array($result)) {
$minibuffer=$minibuffer.$pag_block;
$minibuffer=str_replace("{COMMENT_BLOCK_MAIL}",$row['email'],$minibuffer);
$minibuffer=str_replace("{COMMENT_BLOCK_NAME}",$row['name'],$minibuffer);
$minibuffer=str_replace("{COMMENT_BLOCK_COMMENT}",SmileyReplace($row['comment']),$minibuffer);
$thedate=date("d",$row['postdate'])."-".date("m",$row['postdate'])."-".date("Y",$row['postdate'])." ".date("H",$row['postdate']).":".date("i",$row['postdate']);
$minibuffer=str_replace("{COMMENT_BLOCK_DATE}",$thedate,$minibuffer);
}
}
}
return $aux_buffer.$minibuffer.substr($buffer,strpos($buffer,"{COMMENT_BLOCK_END}")+strlen("{COMMENT_BLOCK_END}"));
}
function add_comment($page_id,$name,$email,$content,$ref) {
global $g_dbprefix;
if ($_SERVER) {
if ( $_SERVER[HTTP_X_FORWARDED_FOR] ) {
$realip = $_SERVER["HTTP_X_FORWARDED_FOR"];
} elseif ( $_SERVER["HTTP_CLIENT_IP"] ) {
$realip = $_SERVER["HTTP_CLIENT_IP"];
} else {
$realip = $_SERVER["REMOTE_ADDR"];
}
} else {
if ( getenv( 'HTTP_X_FORWARDED_FOR' ) ) {
$realip = getenv( 'HTTP_X_FORWARDED_FOR' );
} elseif ( getenv( 'HTTP_CLIENT_IP' ) ) {
$realip = getenv( 'HTTP_CLIENT_IP' );
} else {
$realip = getenv( 'REMOTE_ADDR' );
}
}
$result=mysql_query("INSERT INTO ".$g_dbprefix."comments (page_id,name,email,comment,postdate,ip) VALUES (".$page_id.",'".$name."','".$email."','".$content."',".time().",'".$realip."')");
Header("Location: ". $ref);
}
?>