Location: PHPKode > projects > WSN Guest > wsn-guest/admin/admincommonfuncs.php
<?php

function integrationoptions($selected)
{ 
 $integrationscripts = ", vbulletin, invision, phpbb, wsnlinks, wsnguest";
 $integrationscripttitles = "None, vBulletin 3.00, Invision Board, phpBB2, WSN Links, WSN Guest";
 $arr = explode(', ', $integrationscripts);
 $arrt = explode(', ', $integrationscripttitles);
 $num = sizeof($arr);
 for ($x=0; $x<$num; $x++)
 {
  if ($arr[$x] == $selected) $options .= '<option value="'. $arr[$x] .'" selected>'. $arrt[$x] .'</option>';
  else $options .= '<option value="'. $arr[$x] .'">'. $arrt[$x] .'</option>';
 }
 return $options;
}

function filewrite($filename, $data)
{
// supply a file name and I'll write your data to it
 $fd = fopen($filename, 'w');
 $check = fwrite ($fd, $data);
 fclose ($fd);
 return $check;
}

function fileappend($filename, $data)
{
// supply a file name and I'll append your data to the end of it
 $fd = fopen($filename, 'a');
 $check = fwrite ($fd, $data);
 fclose ($fd);
 return $check;
}

function encodesqlline($sqltext)
{
 $sqltext = str_replace('&lt;', '&lt&', $sqltext);
 $sqltext = str_replace('&gt;', '&gt&', $sqltext);
 $sqltext = str_replace('&#59;', '&#59&', $sqltext);
 $sqltext = str_replace('&#125;', '&#125&', $sqltext);
 $sqltext = str_replace('&#123;', '&#123&', $sqltext);
 $sqltext = str_replace('&quot;', '&quot&', $sqltext);  
 $sqltext = str_replace('&amp;', '&amp&', $sqltext);
 $sqltext = str_replace('&#39;', '&#39&', $sqltext);
 $sqltext = str_replace('&#34;', '&#34&', $sqltext);
 $sqltext = str_replace('&#8242;', '&#8242&', $sqltext);
 $sqltext = str_replace(';', '{semicolon}', $sqltext);
 return $sqltext;
}


function decodesqlline($sqltext)
{
 $sqltext = str_replace('&lt&', '&lt;', $sqltext);
 $sqltext = str_replace( '&gt&', '&gt;', $sqltext);
 $sqltext = str_replace('&#59&', '&#59;', $sqltext);
 $sqltext = str_replace('&#125&', '&#125;', $sqltext);
 $sqltext = str_replace('&#123&', '&#123;', $sqltext);
 $sqltext = str_replace('&quot&', '&quot;', $sqltext);  
 $sqltext = str_replace('&amp&', '&amp;', $sqltext);
 $sqltext = str_replace('&#39&', '&#39;', $sqltext);
 $sqltext = str_replace('&#34&', '&#34;', $sqltext);
 $sqltext = str_replace('&#8242&', '&#8242;', $sqltext);
 $sqltext = str_replace('{semicolon}', ';', $sqltext);
 return $sqltext;
}

function encodesql($sqltext)
{
 $sqltext = str_replace('&lt;', '&lt&', $sqltext);
 $sqltext = str_replace('&gt;', '&gt&', $sqltext);
 $sqltext = str_replace('&#59;', '&#59&', $sqltext);
 $sqltext = str_replace('&#125;', '&#125&', $sqltext);
 $sqltext = str_replace('&#123;', '&#123&', $sqltext);
 $sqltext = str_replace('&quot;', '&quot&', $sqltext);  
 $sqltext = str_replace('&amp;', '&amp&', $sqltext);
 $sqltext = str_replace('&#39;', '&#39&', $sqltext);
 $sqltext = str_replace('&#34;', '&#34&', $sqltext);
 $sqltext = str_replace('&#8242;', '&#8242&', $sqltext);
 return $sqltext;
}

