Library /lib/fields/class.Editor.php

Language PHP Lines 276
MD5 Hash 8e897bee529a9d8ab1be90101beccc53
Repository https://github.com/reshadf/Library.git View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
<?php
/**
 * class Editor
 *
 * Create a Editor on the given form
 *
 * @author Teye Heimans
 * @package FormHandler
 * @subpackage Fields
 * 
 * converted to ckeditor
 * @since 2011-07-04
 * @author Jphan Wiegel @ PHP-GLOBE
 */

class Editor extends Field
{
    var $_oEditor;    // FCKeditor: the object of the fck editor
    
    /**
     * Editor::Editor()
     *
     * Constructor: create a new Editor object
     *
     * @param object $oForm: The form where the field is located on
     * @return Editor
     * @access public
     * @author Teye Heimans
     */
    function Editor( &$oForm, $sName )
    {
    	$this->_oEditor = new ckeditor( $sName );
                
    	$this->_oEditor->returnOutput = true;
    	
        $this->_oEditor->basePath = FH_FHTML_DIR . 'ckeditor/';
        
        // &nbsp; added as workarround IE9
        $this->_oEditor->Value = isset( $this->_mValue ) ? $this->_mValue : '';
        $this->setToolbar( 'Default' ); // Default or Basic

        $this->setServerPath( '' );

		parent::Field( $oForm, $sName );

        // set the language
        $this->_oEditor->config['language']  = str_replace('-utf8', '', $oForm->_lang);        

		// default height & width
        $this->setWidth ( 720 );
        $this->setHeight( 400 );

        // default, silver or office2003
        $this->setSkin( 'v2' );
    }

    /**
     * Editor::setHeight()
     *
     * Set the height of the editor (in pixels!)
     *
     * @param integer $iHeight: the height
     * @return void
     * @access public
     * @author Teye Heimans
     */
    function setHeight( $iHeight )
    {
        $this->_oEditor->config['height'] = $iHeight;
    }

    /**
     * Editor::setValue()
     *
     * Set the value of the field
     *
     * @param string $sValue: The html to set into the field
     * @return void
     * @access public
     * @author Teye Heimans
     */
    function setValue( $sValue )
    {
    	$this->_mValue = $sValue;
    	$this->_oEditor->Value = $sValue;
    }

    /**
     * Editor::setWidth()
     *
     * Set the width of the editor  (in pixels!)
     *
     * @param integer $iWidth: the width
     * @return void
     * @access public
     * @author Teye Heimans
     */
    function setWidth( $iWidth)
    {
        $this->_oEditor->config['width'] = $iWidth;
    }

    /**
     * Editor::setToolbar()
     *
     * Set the toolbar we should use for the editor
     *
     * @param string $sToolbar: The toolbar we should use
     * @return void
     * @access public
     * @author Teye Heimans
     */
    function setToolbar( $sToolbar )
    {
        $this->_oEditor->config['toolbar'] = $sToolbar;
    }


    /**
     * Editor::setConfig()
     *
     * Set extra config options for the editor
     *
     * @param array $config: The config array with extra config options to set for the fckeditor
     * @return void
     * @access public
     * @author Teye Heimans
     */
    function setConfig( $config )
    {
        $this->_oEditor->config = array_merge( $this->_oEditor->config, $config );
    }

