<?php

load_plugin_textdomain('xpressme', 'wp-content/plugins/xpressme/language');

class XPressME_Class{
	var $pluginName = 'xpressme';	
	var $is_use_xoops_upload_path;
	
	//constructor
	function wp_fckeditor()
	{
		$this->setdefault();    //not setting propaty load
		$this->SettingValueRead();
	}


	function add_option_page()
	{
		add_options_page('XPressME', __('XPressME Settings', 'xpressme'), 8, 'xpressme_config', array(&$this, 'option_page'));
//		add_submenu_page('post.php', 'FCKEditor','FCKEditor',1, 'xpress_fckeditor', array(&$this, 'option_page'));
	}
	
	function add_admin_head()
	{ 
		// add header text
	}

	
		//Set Default Value	
	function setDefault()
	{
		$this->is_use_xoops_upload_path = true;
	}
	
	function SettingValueRead()
	{
		$options = get_option('xpressme_option');

		if (!$options) {
			$this->setDefault();
			$this->SettingValueWrite('add_new');
		} else {
			foreach ($options as $option_name => $option_value){
	        		$this-> {$option_name} = $option_value;
			}
			$this->build_smiley_images($this->fck_SmileyPath,$this->fck_SmileyName);
		}

	}
	
		// mode 0:add  1:update	
	function SettingValueWrite($mode)
	{
		$write_options = array (
			'is_use_xoops_upload_path' => $this->is_use_xoops_upload_path 
		);
		if ($mode == 'add_new') {
			add_option('xpressme_option', $write_options);
		} else {			
			update_option("xpressme_option", $write_options);
		}
	}
		
	function option_page()
	{
		echo '<div class="wrap">';
		echo '<div id="icon-options-general" class="icon32"><br /></div>';
		echo '<h2>' . __('XPressME Configuration Page', 'xpressme') . '</h2> ';

		echo '<form method="post" action="options.php">';
		echo '<table class="form-table">';

		$this->is_use_xoops_upload_path_html();
		echo '</table>';
		echo '</div>';

	}

	function is_use_xoops_upload_path_html()
	{
		
		echo '<tr>';
		echo '<th><label for="images_to_link">' . __('Media Upload Base Path','xpressme') . '</label></th>';
		echo '<td>';

//		if ($this->is_use_xoops_upload_path == true){
  			echo '<label><input type="radio" name="ch_is_use_xoops_upload_path"  value="1" checked="checked" /> ' . __('Use XOOPS UPLOAD PATH','xpressme') .'</label><br />';
  			echo '<label><input type="radio" name="ch_is_use_xoops_upload_path" value="0" />' . __('USE WordPress BASE_PATH','xpressme') . '</label>';
		echo '</td>';
		echo '</tr><tr>';
		
	}

	
	function xpress_upload_filter($uploads)
	{
		if ($this->is_use_xoops_upload_path){
			if (!defined("XOOPS_UPLOAD_PATH"))
				define("XOOPS_UPLOAD_PATH", XOOPS_ROOT_PATH."/uploads");
			if (!defined("XOOPS_UPLOAD_URL"))
				define("XOOPS_UPLOAD_URL", XOOPS_URL."/uploads");

			$wordpress_dir = ABSPATH ;
			$xoops_dir = XOOPS_UPLOAD_PATH . '/';
			$wordpress_base_url = get_option( 'siteurl' );
			$xoops_upload_url = XOOPS_UPLOAD_URL;
			
			$uploads[path] =  str_replace ($wordpress_dir, $xoops_dir, $uploads[path]);
			$uploads[basedir] = str_replace ($wordpress_dir, $xoops_dir, $uploads[basedir]);
			$uploads[url] = str_replace ($wordpress_base_url, $xoops_upload_url, $uploads[url]);
			$uploads[baseurl] = str_replace ($wordpress_base_url, $xoops_upload_url, $uploads[baseurl]);
		}
		return $uploads;
	}	
}
?>