function processsql($sqltext)
{
 global $db, $prefix;
 $sqltext = str_replace('{PREFIX}', $prefix, $sqltext);
 $sqlarray = explode(';', $sqltext);
 $num = sizeof($sqlarray);
 for ($count=0; $count<($num-1); $count++)
 {
  $sqlarray[$count] = str_replace('&lt&', '&lt;', $sqlarray[$count]);
  $sqlarray[$count] = str_replace('&gt&', '&gt;', $sqlarray[$count]);
  $sqlarray[$count] = str_replace('&#59&', '&#59;', $sqlarray[$count]);
  $sqlarray[$count] = str_replace('&#125&', '&#125;', $sqlarray[$count]);
  $sqlarray[$count] = str_replace('&#123&', '&#123;', $sqlarray[$count]);
  $sqlarray[$count] = str_replace('&quot&', '&quot;', $sqlarray[$count]);  
  $sqlarray[$count] = str_replace('&amp&', '&amp;', $sqlarray[$count]);
  $sqlarray[$count] = str_replace('&#39&', '&#39;', $sqlarray[$count]);
  $sqlarray[$count] = str_replace('&#34&', '&#34;', $sqlarray[$count]);
  $sqlarray[$count] = str_replace('&#8242&', '&#8242;', $sqlarray[$count]);
  $sqlarray[$count] = str_replace('{semicolon}', ';', $sqlarray[$count]);
  $sqlarray[$count] = stripslashes($sqlarray[$count]);
  $db->query($sqlarray[$count]);
 }
 return mysql_error();
}

function getunvallinks()
{
 global $db, $settings;
 $doit = $db->select($settings->linkfields, 'linkstable', 'validated=0', 'ORDER BY id ASC', '');
 return $doit;
}

function getunvalcats()
{
 global $db, $settings;
 $doit = $db->select($settings->categoryfields, 'categoriestable', 'validated=0', 'ORDER BY id ASC', '');
 return $doit;
}

function geturl($url)
{
 $fd = @fopen($url, 'rb');
 $filecontents = @fread ($fd, 300000);
 @fclose ($fd);
 return $filecontents;
}

function emailmembervalidation($thismem)
{
 global $language, $settings;
 $adminaddress = $settings->email;
 $submitter = $thismem->email;
 $subject = $language->email_validatemembertitle;
 $message = $language->email_validatememberbody;
 $message = memberreplacements($message, $thismem);   
 $message = str_replace('{DIRURL}', $settings->dirurl, $message);
 $message = decodeit($message);
 sendemail("$submitter", "$subject", "$message", "From: $adminaddress");
}


function fieldselector($type, $selected)
{
 global $settings;
 $selected = ' '. str_replace(',', ' ', $selected) . ' ';
 $fields = explode(',', $settings->$type);
 $num = sizeof($fields);
 for ($x=0; $x<$num; $x++)
 {
  if (strstr($selected, ' '. $fields[$x] .' ')) $stuff .= '<option value="'. $fields[$x] .'" selected>'. $fields[$x] .'</option>'; 
  else $stuff .= '<option value="'. $fields[$x] .'">'. $fields[$x] .'</option>';
 }
 return $stuff;
}


function languageupload($filename, $groupid)
{
 global $db;
 $text = fileread($filename);
 if (stristr($text, 'INSERT INTO {PREFIX}')) 
 { // maintain backwards compatability with 2.3x language sets
    $text = str_replace('{GROUPNAME}', $groupid, $text);
    $subresult = processsql($text);
	if ($subresult != '') { echo $subresult; $result = false; }
	else $result = true;
 }
 else
 {
  $thestuff = explode('|||END LINE|||', $text);
  $num = sizeof($thestuff);
  for ($c=0; $c<$num; $c++)
  {
   $line = explode('|||DIVIDER|||', $thestuff[$c]);
   $name = decodesqlline($line[0]);
   $value = @decodesqlline($line[1]);
   if ($name != '') $result = $db->insert('languagetable', 'id,name,value,groupid', "'', '$name', '$value', '$groupid'");
  }
 }
 return $result;
}


