diff --git a/main/inc/lib/fckeditor/fckeditor.php b/main/inc/lib/fckeditor/fckeditor.php index 3ca3f8e305..2318029c4d 100644 --- a/main/inc/lib/fckeditor/fckeditor.php +++ b/main/inc/lib/fckeditor/fckeditor.php @@ -19,13 +19,503 @@ * * == END LICENSE == * - * This is the integration file for PHP (All versions). + * This is the integration file for PHP 5. * - * It loads the correct integration file based on the PHP version (avoiding - * strict error messages with PHP 5). + * It defines the FCKeditor class that can be used to create editor + * instances in PHP pages on server side. */ -if ( !function_exists('version_compare') || version_compare( phpversion(), '5', '<' ) ) - include_once( 'fckeditor_php4.php' ) ; -else - include_once( 'fckeditor_php5.php' ) ; +// Code to adapt the editor to the Dokeos LMS has been added by Ivan Tcholakov, FEB-2009. + +/** + * Check if browser is compatible with FCKeditor. + * Return true if is compatible. + * + * @return boolean + */ +function FCKeditor_IsCompatibleBrowser() +{ + if ( isset( $_SERVER ) ) { + $sAgent = $_SERVER['HTTP_USER_AGENT'] ; + } + else { + global $HTTP_SERVER_VARS ; + if ( isset( $HTTP_SERVER_VARS ) ) { + $sAgent = $HTTP_SERVER_VARS['HTTP_USER_AGENT'] ; + } + else { + global $HTTP_USER_AGENT ; + $sAgent = $HTTP_USER_AGENT ; + } + } + + if ( strpos($sAgent, 'MSIE') !== false && strpos($sAgent, 'mac') === false && strpos($sAgent, 'Opera') === false ) + { + $iVersion = (float)substr($sAgent, strpos($sAgent, 'MSIE') + 5, 3) ; + return ($iVersion >= 5.5) ; + } + else if ( strpos($sAgent, 'Gecko/') !== false ) + { + $iVersion = (int)substr($sAgent, strpos($sAgent, 'Gecko/') + 6, 8) ; + return ($iVersion >= 20030210) ; + } + else if ( strpos($sAgent, 'Opera/') !== false ) + { + $fVersion = (float)substr($sAgent, strpos($sAgent, 'Opera/') + 6, 4) ; + return ($fVersion >= 9.5) ; + } + else if ( preg_match( "|AppleWebKit/(\d+)|i", $sAgent, $matches ) ) + { + $iVersion = $matches[1] ; + return ( $matches[1] >= 522 ) ; + } + else + return false ; +} + +class FCKeditor +{ + /** + * Name of the FCKeditor instance. + * + * @access protected + * @var string + */ + public $InstanceName ; + /** + * Path to FCKeditor relative to the document root. + * + * @var string + */ + public $BasePath ; + /** + * Width of the FCKeditor. + * Examples: 100%, 600 + * + * @var mixed + */ + public $Width ; + /** + * Height of the FCKeditor. + * Examples: 400, 50% + * + * @var mixed + */ + public $Height ; + /** + * Name of the toolbar to load. + * + * @var string + */ + public $ToolbarSet ; + /** + * Initial value. + * + * @var string + */ + public $Value ; + /** + * This is where additional configuration can be passed. + * Example: + * $oFCKeditor->Config['EnterMode'] = 'br'; + * + * @var array + */ + public $Config ; + + /** + * Main Constructor. + * Refer to the _samples/php directory for examples. + * + * @param string $instanceName + */ + public function __construct( $instanceName ) + { + $this->InstanceName = $instanceName ; + $this->BasePath = '/fckeditor/' ; + $this->Width = '100%' ; + $this->Height = '200' ; + $this->ToolbarSet = 'Default' ; + $this->Value = '' ; + + $this->Config = array() ; + } + + /** + * Display FCKeditor. + * + */ + public function Create($called_by_formvalidator = false) + { + echo $this->CreateHtml($called_by_formvalidator) ; + } + + /** + * Return the HTML code required to run FCKeditor. + * + * @return string + */ + public function CreateHtml($called_by_formvalidator = false) + { + // Adaptation for the Dokeos LMS. + + // Default configuration settings will be calculated when the editor + // is (still) created directly, without using the formvalidator module. + // These default settings might not cover all possible cases. + + if (!$called_by_formvalidator) + { + global $language_interface; + + $this->BasePath = api_get_path(REL_PATH).'main/inc/lib/fckeditor/'; + + @ $editor_lang = Database :: get_language_isocode($language_interface); + $language_file = api_get_path(SYS_PATH).'main/inc/lib/fckeditor/editor/lang/'.$editor_lang.'.js'; + if (empty ($editor_lang) || !file_exists($language_file)) + { + //if there was no valid iso-code, use the english one + $editor_lang = 'en'; + } + + $TBL_LANGUAGES = Database::get_main_table(TABLE_MAIN_LANGUAGE); + + // We are in a course + if (isset($_SESSION["_course"]["language"])) { + $sql = "SELECT isocode FROM ".$TBL_LANGUAGES." WHERE english_name='".$_SESSION["_course"]["language"]."'"; + } elseif (isset($_SESSION["_user"]["language"])) { + //Else, we get the current session language + $sql = "SELECT isocode FROM ".$TBL_LANGUAGES." WHERE english_name='".$_SESSION["_user"]["language"]."'"; + } else { + //Else we get the default platform language + $platform_language = api_get_setting("platformLanguage"); + $sql = "SELECT isocode FROM ".$TBL_LANGUAGES." WHERE english_name='$platform_language'"; + } + + $result_sql = api_sql_query($sql, __FILE__, __LINE__); + $isocode_language = Database::result($result_sql, 0, 0); + $this->Config['DefaultLanguage'] = $isocode_language; + + // css should be dokeos ones + $this->Config['EditorAreaCSS'] = $this->Config['ToolbarComboPreviewCSS'] = api_get_path(REL_PATH).'main/css/'.api_get_setting('stylesheets').'/default.css'; + + // Default configuration settings for document repositories. + + // Preliminary calculations for assembling required paths. + $script_name = substr($_SERVER['PHP_SELF'], strlen(api_get_path(REL_PATH))); + $script_path = explode('/', $script_name); + $script_path[count($script_path) - 1] = ''; + if (api_is_in_course()) + { + $relative_path_prefix = str_repeat('../', count($script_path) - 1); + } + else + { + $relative_path_prefix = str_repeat('../', count($script_path) - 2); + } + $script_path = implode('/', $script_path); + $script_path = api_get_path(WEB_PATH).$script_path; + + $use_advanced_filemanager = api_get_setting('advanced_filemanager') == 'true'; + + if (api_is_in_course()) + { + if (!api_is_in_group()) + { + // 1. We are inside a course and not in a group. + + if (api_is_allowed_to_edit()) + { + // 1.1. Teacher (tutor and coach are not authorized to change anything in the "content creation" tools) + + if (empty($this->Config['CreateDocumentWebDir'])) + { + $this->Config['CreateDocumentWebDir'] = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/'; + } + + if (is_null($this->Config['CreateDocumentDir'])) + { + $this->Config['CreateDocumentDir'] = $relative_path_prefix.'courses/'.api_get_course_path().'/document/'; + } + + if (empty($this->Config['BaseHref'])) + { + $this->Config['BaseHref'] = $script_path; + } + + $upload_path = api_get_path(REL_COURSE_PATH).api_get_course_path().'/document/'; + } + else + { + // 1.2. Student + + if (empty($this->Config['CreateDocumentWebDir'])) + { + $this->Config['CreateDocumentWebDir'] = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/shared_folder/'.api_get_user_id().'/'; + } + + if (is_null($this->Config['CreateDocumentDir'])) + { + $this->Config['CreateDocumentDir'] = $relative_path_prefix.'courses/'.api_get_course_path().'/document/shared_folder/'.api_get_user_id().'/'; + } + + if (empty($this->Config['BaseHref'])) + { + $this->Config['BaseHref'] = $script_path; + } + + $upload_path = api_get_path(REL_COURSE_PATH).api_get_course_path().'/document/shared_folder/'.api_get_user_id().'/'; + } + } + else + { + // 2. Inside a course and inside a group. + + global $group_properties; + + if (empty($this->Config['CreateDocumentWebDir'])) + { + $this->Config['CreateDocumentWebDir'] = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document'.$group_properties['directory'].'/'; + } + + if (is_null($this->Config['CreateDocumentDir'])) + { + $this->Config['CreateDocumentDir'] = $relative_path_prefix.'courses/'.api_get_course_path().'/document'.$group_properties['directory'].'/'; + } + + if (empty($this->Config['BaseHref'])) + { + $this->Config['BaseHref'] = $script_path; + } + + $upload_path = api_get_path(REL_COURSE_PATH).api_get_course_path().'/document'.$group_properties['directory'].'/'; + } + } + else + { + if (api_is_platform_admin() && $_SESSION['this_section'] == 'platform_admin') + { + // 3. Platform administration activities. + + if (empty($this->Config['CreateDocumentWebDir'])) + { + $this->Config['CreateDocumentWebDir'] = api_get_path(WEB_PATH).'home/default_platform_document/'; + } + + if (is_null($this->Config['CreateDocumentDir'])) + { + $this->Config['CreateDocumentDir'] = api_get_path(WEB_PATH).'home/default_platform_document/'; // A side-effect is in use here. + } + + if (empty($this->Config['BaseHref'])) + { + $this->Config['BaseHref'] = api_get_path(WEB_PATH).'home/default_platform_document/'; + } + + $upload_path = api_get_path(REL_PATH).'home/default_platform_document/'; + } + else + { + // 4. The user is outside courses. + + if (empty($this->Config['CreateDocumentWebDir'])) + { + $this->Config['CreateDocumentWebDir'] = api_get_path('WEB_PATH').'main/upload/users/'.api_get_user_id().'/my_files/'; + } + + if (is_null($this->Config['CreateDocumentDir'])) + { + $this->Config['CreateDocumentDir'] = $relative_path_prefix.'upload/users/'.api_get_user_id().'/my_files/'; + } + + if (empty($this->Config['BaseHref'])) + { + $this->Config['BaseHref'] = $script_path; + } + + $upload_path = api_get_path(REL_PATH).'main/upload/users/'.api_get_user_id().'/my_files/'; + } + } + + // Setting hyperlinks used to call file managers. + + if ($use_advanced_filemanager) + { + // Let javascripts "know" which file manager has been chosen. + $this->Config['AdvancedFileManager'] = true; + + // Configuration path when advanced file manager is used. + $this->Config['CustomConfigurationsPath'] = api_get_path(REL_PATH)."main/inc/lib/fckeditor/myconfig_afm.js"; + + // URLs for opening the file browser for different resource types (file types): + + // for images + $this->Config['ImageBrowserURL'] = $this->BasePath.'/editor/plugins/ajaxfilemanager/ajaxfilemanager.php'; + + // for flash + $this->Config['FlashBrowserURL'] = $this->BasePath.'/editor/plugins/ajaxfilemanager/ajaxfilemanager.php'; + + // for audio files (mp3) + $this->Config['MP3BrowserURL'] = $this->BasePath.'/editor/plugins/ajaxfilemanager/ajaxfilemanager.php'; + + // for videos + $this->Config['VideoBrowserURL'] = $this->BasePath.'/editor/plugins/ajaxfilemanager/ajaxfilemanager.php'; + + // for videos (flv) + $this->Config['MediaBrowserURL'] = $this->BasePath.'/editor/plugins/ajaxfilemanager/ajaxfilemanager.php'; + + // for links (any resource type) + $this->Config['LinkBrowserURL'] = $this->BasePath.'/editor/plugins/ajaxfilemanager/ajaxfilemanager.php'; + } + else + { + // Passing the file manager setting to javascripts too. + $this->Config['AdvancedFileManager'] = false; + + // Configuration path when simple file manager is used. + $this->Config['CustomConfigurationsPath'] = api_get_path(REL_PATH)."main/inc/lib/fckeditor/myconfig.js"; + + // URLs for opening the file browser for different resource types (file types): + + // for images + $this->Config['ImageBrowserURL'] = $this->BasePath . "editor/filemanager/browser/default/browser.html?Type=Images&Connector=connectors/php/connector.php&ServerPath=$upload_path"; + + // for flash + $this->Config['FlashBrowserURL'] = $this->BasePath . "editor/filemanager/browser/default/browser.html?Type=Flash&Connector=connectors/php/connector.php&ServerPath=$upload_path"; + + // for audio files (mp3) + $this->Config['MP3BrowserURL'] = $this->BasePath . "editor/filemanager/browser/default/browser.html?Type=MP3&Connector=connectors/php/connector.php&ServerPath=$upload_path"; + + // for videos + $this->Config['VideoBrowserURL'] = $this->BasePath . "editor/filemanager/browser/default/browser.html?Type=Video&Connector=connectors/php/connector.php&ServerPath=$upload_path"; + + // for videos (flv) + $this->Config['MediaBrowserURL'] = $this->BasePath . "editor/filemanager/browser/default/browser.html?Type=Video/flv&Connector=connectors/php/connector.php&ServerPath=$upload_path"; + + // for links (any resource type) + $this->Config['LinkBrowserURL'] = $this->BasePath . "editor/filemanager/browser/default/browser.html?Type=File&Connector=connectors/php/connector.php&ServerPath=$upload_path"; + } + + // URLs for making quick uplods for different resource types (file types). + // These URLs are used by the dialogs' quick upload tabs: + + // for images + $this->Config['ImageUploadURL'] = $this->BasePath . "editor/filemanager/upload/php/upload.php?Type=Images&ServerPath=$upload_path" ; + + // for flash + $this->Config['FlashUploadURL'] = $this->BasePath . "editor/filemanager/upload/php/upload.php?Type=Flash&ServerPath=$upload_path" ; + + // for audio files (mp3) + $this->Config['MP3UploadURL'] = $this->BasePath . "editor/filemanager/upload/php/upload.php?Type=MP3&ServerPath=$upload_path" ; + + // for videos + $this->Config['VideoUploadURL'] = $this->BasePath . "editor/filemanager/upload/php/upload.php?Type=Video&ServerPath=$upload_path" ; + + // for videos (flv) + $this->Config['MediaUploadURL'] = $this->BasePath . "editor/filemanager/upload/php/upload.php?Type=Video/flv&ServerPath=$upload_path" ; + + // for links (any resource type) + $this->Config['LinkUploadURL'] = $this->BasePath . "editor/filemanager/upload/php/upload.php?Type=File&ServerPath=$upload_path" ; + } + + // The original code starts from here. + + $HtmlValue = htmlspecialchars( $this->Value ) ; + + $Html = '' ; + + if ( $this->IsCompatible() ) + { + if ( isset( $_GET['fcksource'] ) && $_GET['fcksource'] == "true" ) + $File = 'fckeditor.original.html' ; + else + $File = 'fckeditor.html' ; + + $Link = "{$this->BasePath}editor/{$File}?InstanceName={$this->InstanceName}" ; + + if ( $this->ToolbarSet != '' ) + $Link .= "&Toolbar={$this->ToolbarSet}" ; + + // Render the linked hidden field. + $Html .= "InstanceName}\" name=\"{$this->InstanceName}\" value=\"{$HtmlValue}\" style=\"display:none\" />" ; + + // Render the configurations hidden field. + $Html .= "InstanceName}___Config\" value=\"" . $this->GetConfigFieldString() . "\" style=\"display:none\" />" ; + + // Render the editor IFRAME. + $Html .= "" ; + } + else + { + if ( strpos( $this->Width, '%' ) === false ) + $WidthCSS = $this->Width . 'px' ; + else + $WidthCSS = $this->Width ; + + if ( strpos( $this->Height, '%' ) === false ) + $HeightCSS = $this->Height . 'px' ; + else + $HeightCSS = $this->Height ; + + $Html .= "" ; + } + + return $Html ; + } + + /** + * Returns true if browser is compatible with FCKeditor. + * + * @return boolean + */ + public function IsCompatible() + { + return FCKeditor_IsCompatibleBrowser() ; + } + + /** + * Get settings from Config array as a single string. + * + * @access protected + * @return string + */ + public function GetConfigFieldString() + { + $sParams = '' ; + $bFirst = true ; + + foreach ( $this->Config as $sKey => $sValue ) + { + if ( $bFirst == false ) + $sParams .= '&' ; + else + $bFirst = false ; + + if ( $sValue === true ) + $sParams .= $this->EncodeConfig( $sKey ) . '=true' ; + else if ( $sValue === false ) + $sParams .= $this->EncodeConfig( $sKey ) . '=false' ; + else + $sParams .= $this->EncodeConfig( $sKey ) . '=' . $this->EncodeConfig( $sValue ) ; + } + + return $sParams ; + } + + /** + * Encode characters that may break the configuration string + * generated by GetConfigFieldString(). + * + * @access protected + * @param string $valueToEncode + * @return string + */ + public function EncodeConfig( $valueToEncode ) + { + $chars = array( + '&' => '%26', + '=' => '%3D', + '"' => '%22' ) ; + + return strtr( $valueToEncode, $chars ) ; + } +} diff --git a/main/inc/lib/fckeditor/fckeditor_php4.php b/main/inc/lib/fckeditor/fckeditor_php4.php deleted file mode 100644 index feab27d8fa..0000000000 --- a/main/inc/lib/fckeditor/fckeditor_php4.php +++ /dev/null @@ -1,262 +0,0 @@ -= 5.5) ; - } - else if ( strpos($sAgent, 'Gecko/') !== false ) - { - $iVersion = (int)substr($sAgent, strpos($sAgent, 'Gecko/') + 6, 8) ; - return ($iVersion >= 20030210) ; - } - else if ( strpos($sAgent, 'Opera/') !== false ) - { - $fVersion = (float)substr($sAgent, strpos($sAgent, 'Opera/') + 6, 4) ; - return ($fVersion >= 9.5) ; - } - else if ( preg_match( "|AppleWebKit/(\d+)|i", $sAgent, $matches ) ) - { - $iVersion = $matches[1] ; - return ( $matches[1] >= 522 ) ; - } - else - return false ; -} - -class FCKeditor -{ - /** - * Name of the FCKeditor instance. - * - * @access protected - * @var string - */ - var $InstanceName ; - /** - * Path to FCKeditor relative to the document root. - * - * @var string - */ - var $BasePath ; - /** - * Width of the FCKeditor. - * Examples: 100%, 600 - * - * @var mixed - */ - var $Width ; - /** - * Height of the FCKeditor. - * Examples: 400, 50% - * - * @var mixed - */ - var $Height ; - /** - * Name of the toolbar to load. - * - * @var string - */ - var $ToolbarSet ; - /** - * Initial value. - * - * @var string - */ - var $Value ; - /** - * This is where additional configuration can be passed. - * Example: - * $oFCKeditor->Config['EnterMode'] = 'br'; - * - * @var array - */ - var $Config ; - - /** - * Main Constructor. - * Refer to the _samples/php directory for examples. - * - * @param string $instanceName - */ - function FCKeditor( $instanceName ) - { - $this->InstanceName = $instanceName ; - $this->BasePath = '/fckeditor/' ; - $this->Width = '100%' ; - $this->Height = '200' ; - $this->ToolbarSet = 'Default' ; - $this->Value = '' ; - - $this->Config = array() ; - } - - /** - * Display FCKeditor. - * - */ - function Create($called_by_formvalidator = false) - { - echo $this->CreateHtml($called_by_formvalidator) ; - } - - /** - * Return the HTML code required to run FCKeditor. - * - * @return string - */ - function CreateHtml($called_by_formvalidator = false) - { - $HtmlValue = htmlspecialchars( $this->Value ) ; - - $Html = '' ; - - if ( !isset( $_GET ) ) { - global $HTTP_GET_VARS ; - $_GET = $HTTP_GET_VARS ; - } - - if ( $this->IsCompatible() ) - { - if ( isset( $_GET['fcksource'] ) && $_GET['fcksource'] == "true" ) - $File = 'fckeditor.original.html' ; - else - $File = 'fckeditor.html' ; - - $Link = "{$this->BasePath}editor/{$File}?InstanceName={$this->InstanceName}" ; - - if ( $this->ToolbarSet != '' ) - $Link .= "&Toolbar={$this->ToolbarSet}" ; - - // Render the linked hidden field. - $Html .= "InstanceName}\" name=\"{$this->InstanceName}\" value=\"{$HtmlValue}\" style=\"display:none\" />" ; - - // Render the configurations hidden field. - $Html .= "InstanceName}___Config\" value=\"" . $this->GetConfigFieldString() . "\" style=\"display:none\" />" ; - - // Render the editor IFRAME. - $Html .= "" ; - } - else - { - if ( strpos( $this->Width, '%' ) === false ) - $WidthCSS = $this->Width . 'px' ; - else - $WidthCSS = $this->Width ; - - if ( strpos( $this->Height, '%' ) === false ) - $HeightCSS = $this->Height . 'px' ; - else - $HeightCSS = $this->Height ; - - $Html .= "" ; - } - - return $Html ; - } - - /** - * Returns true if browser is compatible with FCKeditor. - * - * @return boolean - */ - function IsCompatible() - { - return FCKeditor_IsCompatibleBrowser() ; - } - - /** - * Get settings from Config array as a single string. - * - * @access protected - * @return string - */ - function GetConfigFieldString() - { - $sParams = '' ; - $bFirst = true ; - - foreach ( $this->Config as $sKey => $sValue ) - { - if ( $bFirst == false ) - $sParams .= '&' ; - else - $bFirst = false ; - - if ( $sValue === true ) - $sParams .= $this->EncodeConfig( $sKey ) . '=true' ; - else if ( $sValue === false ) - $sParams .= $this->EncodeConfig( $sKey ) . '=false' ; - else - $sParams .= $this->EncodeConfig( $sKey ) . '=' . $this->EncodeConfig( $sValue ) ; - } - - return $sParams ; - } - - /** - * Encode characters that may break the configuration string - * generated by GetConfigFieldString(). - * - * @access protected - * @param string $valueToEncode - * @return string - */ - function EncodeConfig( $valueToEncode ) - { - $chars = array( - '&' => '%26', - '=' => '%3D', - '"' => '%22' ) ; - - return strtr( $valueToEncode, $chars ) ; - } -} diff --git a/main/inc/lib/fckeditor/fckeditor_php4_original.php b/main/inc/lib/fckeditor/fckeditor_php4_original.php deleted file mode 100644 index dae4cf320d..0000000000 --- a/main/inc/lib/fckeditor/fckeditor_php4_original.php +++ /dev/null @@ -1,262 +0,0 @@ -= 5.5) ; - } - else if ( strpos($sAgent, 'Gecko/') !== false ) - { - $iVersion = (int)substr($sAgent, strpos($sAgent, 'Gecko/') + 6, 8) ; - return ($iVersion >= 20030210) ; - } - else if ( strpos($sAgent, 'Opera/') !== false ) - { - $fVersion = (float)substr($sAgent, strpos($sAgent, 'Opera/') + 6, 4) ; - return ($fVersion >= 9.5) ; - } - else if ( preg_match( "|AppleWebKit/(\d+)|i", $sAgent, $matches ) ) - { - $iVersion = $matches[1] ; - return ( $matches[1] >= 522 ) ; - } - else - return false ; -} - -class FCKeditor -{ - /** - * Name of the FCKeditor instance. - * - * @access protected - * @var string - */ - var $InstanceName ; - /** - * Path to FCKeditor relative to the document root. - * - * @var string - */ - var $BasePath ; - /** - * Width of the FCKeditor. - * Examples: 100%, 600 - * - * @var mixed - */ - var $Width ; - /** - * Height of the FCKeditor. - * Examples: 400, 50% - * - * @var mixed - */ - var $Height ; - /** - * Name of the toolbar to load. - * - * @var string - */ - var $ToolbarSet ; - /** - * Initial value. - * - * @var string - */ - var $Value ; - /** - * This is where additional configuration can be passed. - * Example: - * $oFCKeditor->Config['EnterMode'] = 'br'; - * - * @var array - */ - var $Config ; - - /** - * Main Constructor. - * Refer to the _samples/php directory for examples. - * - * @param string $instanceName - */ - function FCKeditor( $instanceName ) - { - $this->InstanceName = $instanceName ; - $this->BasePath = '/fckeditor/' ; - $this->Width = '100%' ; - $this->Height = '200' ; - $this->ToolbarSet = 'Default' ; - $this->Value = '' ; - - $this->Config = array() ; - } - - /** - * Display FCKeditor. - * - */ - function Create() - { - echo $this->CreateHtml() ; - } - - /** - * Return the HTML code required to run FCKeditor. - * - * @return string - */ - function CreateHtml() - { - $HtmlValue = htmlspecialchars( $this->Value ) ; - - $Html = '' ; - - if ( !isset( $_GET ) ) { - global $HTTP_GET_VARS ; - $_GET = $HTTP_GET_VARS ; - } - - if ( $this->IsCompatible() ) - { - if ( isset( $_GET['fcksource'] ) && $_GET['fcksource'] == "true" ) - $File = 'fckeditor.original.html' ; - else - $File = 'fckeditor.html' ; - - $Link = "{$this->BasePath}editor/{$File}?InstanceName={$this->InstanceName}" ; - - if ( $this->ToolbarSet != '' ) - $Link .= "&Toolbar={$this->ToolbarSet}" ; - - // Render the linked hidden field. - $Html .= "InstanceName}\" name=\"{$this->InstanceName}\" value=\"{$HtmlValue}\" style=\"display:none\" />" ; - - // Render the configurations hidden field. - $Html .= "InstanceName}___Config\" value=\"" . $this->GetConfigFieldString() . "\" style=\"display:none\" />" ; - - // Render the editor IFRAME. - $Html .= "" ; - } - else - { - if ( strpos( $this->Width, '%' ) === false ) - $WidthCSS = $this->Width . 'px' ; - else - $WidthCSS = $this->Width ; - - if ( strpos( $this->Height, '%' ) === false ) - $HeightCSS = $this->Height . 'px' ; - else - $HeightCSS = $this->Height ; - - $Html .= "" ; - } - - return $Html ; - } - - /** - * Returns true if browser is compatible with FCKeditor. - * - * @return boolean - */ - function IsCompatible() - { - return FCKeditor_IsCompatibleBrowser() ; - } - - /** - * Get settings from Config array as a single string. - * - * @access protected - * @return string - */ - function GetConfigFieldString() - { - $sParams = '' ; - $bFirst = true ; - - foreach ( $this->Config as $sKey => $sValue ) - { - if ( $bFirst == false ) - $sParams .= '&' ; - else - $bFirst = false ; - - if ( $sValue === true ) - $sParams .= $this->EncodeConfig( $sKey ) . '=true' ; - else if ( $sValue === false ) - $sParams .= $this->EncodeConfig( $sKey ) . '=false' ; - else - $sParams .= $this->EncodeConfig( $sKey ) . '=' . $this->EncodeConfig( $sValue ) ; - } - - return $sParams ; - } - - /** - * Encode characters that may break the configuration string - * generated by GetConfigFieldString(). - * - * @access protected - * @param string $valueToEncode - * @return string - */ - function EncodeConfig( $valueToEncode ) - { - $chars = array( - '&' => '%26', - '=' => '%3D', - '"' => '%22' ) ; - - return strtr( $valueToEncode, $chars ) ; - } -} diff --git a/main/inc/lib/fckeditor/fckeditor_php5.php b/main/inc/lib/fckeditor/fckeditor_php5.php deleted file mode 100644 index 2318029c4d..0000000000 --- a/main/inc/lib/fckeditor/fckeditor_php5.php +++ /dev/null @@ -1,521 +0,0 @@ -= 5.5) ; - } - else if ( strpos($sAgent, 'Gecko/') !== false ) - { - $iVersion = (int)substr($sAgent, strpos($sAgent, 'Gecko/') + 6, 8) ; - return ($iVersion >= 20030210) ; - } - else if ( strpos($sAgent, 'Opera/') !== false ) - { - $fVersion = (float)substr($sAgent, strpos($sAgent, 'Opera/') + 6, 4) ; - return ($fVersion >= 9.5) ; - } - else if ( preg_match( "|AppleWebKit/(\d+)|i", $sAgent, $matches ) ) - { - $iVersion = $matches[1] ; - return ( $matches[1] >= 522 ) ; - } - else - return false ; -} - -class FCKeditor -{ - /** - * Name of the FCKeditor instance. - * - * @access protected - * @var string - */ - public $InstanceName ; - /** - * Path to FCKeditor relative to the document root. - * - * @var string - */ - public $BasePath ; - /** - * Width of the FCKeditor. - * Examples: 100%, 600 - * - * @var mixed - */ - public $Width ; - /** - * Height of the FCKeditor. - * Examples: 400, 50% - * - * @var mixed - */ - public $Height ; - /** - * Name of the toolbar to load. - * - * @var string - */ - public $ToolbarSet ; - /** - * Initial value. - * - * @var string - */ - public $Value ; - /** - * This is where additional configuration can be passed. - * Example: - * $oFCKeditor->Config['EnterMode'] = 'br'; - * - * @var array - */ - public $Config ; - - /** - * Main Constructor. - * Refer to the _samples/php directory for examples. - * - * @param string $instanceName - */ - public function __construct( $instanceName ) - { - $this->InstanceName = $instanceName ; - $this->BasePath = '/fckeditor/' ; - $this->Width = '100%' ; - $this->Height = '200' ; - $this->ToolbarSet = 'Default' ; - $this->Value = '' ; - - $this->Config = array() ; - } - - /** - * Display FCKeditor. - * - */ - public function Create($called_by_formvalidator = false) - { - echo $this->CreateHtml($called_by_formvalidator) ; - } - - /** - * Return the HTML code required to run FCKeditor. - * - * @return string - */ - public function CreateHtml($called_by_formvalidator = false) - { - // Adaptation for the Dokeos LMS. - - // Default configuration settings will be calculated when the editor - // is (still) created directly, without using the formvalidator module. - // These default settings might not cover all possible cases. - - if (!$called_by_formvalidator) - { - global $language_interface; - - $this->BasePath = api_get_path(REL_PATH).'main/inc/lib/fckeditor/'; - - @ $editor_lang = Database :: get_language_isocode($language_interface); - $language_file = api_get_path(SYS_PATH).'main/inc/lib/fckeditor/editor/lang/'.$editor_lang.'.js'; - if (empty ($editor_lang) || !file_exists($language_file)) - { - //if there was no valid iso-code, use the english one - $editor_lang = 'en'; - } - - $TBL_LANGUAGES = Database::get_main_table(TABLE_MAIN_LANGUAGE); - - // We are in a course - if (isset($_SESSION["_course"]["language"])) { - $sql = "SELECT isocode FROM ".$TBL_LANGUAGES." WHERE english_name='".$_SESSION["_course"]["language"]."'"; - } elseif (isset($_SESSION["_user"]["language"])) { - //Else, we get the current session language - $sql = "SELECT isocode FROM ".$TBL_LANGUAGES." WHERE english_name='".$_SESSION["_user"]["language"]."'"; - } else { - //Else we get the default platform language - $platform_language = api_get_setting("platformLanguage"); - $sql = "SELECT isocode FROM ".$TBL_LANGUAGES." WHERE english_name='$platform_language'"; - } - - $result_sql = api_sql_query($sql, __FILE__, __LINE__); - $isocode_language = Database::result($result_sql, 0, 0); - $this->Config['DefaultLanguage'] = $isocode_language; - - // css should be dokeos ones - $this->Config['EditorAreaCSS'] = $this->Config['ToolbarComboPreviewCSS'] = api_get_path(REL_PATH).'main/css/'.api_get_setting('stylesheets').'/default.css'; - - // Default configuration settings for document repositories. - - // Preliminary calculations for assembling required paths. - $script_name = substr($_SERVER['PHP_SELF'], strlen(api_get_path(REL_PATH))); - $script_path = explode('/', $script_name); - $script_path[count($script_path) - 1] = ''; - if (api_is_in_course()) - { - $relative_path_prefix = str_repeat('../', count($script_path) - 1); - } - else - { - $relative_path_prefix = str_repeat('../', count($script_path) - 2); - } - $script_path = implode('/', $script_path); - $script_path = api_get_path(WEB_PATH).$script_path; - - $use_advanced_filemanager = api_get_setting('advanced_filemanager') == 'true'; - - if (api_is_in_course()) - { - if (!api_is_in_group()) - { - // 1. We are inside a course and not in a group. - - if (api_is_allowed_to_edit()) - { - // 1.1. Teacher (tutor and coach are not authorized to change anything in the "content creation" tools) - - if (empty($this->Config['CreateDocumentWebDir'])) - { - $this->Config['CreateDocumentWebDir'] = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/'; - } - - if (is_null($this->Config['CreateDocumentDir'])) - { - $this->Config['CreateDocumentDir'] = $relative_path_prefix.'courses/'.api_get_course_path().'/document/'; - } - - if (empty($this->Config['BaseHref'])) - { - $this->Config['BaseHref'] = $script_path; - } - - $upload_path = api_get_path(REL_COURSE_PATH).api_get_course_path().'/document/'; - } - else - { - // 1.2. Student - - if (empty($this->Config['CreateDocumentWebDir'])) - { - $this->Config['CreateDocumentWebDir'] = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/shared_folder/'.api_get_user_id().'/'; - } - - if (is_null($this->Config['CreateDocumentDir'])) - { - $this->Config['CreateDocumentDir'] = $relative_path_prefix.'courses/'.api_get_course_path().'/document/shared_folder/'.api_get_user_id().'/'; - } - - if (empty($this->Config['BaseHref'])) - { - $this->Config['BaseHref'] = $script_path; - } - - $upload_path = api_get_path(REL_COURSE_PATH).api_get_course_path().'/document/shared_folder/'.api_get_user_id().'/'; - } - } - else - { - // 2. Inside a course and inside a group. - - global $group_properties; - - if (empty($this->Config['CreateDocumentWebDir'])) - { - $this->Config['CreateDocumentWebDir'] = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document'.$group_properties['directory'].'/'; - } - - if (is_null($this->Config['CreateDocumentDir'])) - { - $this->Config['CreateDocumentDir'] = $relative_path_prefix.'courses/'.api_get_course_path().'/document'.$group_properties['directory'].'/'; - } - - if (empty($this->Config['BaseHref'])) - { - $this->Config['BaseHref'] = $script_path; - } - - $upload_path = api_get_path(REL_COURSE_PATH).api_get_course_path().'/document'.$group_properties['directory'].'/'; - } - } - else - { - if (api_is_platform_admin() && $_SESSION['this_section'] == 'platform_admin') - { - // 3. Platform administration activities. - - if (empty($this->Config['CreateDocumentWebDir'])) - { - $this->Config['CreateDocumentWebDir'] = api_get_path(WEB_PATH).'home/default_platform_document/'; - } - - if (is_null($this->Config['CreateDocumentDir'])) - { - $this->Config['CreateDocumentDir'] = api_get_path(WEB_PATH).'home/default_platform_document/'; // A side-effect is in use here. - } - - if (empty($this->Config['BaseHref'])) - { - $this->Config['BaseHref'] = api_get_path(WEB_PATH).'home/default_platform_document/'; - } - - $upload_path = api_get_path(REL_PATH).'home/default_platform_document/'; - } - else - { - // 4. The user is outside courses. - - if (empty($this->Config['CreateDocumentWebDir'])) - { - $this->Config['CreateDocumentWebDir'] = api_get_path('WEB_PATH').'main/upload/users/'.api_get_user_id().'/my_files/'; - } - - if (is_null($this->Config['CreateDocumentDir'])) - { - $this->Config['CreateDocumentDir'] = $relative_path_prefix.'upload/users/'.api_get_user_id().'/my_files/'; - } - - if (empty($this->Config['BaseHref'])) - { - $this->Config['BaseHref'] = $script_path; - } - - $upload_path = api_get_path(REL_PATH).'main/upload/users/'.api_get_user_id().'/my_files/'; - } - } - - // Setting hyperlinks used to call file managers. - - if ($use_advanced_filemanager) - { - // Let javascripts "know" which file manager has been chosen. - $this->Config['AdvancedFileManager'] = true; - - // Configuration path when advanced file manager is used. - $this->Config['CustomConfigurationsPath'] = api_get_path(REL_PATH)."main/inc/lib/fckeditor/myconfig_afm.js"; - - // URLs for opening the file browser for different resource types (file types): - - // for images - $this->Config['ImageBrowserURL'] = $this->BasePath.'/editor/plugins/ajaxfilemanager/ajaxfilemanager.php'; - - // for flash - $this->Config['FlashBrowserURL'] = $this->BasePath.'/editor/plugins/ajaxfilemanager/ajaxfilemanager.php'; - - // for audio files (mp3) - $this->Config['MP3BrowserURL'] = $this->BasePath.'/editor/plugins/ajaxfilemanager/ajaxfilemanager.php'; - - // for videos - $this->Config['VideoBrowserURL'] = $this->BasePath.'/editor/plugins/ajaxfilemanager/ajaxfilemanager.php'; - - // for videos (flv) - $this->Config['MediaBrowserURL'] = $this->BasePath.'/editor/plugins/ajaxfilemanager/ajaxfilemanager.php'; - - // for links (any resource type) - $this->Config['LinkBrowserURL'] = $this->BasePath.'/editor/plugins/ajaxfilemanager/ajaxfilemanager.php'; - } - else - { - // Passing the file manager setting to javascripts too. - $this->Config['AdvancedFileManager'] = false; - - // Configuration path when simple file manager is used. - $this->Config['CustomConfigurationsPath'] = api_get_path(REL_PATH)."main/inc/lib/fckeditor/myconfig.js"; - - // URLs for opening the file browser for different resource types (file types): - - // for images - $this->Config['ImageBrowserURL'] = $this->BasePath . "editor/filemanager/browser/default/browser.html?Type=Images&Connector=connectors/php/connector.php&ServerPath=$upload_path"; - - // for flash - $this->Config['FlashBrowserURL'] = $this->BasePath . "editor/filemanager/browser/default/browser.html?Type=Flash&Connector=connectors/php/connector.php&ServerPath=$upload_path"; - - // for audio files (mp3) - $this->Config['MP3BrowserURL'] = $this->BasePath . "editor/filemanager/browser/default/browser.html?Type=MP3&Connector=connectors/php/connector.php&ServerPath=$upload_path"; - - // for videos - $this->Config['VideoBrowserURL'] = $this->BasePath . "editor/filemanager/browser/default/browser.html?Type=Video&Connector=connectors/php/connector.php&ServerPath=$upload_path"; - - // for videos (flv) - $this->Config['MediaBrowserURL'] = $this->BasePath . "editor/filemanager/browser/default/browser.html?Type=Video/flv&Connector=connectors/php/connector.php&ServerPath=$upload_path"; - - // for links (any resource type) - $this->Config['LinkBrowserURL'] = $this->BasePath . "editor/filemanager/browser/default/browser.html?Type=File&Connector=connectors/php/connector.php&ServerPath=$upload_path"; - } - - // URLs for making quick uplods for different resource types (file types). - // These URLs are used by the dialogs' quick upload tabs: - - // for images - $this->Config['ImageUploadURL'] = $this->BasePath . "editor/filemanager/upload/php/upload.php?Type=Images&ServerPath=$upload_path" ; - - // for flash - $this->Config['FlashUploadURL'] = $this->BasePath . "editor/filemanager/upload/php/upload.php?Type=Flash&ServerPath=$upload_path" ; - - // for audio files (mp3) - $this->Config['MP3UploadURL'] = $this->BasePath . "editor/filemanager/upload/php/upload.php?Type=MP3&ServerPath=$upload_path" ; - - // for videos - $this->Config['VideoUploadURL'] = $this->BasePath . "editor/filemanager/upload/php/upload.php?Type=Video&ServerPath=$upload_path" ; - - // for videos (flv) - $this->Config['MediaUploadURL'] = $this->BasePath . "editor/filemanager/upload/php/upload.php?Type=Video/flv&ServerPath=$upload_path" ; - - // for links (any resource type) - $this->Config['LinkUploadURL'] = $this->BasePath . "editor/filemanager/upload/php/upload.php?Type=File&ServerPath=$upload_path" ; - } - - // The original code starts from here. - - $HtmlValue = htmlspecialchars( $this->Value ) ; - - $Html = '' ; - - if ( $this->IsCompatible() ) - { - if ( isset( $_GET['fcksource'] ) && $_GET['fcksource'] == "true" ) - $File = 'fckeditor.original.html' ; - else - $File = 'fckeditor.html' ; - - $Link = "{$this->BasePath}editor/{$File}?InstanceName={$this->InstanceName}" ; - - if ( $this->ToolbarSet != '' ) - $Link .= "&Toolbar={$this->ToolbarSet}" ; - - // Render the linked hidden field. - $Html .= "InstanceName}\" name=\"{$this->InstanceName}\" value=\"{$HtmlValue}\" style=\"display:none\" />" ; - - // Render the configurations hidden field. - $Html .= "InstanceName}___Config\" value=\"" . $this->GetConfigFieldString() . "\" style=\"display:none\" />" ; - - // Render the editor IFRAME. - $Html .= "" ; - } - else - { - if ( strpos( $this->Width, '%' ) === false ) - $WidthCSS = $this->Width . 'px' ; - else - $WidthCSS = $this->Width ; - - if ( strpos( $this->Height, '%' ) === false ) - $HeightCSS = $this->Height . 'px' ; - else - $HeightCSS = $this->Height ; - - $Html .= "" ; - } - - return $Html ; - } - - /** - * Returns true if browser is compatible with FCKeditor. - * - * @return boolean - */ - public function IsCompatible() - { - return FCKeditor_IsCompatibleBrowser() ; - } - - /** - * Get settings from Config array as a single string. - * - * @access protected - * @return string - */ - public function GetConfigFieldString() - { - $sParams = '' ; - $bFirst = true ; - - foreach ( $this->Config as $sKey => $sValue ) - { - if ( $bFirst == false ) - $sParams .= '&' ; - else - $bFirst = false ; - - if ( $sValue === true ) - $sParams .= $this->EncodeConfig( $sKey ) . '=true' ; - else if ( $sValue === false ) - $sParams .= $this->EncodeConfig( $sKey ) . '=false' ; - else - $sParams .= $this->EncodeConfig( $sKey ) . '=' . $this->EncodeConfig( $sValue ) ; - } - - return $sParams ; - } - - /** - * Encode characters that may break the configuration string - * generated by GetConfigFieldString(). - * - * @access protected - * @param string $valueToEncode - * @return string - */ - public function EncodeConfig( $valueToEncode ) - { - $chars = array( - '&' => '%26', - '=' => '%3D', - '"' => '%22' ) ; - - return strtr( $valueToEncode, $chars ) ; - } -} diff --git a/main/inc/lib/fckeditor/fckeditor_php5_original.php b/main/inc/lib/fckeditor/fckeditor_php5_original.php deleted file mode 100644 index 939bfc9956..0000000000 --- a/main/inc/lib/fckeditor/fckeditor_php5_original.php +++ /dev/null @@ -1,257 +0,0 @@ -= 5.5) ; - } - else if ( strpos($sAgent, 'Gecko/') !== false ) - { - $iVersion = (int)substr($sAgent, strpos($sAgent, 'Gecko/') + 6, 8) ; - return ($iVersion >= 20030210) ; - } - else if ( strpos($sAgent, 'Opera/') !== false ) - { - $fVersion = (float)substr($sAgent, strpos($sAgent, 'Opera/') + 6, 4) ; - return ($fVersion >= 9.5) ; - } - else if ( preg_match( "|AppleWebKit/(\d+)|i", $sAgent, $matches ) ) - { - $iVersion = $matches[1] ; - return ( $matches[1] >= 522 ) ; - } - else - return false ; -} - -class FCKeditor -{ - /** - * Name of the FCKeditor instance. - * - * @access protected - * @var string - */ - public $InstanceName ; - /** - * Path to FCKeditor relative to the document root. - * - * @var string - */ - public $BasePath ; - /** - * Width of the FCKeditor. - * Examples: 100%, 600 - * - * @var mixed - */ - public $Width ; - /** - * Height of the FCKeditor. - * Examples: 400, 50% - * - * @var mixed - */ - public $Height ; - /** - * Name of the toolbar to load. - * - * @var string - */ - public $ToolbarSet ; - /** - * Initial value. - * - * @var string - */ - public $Value ; - /** - * This is where additional configuration can be passed. - * Example: - * $oFCKeditor->Config['EnterMode'] = 'br'; - * - * @var array - */ - public $Config ; - - /** - * Main Constructor. - * Refer to the _samples/php directory for examples. - * - * @param string $instanceName - */ - public function __construct( $instanceName ) - { - $this->InstanceName = $instanceName ; - $this->BasePath = '/fckeditor/' ; - $this->Width = '100%' ; - $this->Height = '200' ; - $this->ToolbarSet = 'Default' ; - $this->Value = '' ; - - $this->Config = array() ; - } - - /** - * Display FCKeditor. - * - */ - public function Create() - { - echo $this->CreateHtml() ; - } - - /** - * Return the HTML code required to run FCKeditor. - * - * @return string - */ - public function CreateHtml() - { - $HtmlValue = htmlspecialchars( $this->Value ) ; - - $Html = '' ; - - if ( $this->IsCompatible() ) - { - if ( isset( $_GET['fcksource'] ) && $_GET['fcksource'] == "true" ) - $File = 'fckeditor.original.html' ; - else - $File = 'fckeditor.html' ; - - $Link = "{$this->BasePath}editor/{$File}?InstanceName={$this->InstanceName}" ; - - if ( $this->ToolbarSet != '' ) - $Link .= "&Toolbar={$this->ToolbarSet}" ; - - // Render the linked hidden field. - $Html .= "InstanceName}\" name=\"{$this->InstanceName}\" value=\"{$HtmlValue}\" style=\"display:none\" />" ; - - // Render the configurations hidden field. - $Html .= "InstanceName}___Config\" value=\"" . $this->GetConfigFieldString() . "\" style=\"display:none\" />" ; - - // Render the editor IFRAME. - $Html .= "" ; - } - else - { - if ( strpos( $this->Width, '%' ) === false ) - $WidthCSS = $this->Width . 'px' ; - else - $WidthCSS = $this->Width ; - - if ( strpos( $this->Height, '%' ) === false ) - $HeightCSS = $this->Height . 'px' ; - else - $HeightCSS = $this->Height ; - - $Html .= "" ; - } - - return $Html ; - } - - /** - * Returns true if browser is compatible with FCKeditor. - * - * @return boolean - */ - public function IsCompatible() - { - return FCKeditor_IsCompatibleBrowser() ; - } - - /** - * Get settings from Config array as a single string. - * - * @access protected - * @return string - */ - public function GetConfigFieldString() - { - $sParams = '' ; - $bFirst = true ; - - foreach ( $this->Config as $sKey => $sValue ) - { - if ( $bFirst == false ) - $sParams .= '&' ; - else - $bFirst = false ; - - if ( $sValue === true ) - $sParams .= $this->EncodeConfig( $sKey ) . '=true' ; - else if ( $sValue === false ) - $sParams .= $this->EncodeConfig( $sKey ) . '=false' ; - else - $sParams .= $this->EncodeConfig( $sKey ) . '=' . $this->EncodeConfig( $sValue ) ; - } - - return $sParams ; - } - - /** - * Encode characters that may break the configuration string - * generated by GetConfigFieldString(). - * - * @access protected - * @param string $valueToEncode - * @return string - */ - public function EncodeConfig( $valueToEncode ) - { - $chars = array( - '&' => '%26', - '=' => '%3D', - '"' => '%22' ) ; - - return strtr( $valueToEncode, $chars ) ; - } -}