Location: PHPKode > projects > Jarida > jarida_1.0/include/common.php
<?php

function replaceSmilies($text, $db)
{
  $query = "SELECT smilie_id FROM tblSmilie";

  $result = $db->doQuery($query);

  while($row = $result->getArray())
    {
      $smilie = new Smilie($db, $row['smilie_id']);
      $text = str_replace($smilie->getCode(),"<img src=\"img/" . $smilie->getFile() . "\" alt=\"\" />",$text);
    }
  return($text);

}


function replaceBadWords($text, &$db)
{
  $query = "SELECT censor_id FROM tblCensor";

  $result = $db->doQuery($query);

  while($row = $result->getArray())
    {
      $censor = new Censor($db, $row['censor_id']);
      $text = str_replace($censor->getWord(),$censor->getReplace(),$text);
    }
  return($text);

}





function add_img($location)
{
  $file_uploaded = $_FILES['file'];

  //Create an array of accepted image files
  $img_types = array('image/pjpeg' => 'jpg',
		       'image/jpeg' => 'jpg',
		       'image/gif' => 'gif',
		       'image/bmp' => 'bmp',
		       'image/x-png' => 'png',
		       'image/png' => 'png');

  //Filter the images using the above created array
  if($file_uploaded['size'] > 0) 
    {
      if(!array_key_exists($file_uploaded['type'], $img_types)) 
	{
	  $filename = false;
	} 
      else 
	{
	  //The file is an image, proceed....
	  $filetype = $file_uploaded['type'];
	  $extension = $img_types[$filetype];
	  $filename = time() . ".$extension";
	  copy($file_uploaded['tmp_name'], $location . $filename);
	}
    }
  return $filename;
}


//Thanks to Greg Knox from Sitepoint.com
function imageResize($width, $height, $target)
{

  if($width > $height)
    {
      $ratio = ($target / $width);
    }
  else
    {
      $ratio = ($target / $height);
    }

  $new_width = round($width * $ratio);
  $new_height = round($height * $ratio);

  $dimensions = array('width' => $new_width,
		      'height' => $new_height);

  return $dimensions; 

}


function authenticate($pass, &$db)
{
  $query = "SELECT config_value FROM tblConfig WHERE config_value = '$pass'";
  $result = $db->doQuery($query);
  echo $db->getError();
  if($result->getNumRows() > 0)
    {
      return true;
    }
  else
    {
      return false;
    }
}

?>
Return current item: Jarida