function languageappend($filename, $groupid)
{
 global $db, $itemsadded, $debug;
 // This function adds language only where the item name doesn't already exist in the set
 $testlang = new language($groupid);
 $oldlangnames = $testlang->allnames();
 $text = fileread($filename);
 if (stristr($text, 'INSERT INTO {PREFIX}')) 
 { // maintain backwards compatability with 2.3x language sets
  echo "Cannot append using 2.3x style language -- it would duplicate existing data. Please use a 2.4+ language file.";
  $result = false;
 }
 else
 {
  $thestuff = explode('|||END LINE|||', $text);
  $num = sizeof($thestuff);
  for ($c=0; $c<$num; $c++)
  {
   $line = explode('|||DIVIDER|||', $thestuff[$c]);
   $name = decodesqlline($line[0]);
   $value = decodesqlline($line[1]);
   if (($name != '') && (!stristr($oldlangnames, $name)))
   {
    $result = $db->insert('languagetable', 'id,name,value,groupid', "'', '$name', '$value', '$groupid'");
    if ($debug == 1) echo "$name was not found so its being inserted. <br>";
    $itemsadded .= '|||'. $name .'|||';
   }
  }
 }
 return $result;
}


function languageoverwrite($filename, $groupid)
{
 global $db, $itemsadded, $debug;
 $result = true;
 /* This function writes the contents of the file to the language, overwriting existing values, but leaves anything not specified in the file alone. Useful for spelling corrections, etc. */
 $testlang = new language($groupid);
 $oldlangnames = $testlang->allnames();

 $text = fileread($filename);
 if (stristr($text, 'INSERT INTO {PREFIX}')) 
 { // maintain backwards compatability with 2.3x language sets
  echo "Cannot overwrite using 2.3x style language -- it would duplicate existing data. Please use a 2.4+ language file.";
  $result = false;
 }
 else
 {
  $thestuff = explode('|||END LINE|||', $text);
  $num = sizeof($thestuff);
  for ($c=0; $c<$num; $c++)
  {
   $line = explode('|||DIVIDER|||', $thestuff[$c]);
   $name = encodesqlline($line[0]);
   $value = encodesqlline($line[1]);
   if (($name != '') && stristr($oldlangnames, $name))
   {
    $test = $db->update('languagetable', "value", "'$value'", "name='$name' AND groupid='$groupid'");
    if ($debug == 1) echo "updated $name to $value <br>";
    $itemsadded .= '|||'. $name .'|||';
   }
  }
 }
 return $result;
}


function admindownload($content, $filename)
{
 header("Pragma: public");
 switch (extension($filename))
 {
 case 'zip':
 header("Content-type: application/zip");
 break;

 case 'gif':
 header("Content-type: image/gif");
 break;

 case 'png':
 header("Content-type: image/png");
 break;

 case 'jpeg':
 case 'jpg':
 header("Content-type: image/jpeg");
 break;
 
 case 'bmp':
 header("Content-type: image/x-xbitmap");
 break;

 case 'swf':
 header("Content-type:  application/x-shockwave-flash");
 break;
 }
 // It will be called by the file title (say, x.zip), even though saved as something else (random id by default)
 header("Content-Disposition: attachment; filename=$filename");
 // The real source 
 echo $content;
 die(""); // stop processing so we don't get the current page stuck in the file
}

function extractphp($phpDocument)
{
 $questMark = "?";
 $phpOpenTag = "<${questMark}php";
 $phpCloseTag = "${questMark}>";
 return ("$phpCloseTag" . stripslashes($phpDocument) . "$phpOpenTag ");
}




?>
Return current item: WSN Guest