    /**
     * Editor::setServerPath()
     *
     * Set the server path used for browsing and uploading images
     *
     * @param string $sPath: The path
     * @return void
     * @access public
     * @author Teye Heimans
     */
    function setServerPath( $sPath )
    {
        if( $sPath === false )
        {
            $this->_oEditor->Config['LinkBrowser']  = false;
            $this->_oEditor->Config['ImageBrowser'] = false;
            $this->_oEditor->Config['FlashBrowser'] = false;
            return;
        }

    	// get the dir where the script is located in
    	$sSelfPath = $_SERVER['PHP_SELF'] ;
	    $sSelfPath = substr( $sSelfPath, 0, strrpos( $sSelfPath, '/' ) ) ;

	    // get the dir where the user want's to upload the dir in
	    $sPath = $this->_getServerPath( $sPath, $sSelfPath );
        // path (URL) to the FCKeditor...
        $char = substr(FH_FHTML_DIR, 0, 1);
        $pre  = ($char != '/' && $char != '\\' && strtolower(substr(FH_FHTML_DIR, 0, 4)) != 'http') ? str_replace('//', '/', dirname( $_SERVER['PHP_SELF'] ).'/') : '';

        $sURL =
          $pre . FH_FHTML_DIR .
          'filemanager/browser/default/browser.html?'.
          'Type=%s&Connector=../../connectors/php/connector.php?ServerPath='.$sPath
        ;

        $this->_oEditor->config['filebrowserImageBrowseUrl'] = ( sprintf( $sURL, 'Image', $sPath ) );
        $this->_oEditor->config['filebrowserBrowseUrl']  = ( sprintf( $sURL, 'File', $sPath ) );
        $this->_oEditor->config['filebrowserFlashBrowseUrl'] = ( sprintf( $sURL, 'Flash', $sPath ) );
    }


    /**
     * Editor::setSkin()
     *
     * Set the skin used for the FCKeditor
     *
     * @param string $skin
     * @return void
     * @access public
     * @author Teye Heimans
     */
    function setSkin( $sSkin )
    {
        $this->_oEditor->config['skin'] = $sSkin;
    }


    /**
     * Editor::getField()
     *
     * Return the HTML of the field
     *
     * @return string: The HTML of the editor
     * @access public
     * @author Teye Heimans
     */
    function getField()
    {
        // view mode enabled ?
        if( $this -> getViewMode() )
        {
            // get the view value..
            return $this -> _getViewValue();
        }
		/*@var _oEditor CKEditor*/
            
        return $this->_oEditor->editor( $this->_sName, $this->_oEditor->Value ).
        (isset($this->_sExtraAfter) ? $this->_sExtraAfter :'');
    }

    /**
     * Editor::_getServerPath()
     *
     * Get the dir which should be used for browsing...
     *
     * @param string $sDir: The dir given by the user
     * @param string $sServerPath: The dir where the script is located on the server
     * @return void
     * @access private
     * @author Teye Heimans
     */
    function _getServerPath( $sDir, $sServerPath )
    {
    	// remove ending slash at the server path
    	if( substr($sServerPath, -1) == '/' )
    	{
			$sServerPath = substr( $sServerPath, 0, -1);
		}
		// when no dir is given, just return the path where the script is located
		if( $sDir == '' )
		{
			return $sServerPath;
		}

		// dir starting with a /? Then start at the root...
		if( $sDir{0} == '/' )
		{
			return $sDir;
		}
		// dir starting with ./? Then relative from the dir where the script is located
		else if( substr( $sDir, 0, 2) == './' )
		{
			return $sServerPath.'/'.substr($sDir, 2);
		}
		// if we are at the root of the server, return the dir..
		else if( $sServerPath == '/' || $sServerPath == '')
		{
			if( $sDir{0} != '.' && $sDir{0} != '/' )
			{
				 $sDir = '/'.$sDir;
			}
			return $sDir;
		}
		// go a dir lower...
		else if( substr($sDir, 0, 3) == '../' )
		{
    		$sServerPath = substr($sServerPath, 0, -strlen( strrchr($sServerPath, "/") ));

    		return $this->_getServerPath( substr($sDir, 3), $sServerPath);
    	}
    	// none of the above, then return the dir!
    	else
    	{
    		if( $sDir{0} == '/' )
    		{
    			$sDir = substr( $sDir, 1);
    		}
    		return $sServerPath.'/'.$sDir;
    	}
    }
}
?>
Back to Top