Advertisement
Guest User

Ckfinder

a guest
Aug 5th, 2012
13,981
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.16 KB | None | 0 0
  1. <?php
  2. /*
  3.  * CKFinder
  4.  * ========
  5.  * http://ckfinder.com
  6.  * Copyright (C) 2007-2011, 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.  
  14. define( 'CKFINDER_DEFAULT_BASEPATH', '/ckfinder/' ) ;
  15.  
  16. class CKFinder
  17. {
  18.     public $BasePath ;
  19.     public $Width ;
  20.     public $Height ;
  21.     public $SelectFunction ;
  22.     public $SelectFunctionData ;
  23.     public $SelectThumbnailFunction ;
  24.     public $SelectThumbnailFunctionData ;
  25.     public $DisableThumbnailSelection = false ;
  26.     public $ClassName = '' ;
  27.     public $Id = '' ;
  28.     public $StartupPath ;
  29.     public $ResourceType ;
  30.     public $RememberLastFolder = true ;
  31.     public $StartupFolderExpanded = false ;
  32.  
  33.     // PHP 5 Constructor
  34.     function __construct( $basePath = CKFINDER_DEFAULT_BASEPATH, $width = '100%', $height = 400, $selectFunction = null )
  35.     {
  36.         $this->BasePath         = $basePath ;
  37.         $this->Width            = $width ;
  38.         $this->Height           = $height ;
  39.         $this->SelectFunction   = $selectFunction ;
  40.         $this->SelectThumbnailFunction  = $selectFunction ;
  41.     }
  42.  
  43.     // Renders CKFinder in the current page.
  44.     public function Create()
  45.     {
  46.         echo $this->CreateHtml() ;
  47.     }
  48.  
  49.     // Gets the HTML needed to create a CKFinder instance.
  50.     public function CreateHtml()
  51.     {
  52.         $className = $this->ClassName ;
  53.         if ( !empty( $className ) )
  54.             $className = ' class="' . $className . '"' ;
  55.  
  56.         $id = $this->Id ;
  57.         if ( !empty( $id ) )
  58.             $id = ' id="' . $id . '"' ;
  59.  
  60.         return '<iframe src="' . $this->_BuildUrl() . '" width="' . $this->Width . '" ' .
  61.             'height="' . $this->Height . '"' . $className . $id . ' frameborder="0" scrolling="no"></iframe>' ;
  62.     }
  63.  
  64.     private function _BuildUrl( $url = "" )
  65.     {
  66.         if ( !$url )
  67.             $url = $this->BasePath ;
  68.  
  69.         $qs = "" ;
  70.  
  71.         if ( empty( $url ) )
  72.             $url = CKFINDER_DEFAULT_BASEPATH ;
  73.  
  74.         if ( $url[ strlen( $url ) - 1 ] != '/' )
  75.             $url = $url . '/' ;
  76.  
  77.         $url .= 'ckfinder.html' ;
  78.  
  79.         if ( !empty( $this->SelectFunction ) )
  80.             $qs .= '?action=js&amp;func=' . $this->SelectFunction ;
  81.  
  82.         if ( !empty( $this->SelectFunctionData ) )
  83.         {
  84.             $qs .= $qs ? "&amp;" : "?" ;
  85.             $qs .= 'data=' . rawurlencode($this->SelectFunctionData) ;
  86.         }
  87.  
  88.         if ( $this->DisableThumbnailSelection )
  89.         {
  90.             $qs .= $qs ? "&amp;" : "?" ;
  91.             $qs .= "dts=1" ;
  92.         }
  93.         else if ( !empty( $this->SelectThumbnailFunction ) || !empty( $this->SelectFunction ) )
  94.         {
  95.             $qs .= $qs ? "&amp;" : "?" ;
  96.             $qs .= 'thumbFunc=' . ( !empty( $this->SelectThumbnailFunction ) ? $this->SelectThumbnailFunction : $this->SelectFunction ) ;
  97.  
  98.             if ( !empty( $this->SelectThumbnailFunctionData ) )
  99.                 $qs .= '&amp;tdata=' . rawurlencode( $this->SelectThumbnailFunctionData ) ;
  100.             else if ( empty( $this->SelectThumbnailFunction ) && !empty( $this->SelectFunctionData ) )
  101.                 $qs .= '&amp;tdata=' . rawurlencode( $this->SelectFunctionData ) ;
  102.         }
  103.  
  104.         if ( !empty( $this->StartupPath ) )
  105.         {
  106.             $qs .= ( $qs ? "&amp;" : "?" ) ;
  107.             $qs .= "start=" . urlencode( $this->StartupPath . ( $this->StartupFolderExpanded ? ':1' : ':0' ) ) ;
  108.         }
  109.  
  110.         if ( !empty( $this->ResourceType ) )
  111.         {
  112.             $qs .= ( $qs ? "&amp;" : "?" ) ;
  113.             $qs .= "type=" . urlencode( $this->ResourceType ) ;
  114.         }
  115.  
  116.         if ( !$this->RememberLastFolder )
  117.         {
  118.             $qs .= ( $qs ? "&amp;" : "?" ) ;
  119.             $qs .= "rlf=0" ;
  120.         }
  121.  
  122.         if ( !empty( $this->Id ) )
  123.         {
  124.             $qs .= ( $qs ? "&amp;" : "?" ) ;
  125.             $qs .= "id=" . urlencode( $this->Id ) ;
  126.         }
  127.  
  128.         return $url . $qs ;
  129.     }
  130.  
  131.     // Static "Create".
  132.     public static function CreateStatic( $basePath = CKFINDER_DEFAULT_BASEPATH, $width = '100%', $height = 400, $selectFunction = null )
  133.     {
  134.         $finder = new CKFinder( $basePath, $width, $height, $selectFunction ) ;
  135.         $finder->Create() ;
  136.     }
  137.  
  138.     // Static "SetupFCKeditor".
  139.     public static function SetupFCKeditor( &$editorObj, $basePath = CKFINDER_DEFAULT_BASEPATH, $imageType = null, $flashType = null )
  140.     {
  141.         if ( empty( $basePath ) )
  142.             $basePath = CKFINDER_DEFAULT_BASEPATH ;
  143.  
  144.         $ckfinder = new CKFinder( $basePath ) ;
  145.         $ckfinder->SetupFCKeditorObject( $editorObj, $imageType, $flashType );
  146.     }
  147.  
  148.     // Non-static method of attaching CKFinder to FCKeditor
  149.     public function SetupFCKeditorObject( &$editorObj, $imageType = null, $flashType = null )
  150.     {
  151.         $url = $this->BasePath ;
  152.  
  153.         // If it is a path relative to the current page.
  154.         if ( isset($url[0]) && $url[0] != '/' )
  155.         {
  156.             $url = substr( $_SERVER[ 'REQUEST_URI' ], 0, strrpos( $_SERVER[ 'REQUEST_URI' ], '/' ) + 1 ) . $url ;
  157.         }
  158.  
  159.         $url = $this->_BuildUrl( $url ) ;
  160.         $qs = ( strpos($url, "?") !== false ) ? "&" : "?" ;
  161.  
  162.         if ( $this->Width !== '100%' && is_numeric( str_ireplace( "px", "", $this->Width ) ) )
  163.         {
  164.             $width = intval( $this->Width );
  165.             $editorObj->Config['LinkBrowserWindowWidth'] = $width ;
  166.             $editorObj->Config['ImageBrowserWindowWidth'] = $width ;
  167.             $editorObj->Config['FlashBrowserWindowWidth'] = $width ;
  168.         }
  169.         if ( $this->Height !== 400 && is_numeric( str_ireplace( "px", "", $this->Height ) ) )
  170.         {
  171.             $height = intval( $this->Height );
  172.             $editorObj->Config['LinkBrowserWindowHeight'] = $height ;
  173.             $editorObj->Config['ImageBrowserWindowHeight'] = $height ;
  174.             $editorObj->Config['FlashBrowserWindowHeight'] = $height ;
  175.         }
  176.  
  177.         $editorObj->Config['LinkBrowserURL'] = $url ;
  178.         $editorObj->Config['ImageBrowserURL'] = $url . $qs . 'type=' . ( empty( $imageType ) ? 'Images' : $imageType ) ;
  179.         $editorObj->Config['FlashBrowserURL'] = $url . $qs . 'type=' . ( empty( $flashType ) ? 'Flash' : $flashType ) ;
  180.  
  181.         $dir = substr( $url, 0, strrpos( $url, "/" ) + 1 ) ;
  182.         $editorObj->Config['LinkUploadURL'] = $dir . urlencode( 'core/connector/php/connector.php?command=QuickUpload&type=Files' ) ;
  183.         $editorObj->Config['ImageUploadURL'] = $dir . urlencode( 'core/connector/php/connector.php?command=QuickUpload&type=') . ( empty( $imageType ) ? 'Images' : $imageType ) ;
  184.         $editorObj->Config['FlashUploadURL'] = $dir . urlencode( 'core/connector/php/connector.php?command=QuickUpload&type=') . ( empty( $flashType ) ? 'Flash' : $flashType ) ;
  185.     }
  186.  
  187.     // Static "SetupCKEditor".
  188.     public static function SetupCKEditor( &$editorObj, $basePath = CKFINDER_DEFAULT_BASEPATH, $imageType = null, $flashType = null )
  189.     {
  190.         if ( empty( $basePath ) )
  191.             $basePath = CKFINDER_DEFAULT_BASEPATH ;
  192.  
  193.         $ckfinder = new CKFinder( $basePath ) ;
  194.         $ckfinder->SetupCKEditorObject( $editorObj, $imageType, $flashType );
  195.     }
  196.  
  197.     // Non-static method of attaching CKFinder to CKEditor
  198.     public function SetupCKEditorObject( &$editorObj, $imageType = null, $flashType = null )
  199.     {
  200.         $url = $this->BasePath ;
  201.  
  202.         // If it is a path relative to the current page.
  203.         if ( isset($url[0]) && $url[0] != '/' )
  204.         {
  205.             $url = substr( $_SERVER[ 'REQUEST_URI' ], 0, strrpos( $_SERVER[ 'REQUEST_URI' ], '/' ) + 1 ) . $url ;
  206.         }
  207.  
  208.         $url = $this->_BuildUrl( $url ) ;
  209.         $qs = ( strpos($url, "?") !== false ) ? "&" : "?" ;
  210.  
  211.         if ( $this->Width !== '100%' && is_numeric( str_ireplace( "px", "", $this->Width ) ) )
  212.         {
  213.             $width = intval( $this->Width );
  214.             $editorObj->config['filebrowserWindowWidth'] = $width ;
  215.         }
  216.         if ( $this->Height !== 400 && is_numeric( str_ireplace( "px", "", $this->Height ) ) )
  217.         {
  218.             $height = intval( $this->Height );
  219.             $editorObj->config['filebrowserWindowHeight'] = $height ;
  220.         }
  221.  
  222.         $editorObj->config['filebrowserBrowseUrl'] = $url ;
  223.         $editorObj->config['filebrowserImageBrowseUrl'] = $url . $qs . 'type=' . ( empty( $imageType ) ? 'Images' : $imageType ) ;
  224.         $editorObj->config['filebrowserFlashBrowseUrl'] = $url . $qs . 'type=' . ( empty( $flashType ) ? 'Flash' : $flashType ) ;
  225.  
  226.         $dir = substr( $url, 0, strrpos( $url, "/" ) + 1 ) ;
  227.         $editorObj->config['filebrowserUploadUrl'] = $dir . 'core/connector/php/connector.php?command=QuickUpload&type=Files' ;
  228.         $editorObj->config['filebrowserImageUploadUrl'] = $dir . 'core/connector/php/connector.php?command=QuickUpload&type=' . ( empty( $imageType ) ? 'Images' : $imageType ) ;
  229.         $editorObj->config['filebrowserFlashUploadUrl'] = $dir . 'core/connector/php/connector.php?command=QuickUpload&type=' . ( empty( $flashType ) ? 'Flash' : $flashType ) ;
  230.     }
  231. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement