<?php
/*
 * This file is part of the easy-CMS project.
 * easy-CMS 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.
 * 
 * easy-CMS 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 easy-CMS; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

/**
 * CoreObject
 *
 * @package Core
 */
 
/**
 */
include_once('classes/debug/Debug.class.php');


/**
* Parent class for easy-CMS objects (holds a debug instance).
*
* @access   public
* @author	Cedric Francoys <cedric.francoys@easy-cms.org>
* @version	CoreObject.class, Sun Nov 14 16:52:42 CET 2004
* @package	Core
*/
class CoreObject {

  var $class_name;
  
  function CoreObject() {
  }

  function setClassName($class_name) {
    $this->class_name = $class_name;
  }
  
  function getClassName() {
    return $this->class_name;
  }
  
  function debug($text, $level = 0, $recurse = DBG_NONE) {
		$debug = &Debug::getInstance();
		$debug->report($text, $level, $recurse);
  }

	function is_html_encoded($string) {
		$this->debug('CoreObject::is_html_encoded, status : function invoked', 10, DBG_OPEN);
    $result = false;
    $temp_string = substr($string, 0, 1024);
		$htmlSpecialCharsTable = array('<br>', '<br />', '<b>', '<i>', '<u>', '<div>', '<span>', '&#156;','&#159;','&#192;','&#193;','&#194;','&#195;','&#196;','&#197;','&#198;','&#199;','&#200;','&#201;','&#202;','&#203;','&#204;','&#205;','&#206;','&#207;','&#209;','&#210;','&#211;','&#212;','&#213;','&#214;','&#216;','&#217;','&#218;','&#219;','&#220;','&#223;','&#224;','&#225;','&#226;','&#227;','&#228;','&#229;','&#230;','&#231;','&#232;','&#233;','&#234;','&#235;','&#236;','&#237;','&#238;','&#239;','&#241;','&#242;','&#243;','&#244;','&#245;','&#246;','&#248;','&#249;','&#250;','&#251;','&#252;','&#255;','&#260;','&#261;','&#262;','&#263;','&#280;','&#281;','&#321;','&#322;','&#323;','&#324;','&#338;','&#346;','&#347;','&#377;','&#378;','&#379;','&#380;','&Agrave;','&Aacute;','&Acirc;','&Atilde;','&Auml;','&Aring;','&Aelig;','&Ccedil;','&Egrave;','&Eacute;','&Ecirc;','&Euml;','&Igrave;','&Iacute;','&Icirc;','&Iuml;','&Ntilde;','&Ograve;','&Oacute;','&Ocirc;','&Otilde;','&Ouml;','&Oslash;','&Ugrave;','&Uacute;','&Ucirc;','&Uuml;','&szlig;','&agrave;','&aacute;','&acirc;','&atilde;','&auml;','&aring;','&aelig;','&ccedil;','&egrave;','&eacute;','&ecirc;','&euml;','&igrave;','&iacute;','&icirc;','&iuml;','&ntilde;','&ograve;','&oacute;','&ocirc;','&otilde;','&ouml;','&oslash;','&ugrave;','&uacute;','&ucirc;','&uuml;','&yuml;');
		for($i = 0; $i < count($htmlSpecialCharsTable); ++$i) {
		  $clue = $htmlSpecialCharsTable[$i];
			if(stristr($temp_string, $clue)) {
				$result = true;
				break;
			}
		}
		$this->debug('CoreObject::is_html_encoded, status : function completed ('.$result.')', 10, DBG_CLOSE);
		return $result;
	}

	function html_encode($string, $checkHTML=true) {
		$this->debug('CoreObject::html_encode, status : function invoked', 10, DBG_OPEN);
    $result = $string;
		if($checkHTML && !$this->is_html_encoded($string)) {
			$string = htmlentities($string, ENT_QUOTES, "UTF-8");
		}
		$this->debug('CoreObject::html_encode, status : function completed', 10, DBG_CLOSE);
		return $string;
	}

} 
?>