PageRenderTime 41ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/old/ckfinder/core/ckfinder_php4.php

https://gitlab.com/endomorphosis/falkenstein
PHP | 238 lines | 177 code | 39 blank | 22 comment | 40 complexity | af2cd7def71ebf23b58de2b1500b45e9 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. var $BasePath ;
  17. var $Width ;
  18. var $Height ;
  19. var $SelectFunction ;
  20. var $SelectFunctionData ;
  21. var $SelectThumbnailFunction ;
  22. var $SelectThumbnailFunctionData ;
  23. var $DisableThumbnailSelection = false ;
  24. var $ClassName = '' ;
  25. var $Id = '' ;
  26. var $ResourceType ;
  27. var $StartupPath ;
  28. var $RememberLastFolder = true ;
  29. var $StartupFolderExpanded = false ;
  30. // PHP 4 Constructor
  31. function CKFinder( $basePath = CKFINDER_DEFAULT_BASEPATH, $width = '100%', $height = 400, $selectFunction = null )
  32. {
  33. $this->BasePath = empty( $basePath ) ? CKFINDER_DEFAULT_BASEPATH : $basePath ;
  34. $this->Width = empty( $width ) ? '100%' : $width ;
  35. $this->Height = empty( $height ) ? 400 : $height ;
  36. $this->SelectFunction = $selectFunction ;
  37. $this->SelectThumbnailFunction = $selectFunction ;
  38. }
  39. // Renders CKFinder in the current page.
  40. function Create()
  41. {
  42. echo $this->CreateHtml() ;
  43. }
  44. // Gets the HTML needed to create a CKFinder instance.
  45. 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. 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. 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. function SetupFCKeditor( &$editorObj, $basePath = CKFINDER_DEFAULT_BASEPATH, $imageType = null, $flashType = null )
  117. {
  118. if ( empty( $basePath ) )
  119. $basePath = CKFINDER_DEFAULT_BASEPATH ;
  120. // If it is a path relative to the current page.
  121. if ( $basePath[0] != '/' )
  122. {
  123. $basePath = substr( $_SERVER[ 'REQUEST_URI' ], 0, strrpos( $_SERVER[ 'REQUEST_URI' ], '/' ) + 1 ) .
  124. $basePath ;
  125. }
  126. $ckfinder = new CKFinder( $basePath ) ;
  127. $ckfinder->SetupFCKeditorObject( $editorObj, $imageType, $flashType );
  128. }
  129. // Non-static method of attaching CKFinder to FCKeditor
  130. function SetupFCKeditorObject( &$editorObj, $imageType = null, $flashType = null )
  131. {
  132. $url = $this->BasePath ;
  133. // If it is a path relative to the current page.
  134. if ( isset($url[0]) && $url[0] != '/' && strpos($url, "://") === false )
  135. {
  136. $url = substr( $_SERVER[ 'REQUEST_URI' ], 0, strrpos( $_SERVER[ 'REQUEST_URI' ], '/' ) + 1 ) . $url ;
  137. }
  138. $url = $this->_BuildUrl( $url ) ;
  139. $qs = ( strpos($url, "?") !== false ) ? "&amp;" : "?" ;
  140. if ( $this->Width !== '100%' && is_numeric( str_replace( "px", "", strtolower( $this->Width ) ) ) )
  141. {
  142. $width = intval( $this->Width );
  143. $editorObj->Config['LinkBrowserWindowWidth'] = $width ;
  144. $editorObj->Config['ImageBrowserWindowWidth'] = $width ;
  145. $editorObj->Config['FlashBrowserWindowWidth'] = $width ;
  146. }
  147. if ( $this->Height !== 400 && is_numeric( str_replace( "px", "", strtolower( $this->Height ) ) ) )
  148. {
  149. $height = intval( $this->Height );
  150. $editorObj->Config['LinkBrowserWindowHeight'] = $height ;
  151. $editorObj->Config['ImageBrowserWindowHeight'] = $height ;
  152. $editorObj->Config['FlashBrowserWindowHeight'] = $height ;
  153. }
  154. $editorObj->Config['LinkBrowserURL'] = $url ;
  155. $editorObj->Config['ImageBrowserURL'] = $url . $qs . 'type=' . ( empty( $imageType ) ? 'Images' : $imageType ) ;
  156. $editorObj->Config['FlashBrowserURL'] = $url . $qs . 'type=' . ( empty( $flashType ) ? 'Flash' : $flashType ) ;
  157. $dir = substr( $url, 0, strrpos( $url, "/" ) + 1 ) ;
  158. $editorObj->Config['LinkUploadURL'] = $dir . urlencode( 'core/connector/php/connector.php?command=QuickUpload&type=Files' ) ;
  159. $editorObj->Config['ImageUploadURL'] = $dir . urlencode( 'core/connector/php/connector.php?command=QuickUpload&type=') . ( empty( $imageType ) ? 'Images' : $imageType ) ;
  160. $editorObj->Config['FlashUploadURL'] = $dir . urlencode( 'core/connector/php/connector.php?command=QuickUpload&type=') . ( empty( $flashType ) ? 'Flash' : $flashType ) ;
  161. }
  162. // Static "SetupCKEditor".
  163. function SetupCKEditor( &$editorObj, $basePath = CKFINDER_DEFAULT_BASEPATH, $imageType = null, $flashType = null )
  164. {
  165. if ( empty( $basePath ) )
  166. $basePath = CKFINDER_DEFAULT_BASEPATH ;
  167. $ckfinder = new CKFinder( $basePath ) ;
  168. $ckfinder->SetupCKEditorObject( $editorObj, $imageType, $flashType );
  169. }
  170. // Non-static method of attaching CKFinder to CKEditor
  171. function SetupCKEditorObject( &$editorObj, $imageType = null, $flashType = null )
  172. {
  173. $url = $this->BasePath ;
  174. // If it is a path relative to the current page.
  175. if ( isset($url[0]) && $url[0] != '/' && strpos($url, "://") === false )
  176. {
  177. $url = substr( $_SERVER[ 'REQUEST_URI' ], 0, strrpos( $_SERVER[ 'REQUEST_URI' ], '/' ) + 1 ) . $url ;
  178. }
  179. $url = $this->_BuildUrl( $url ) ;
  180. $qs = ( strpos($url, "?") !== false ) ? "&" : "?" ;
  181. if ( $this->Width !== '100%' && is_numeric( str_ireplace( "px", "", $this->Width ) ) )
  182. {
  183. $width = intval( $this->Width );
  184. $editorObj->config['filebrowserWindowWidth'] = $width ;
  185. }
  186. if ( $this->Height !== 400 && is_numeric( str_ireplace( "px", "", $this->Height ) ) )
  187. {
  188. $height = intval( $this->Height );
  189. $editorObj->config['filebrowserWindowHeight'] = $height ;
  190. }
  191. $editorObj->config['filebrowserBrowseUrl'] = $url ;
  192. $editorObj->config['filebrowserImageBrowseUrl'] = $url . $qs . 'type=' . ( empty( $imageType ) ? 'Images' : $imageType ) ;
  193. $editorObj->config['filebrowserFlashBrowseUrl'] = $url . $qs . 'type=' . ( empty( $flashType ) ? 'Flash' : $flashType ) ;
  194. $dir = substr( $url, 0, strrpos( $url, "/" ) + 1 ) ;
  195. $editorObj->config['filebrowserUploadUrl'] = $dir . 'core/connector/php/connector.php?command=QuickUpload&type=Files' ;
  196. $editorObj->config['filebrowserImageUploadUrl'] = $dir . 'core/connector/php/connector.php?command=QuickUpload&type=' . ( empty( $imageType ) ? 'Images' : $imageType ) ;
  197. $editorObj->config['filebrowserFlashUploadUrl'] = $dir . 'core/connector/php/connector.php?command=QuickUpload&type=' . ( empty( $flashType ) ? 'Flash' : $flashType ) ;
  198. }
  199. }