PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/old/ckfinder/core/ckfinder_php5.php

https://gitlab.com/endomorphosis/falkenstein
PHP | 231 lines | 172 code | 38 blank | 21 comment | 38 complexity | a9c3d7e8a084ede90e8934debf79df12 MD5 | raw file
  1. <?php
  2. /*
  3. * CKFinder
  4. * ========
  5. * http://ckfinder.com
  6. * Copyright (C) 2007-2012, CKSource - Frederico Knabben. All rights reserved.
  7. *
  8. * The software, this file and its contents are subject to the CKFinder
  9. * License. Please read the license.txt file before using, installing, copying,
  10. * modifying or distribute this file or part of its contents. The contents of
  11. * this file is part of the Source Code of CKFinder.
  12. */
  13. define( 'CKFINDER_DEFAULT_BASEPATH', '/ckfinder/' ) ;
  14. class CKFinder
  15. {
  16. public $BasePath ;
  17. public $Width ;
  18. public $Height ;
  19. public $SelectFunction ;
  20. public $SelectFunctionData ;
  21. public $SelectThumbnailFunction ;
  22. public $SelectThumbnailFunctionData ;
  23. public $DisableThumbnailSelection = false ;
  24. public $ClassName = '' ;
  25. public $Id = '' ;
  26. public $StartupPath ;
  27. public $ResourceType ;
  28. public $RememberLastFolder = true ;
  29. public $StartupFolderExpanded = false ;
  30. // PHP 5 Constructor
  31. function __construct( $basePath = CKFINDER_DEFAULT_BASEPATH, $width = '100%', $height = 400, $selectFunction = null )
  32. {
  33. $this->BasePath = $basePath ;
  34. $this->Width = $width ;
  35. $this->Height = $height ;
  36. $this->SelectFunction = $selectFunction ;
  37. $this->SelectThumbnailFunction = $selectFunction ;
  38. }
  39. // Renders CKFinder in the current page.
  40. public function Create()
  41. {
  42. echo $this->CreateHtml() ;
  43. }
  44. // Gets the HTML needed to create a CKFinder instance.
  45. public function CreateHtml()
  46. {
  47. $className = $this->ClassName ;
  48. if ( !empty( $className ) )
  49. $className = ' class="' . $className . '"' ;
  50. $id = $this->Id ;
  51. if ( !empty( $id ) )
  52. $id = ' id="' . $id . '"' ;
  53. return '<iframe src="' . $this->_BuildUrl() . '" width="' . $this->Width . '" ' .
  54. 'height="' . $this->Height . '"' . $className . $id . ' frameborder="0" scrolling="no"></iframe>' ;
  55. }
  56. private function _BuildUrl( $url = "" )
  57. {
  58. if ( !$url )
  59. $url = $this->BasePath ;
  60. $qs = "" ;
  61. if ( empty( $url ) )
  62. $url = CKFINDER_DEFAULT_BASEPATH ;
  63. if ( $url[ strlen( $url ) - 1 ] != '/' )
  64. $url = $url . '/' ;
  65. $url .= 'ckfinder.html' ;
  66. if ( !empty( $this->SelectFunction ) )
  67. $qs .= '?action=js&amp;func=' . $this->SelectFunction ;
  68. if ( !empty( $this->SelectFunctionData ) )
  69. {
  70. $qs .= $qs ? "&amp;" : "?" ;
  71. $qs .= 'data=' . rawurlencode($this->SelectFunctionData) ;
  72. }
  73. if ( $this->DisableThumbnailSelection )
  74. {
  75. $qs .= $qs ? "&amp;" : "?" ;
  76. $qs .= "dts=1" ;
  77. }
  78. else if ( !empty( $this->SelectThumbnailFunction ) || !empty( $this->SelectFunction ) )
  79. {
  80. $qs .= $qs ? "&amp;" : "?" ;
  81. $qs .= 'thumbFunc=' . ( !empty( $this->SelectThumbnailFunction ) ? $this->SelectThumbnailFunction : $this->SelectFunction ) ;
  82. if ( !empty( $this->SelectThumbnailFunctionData ) )
  83. $qs .= '&amp;tdata=' . rawurlencode( $this->SelectThumbnailFunctionData ) ;
  84. else if ( empty( $this->SelectThumbnailFunction ) && !empty( $this->SelectFunctionData ) )
  85. $qs .= '&amp;tdata=' . rawurlencode( $this->SelectFunctionData ) ;
  86. }
  87. if ( !empty( $this->StartupPath ) )
  88. {
  89. $qs .= ( $qs ? "&amp;" : "?" ) ;
  90. $qs .= "start=" . urlencode( $this->StartupPath . ( $this->StartupFolderExpanded ? ':1' : ':0' ) ) ;
  91. }
  92. if ( !empty( $this->ResourceType ) )
  93. {
  94. $qs .= ( $qs ? "&amp;" : "?" ) ;
  95. $qs .= "type=" . urlencode( $this->ResourceType ) ;
  96. }
  97. if ( !$this->RememberLastFolder )
  98. {
  99. $qs .= ( $qs ? "&amp;" : "?" ) ;
  100. $qs .= "rlf=0" ;
  101. }
  102. if ( !empty( $this->Id ) )
  103. {
  104. $qs .= ( $qs ? "&amp;" : "?" ) ;
  105. $qs .= "id=" . urlencode( $this->Id ) ;
  106. }
  107. return $url . $qs ;
  108. }
  109. // Static "Create".
  110. public static function CreateStatic( $basePath = CKFINDER_DEFAULT_BASEPATH, $width = '100%', $height = 400, $selectFunction = null )
  111. {
  112. $finder = new CKFinder( $basePath, $width, $height, $selectFunction ) ;
  113. $finder->Create() ;
  114. }
  115. // Static "SetupFCKeditor".
  116. public static function SetupFCKeditor( &$editorObj, $basePath = CKFINDER_DEFAULT_BASEPATH, $imageType = null, $flashType = null )
  117. {
  118. if ( empty( $basePath ) )
  119. $basePath = CKFINDER_DEFAULT_BASEPATH ;
  120. $ckfinder = new CKFinder( $basePath ) ;
  121. $ckfinder->SetupFCKeditorObject( $editorObj, $imageType, $flashType );
  122. }
  123. // Non-static method of attaching CKFinder to FCKeditor
  124. public function SetupFCKeditorObject( &$editorObj, $imageType = null, $flashType = null )
  125. {
  126. $url = $this->BasePath ;
  127. // If it is a path relative to the current page.
  128. if ( isset($url[0]) && $url[0] != '/' && strpos($url, "://") === false )
  129. {
  130. $url = substr( $_SERVER[ 'REQUEST_URI' ], 0, strrpos( $_SERVER[ 'REQUEST_URI' ], '/' ) + 1 ) . $url ;
  131. }
  132. $url = $this->_BuildUrl( $url ) ;
  133. $qs = ( strpos($url, "?") !== false ) ? "&" : "?" ;
  134. if ( $this->Width !== '100%' && is_numeric( str_ireplace( "px", "", $this->Width ) ) )
  135. {
  136. $width = intval( $this->Width );
  137. $editorObj->Config['LinkBrowserWindowWidth'] = $width ;
  138. $editorObj->Config['ImageBrowserWindowWidth'] = $width ;
  139. $editorObj->Config['FlashBrowserWindowWidth'] = $width ;
  140. }
  141. if ( $this->Height !== 400 && is_numeric( str_ireplace( "px", "", $this->Height ) ) )
  142. {
  143. $height = intval( $this->Height );
  144. $editorObj->Config['LinkBrowserWindowHeight'] = $height ;
  145. $editorObj->Config['ImageBrowserWindowHeight'] = $height ;
  146. $editorObj->Config['FlashBrowserWindowHeight'] = $height ;
  147. }
  148. $editorObj->Config['LinkBrowserURL'] = $url ;
  149. $editorObj->Config['ImageBrowserURL'] = $url . $qs . 'type=' . ( empty( $imageType ) ? 'Images' : $imageType ) ;
  150. $editorObj->Config['FlashBrowserURL'] = $url . $qs . 'type=' . ( empty( $flashType ) ? 'Flash' : $flashType ) ;
  151. $dir = substr( $url, 0, strrpos( $url, "/" ) + 1 ) ;
  152. $editorObj->Config['LinkUploadURL'] = $dir . urlencode( 'core/connector/php/connector.php?command=QuickUpload&type=Files' ) ;
  153. $editorObj->Config['ImageUploadURL'] = $dir . urlencode( 'core/connector/php/connector.php?command=QuickUpload&type=') . ( empty( $imageType ) ? 'Images' : $imageType ) ;
  154. $editorObj->Config['FlashUploadURL'] = $dir . urlencode( 'core/connector/php/connector.php?command=QuickUpload&type=') . ( empty( $flashType ) ? 'Flash' : $flashType ) ;
  155. }
  156. // Static "SetupCKEditor".
  157. public static function SetupCKEditor( &$editorObj, $basePath = CKFINDER_DEFAULT_BASEPATH, $imageType = null, $flashType = null )
  158. {
  159. if ( empty( $basePath ) )
  160. $basePath = CKFINDER_DEFAULT_BASEPATH ;
  161. $ckfinder = new CKFinder( $basePath ) ;
  162. $ckfinder->SetupCKEditorObject( $editorObj, $imageType, $flashType );
  163. }
  164. // Non-static method of attaching CKFinder to CKEditor
  165. public function SetupCKEditorObject( &$editorObj, $imageType = null, $flashType = null )
  166. {
  167. $url = $this->BasePath ;
  168. // If it is a path relative to the current page.
  169. if ( isset($url[0]) && $url[0] != '/' && strpos($url, "://") === false )
  170. {
  171. $url = substr( $_SERVER[ 'REQUEST_URI' ], 0, strrpos( $_SERVER[ 'REQUEST_URI' ], '/' ) + 1 ) . $url ;
  172. }
  173. $url = $this->_BuildUrl( $url ) ;
  174. $qs = ( strpos($url, "?") !== false ) ? "&" : "?" ;
  175. if ( $this->Width !== '100%' && is_numeric( str_ireplace( "px", "", $this->Width ) ) )
  176. {
  177. $width = intval( $this->Width );
  178. $editorObj->config['filebrowserWindowWidth'] = $width ;
  179. }
  180. if ( $this->Height !== 400 && is_numeric( str_ireplace( "px", "", $this->Height ) ) )
  181. {
  182. $height = intval( $this->Height );
  183. $editorObj->config['filebrowserWindowHeight'] = $height ;
  184. }
  185. $editorObj->config['filebrowserBrowseUrl'] = $url ;
  186. $editorObj->config['filebrowserImageBrowseUrl'] = $url . $qs . 'type=' . ( empty( $imageType ) ? 'Images' : $imageType ) ;
  187. $editorObj->config['filebrowserFlashBrowseUrl'] = $url . $qs . 'type=' . ( empty( $flashType ) ? 'Flash' : $flashType ) ;
  188. $dir = substr( $url, 0, strrpos( $url, "/" ) + 1 ) ;
  189. $editorObj->config['filebrowserUploadUrl'] = $dir . 'core/connector/php/connector.php?command=QuickUpload&type=Files' ;
  190. $editorObj->config['filebrowserImageUploadUrl'] = $dir . 'core/connector/php/connector.php?command=QuickUpload&type=' . ( empty( $imageType ) ? 'Images' : $imageType ) ;
  191. $editorObj->config['filebrowserFlashUploadUrl'] = $dir . 'core/connector/php/connector.php?command=QuickUpload&type=' . ( empty( $flashType ) ? 'Flash' : $flashType ) ;
  192. }
  193. }