@@ -18,17 +18,10 @@
* @version $Id$
* @license http://opensource.org/licenses/gpl-license.php GNU Public License, version 2
*/
class tx_fbmagento_interface {
class tx_fbmagento_interface implements t3lib_Singleton {

/**
* Singleton instance
*
* @var tx_fbmagento_interface
*/
protected static $_instance = null;

/**
* already dispatched?
* allready dispatched?
*
* @var boolean
*/
@@ -45,47 +38,13 @@ class tx_fbmagento_interface {
* enable or disable debug Mode
*/
public $debug = true;

/**
* Singleton pattern implementation makes "new" unavailable
*
* @return void
*/
private function __construct() {
}

/**
* Singleton pattern implementation makes "clone" unavailable
*
* @return void
*/
private function __clone() {
}

/**
* Returns an instance of tx_fbmagento_interface
*
* Singleton pattern implementation
*
* @param array emConf
* @return tx_fbmagento_interface Provides a fluent interface
*/
public static function getInstance(array $config) {
if (null === self::$_instance) {
self::$_instance = new self();
self::$_instance->init($config);
}

return self::$_instance;
}


/**
* init Interface
*
* constructor for tx_fbmagento_interface
*
* @param array emConf
*/
public function init($config) {

public function __construct($config) {
// init Config Array
$this->config = $config;

@@ -95,13 +54,7 @@ public function init($config) {
}

// disable Notices
error_reporting(E_ALL & ~ E_NOTICE);

// overwrite Magento Autoload Function
if (class_exists('Varien_Autoload', false)) {
spl_autoload_unregister(array(Varien_Autoload::instance(), 'autoload'));
}
spl_autoload_register(array(&$this, 'autoload'));
error_reporting ( E_ALL & ~ E_NOTICE );

// Init Mage
$store = tx_fbmagento_tools::getFELangStoreCode();
@@ -208,110 +161,6 @@ public function getHeaderData() {
public function getBodyData(){
return $this->connector->getResponse()->outputBody(true);
}


/**
* generate a duplicate of a Class with an other Name
* Mage_Core_Model_App -> Flagbit_Typo3connect_Rewrite_Core_Model_App
*
* @param string $className
* @return string
*/
protected function rewriteClass($className) {

// cache Path
$cachePath = $this->config['path'] . 'var/cache/';

// get Filename from Classname
$fileName = $this->_getClassPath($className);

// generate a new Version of Classfile (if not already exist)
if (!file_exists($cachePath.$fileName)) {

// get source of the original Class
$content = file_get_contents($this->config['path'] . 'app/code/core/' . uc_words($className, DS) . '.php');

// change Classname
$content = preg_replace('/class(.*)' . $className . '/iU', 'class\1Flagbit_Typo3connect_Rewrite_' . $className, $content);

// write new Class
$classPath = substr($fileName, 0, strrpos($fileName, '/') + 1);

t3lib_div::mkdir_deep($cachePath, substr($fileName, 0, strrpos($fileName, '/') + 1));
t3lib_div::writeFile($cachePath . $fileName, $content);
}

return $cachePath . $fileName;
}

/**
* get absolute class path by class name
*
* @param string $className
* @retirn string
*/
protected function _getClassPath($className) {

$fileName = $this->_getFilename($className);

if (substr($fileName, 1, 1) != '/') {
$includePaths = explode(':', get_include_path());
foreach($includePaths as $includePath){
if($includePath == '.'){
$includePath = rtrim($this->config['path'], '/');
}
if(file_exists($includePath . '/' . $fileName)){
return $includePath . '/' . $fileName;
}
}
}
}

/**
* get the Filename of a Class
*
* @param string $className
* @return string
*/
protected function _getFilename($className) {
$filename = uc_words($className, DS) . '.php';
return $filename;
}

/**
* Class autoload
*
* @todo change to spl_autoload_register
* @param string $class
*/
public function autoload($class) {

if (strpos($class, DS) !== false) {
return;
}

// do some dirty Class reflection because of Mages unrewriteable Classes
$filename = $this->_getFilename($class);
$rewritePath = $this->config['path'] . 'app/code/' . $this->config['namespace'] . '/Flagbit/Typo3connect/Rewrites/' . $filename;

if (file_exists($rewritePath)
&& $filename != '.php' && $filename) {

$newClassFile = $this->rewriteClass($class);
include($newClassFile);

include($rewritePath);
return;
}

$classFile = uc_words($class, DS) . '.php';

try {
@include ($classFile);
} catch (Exception $m) {
// no output since TYPO3 Classes will also be loaded throw autoload
}
}
}

if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/fb_magento/lib/class.tx_fbmagento_interface.php']) {
@@ -158,7 +158,7 @@ public function categories($content, $conf) {

$this->emConf = tx_fbmagento_tools::getExtConfig();
$this->conf = $conf;
$mage = tx_fbmagento_interface::getInstance($this->emConf);
$this->mage = t3lib_div::makeInstance('tx_fbmagento_interface', $this->emConf );

$categories = $this->getStoreCategories($this->conf['startcategory']);

@@ -239,4 +239,4 @@ protected function _parseNodes($nodes) {
include_once ($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/fb_magento/lib/class.tx_fbmagento_navigation.php']);
}

?>
?>
@@ -105,7 +105,7 @@ public function call($resource, $params=array()) {
* @return tx_fbmagento_cache
*/
protected function getCache(){
return tx_fbmagento_cache::getInstance($this->cache);
return t3lib_div::makeInstance('tx_fbmagento_cache', $this->cache);
}

/**
@@ -123,4 +123,4 @@ public function getClient(){
include_once ($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/fb_magento/lib/class.tx_fbmagento_soapinterface.php']);
}

?>
?>
@@ -59,9 +59,15 @@ function main() {

// get Extension Config
$this->emConf = tx_fbmagento_tools::getExtConfig();
<<<<<<< HEAD

// get some Magento Instance
$this->mage = tx_fbmagento_interface::getInstance($this->emConf);
=======

// get an Magento Instance
$this->mage = t3lib_div::makeInstance('tx_fbmagento_interface', $this->emConf );
>>>>>>> bugfix_typo3_update_4_5_4

/*@var $mageUser Mage_Admin_Model_User */
$mageUser = Mage::getSingleton('admin/user');
@@ -102,8 +102,8 @@ public function main($content, $conf) {

}

// get some Magento Instance
$this->mage = tx_fbmagento_interface::getInstance($this->emConf);
// get an Magento Instance
$this->mage = t3lib_div::makeInstance('tx_fbmagento_interface', $this->emConf );
$this->mage->setTsConfig($GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_fbmagento_pi1.']);

$this->mage->dispatch($params);
@@ -168,7 +168,6 @@ public function main($content, $conf) {
* @return boolean
*/
protected function getRoutingDataFromPage() {

$rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
'pi_flexform',
'tt_content',