Changeset 565 for trunk/plugins/Linker


Ignore:
Timestamp:
09/13/06 15:50:09 (13 years ago)
Author:
gogo
Message:

Improvements to passing configuration to (php currently) Plugin backends.

This was prompted by #844, and numerous people having trouble with configuring ImageManager?.

A file has been added contrib/php-xinha.php (perhaps should be moved somewhere better),
this file contains functions which make it much easier to trustworthily pass data to
backends from the javascript frontend.

An example is easiest, imagine the following in your xinha setup, step 3...

with (xinha_config.ImageManager?)
{

<?php

require_once('/path/to/xinha/contrib/php-xinha.php');
xinha_pass_to_php_backend
(

array
(

'images_dir' => '/home/your/directory',
'images_url' => '/directory'

)

)

?>

}

that's all you need. It will (should at least) work with non-default session names also.

Location:
trunk/plugins/Linker
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/plugins/Linker/linker.js

    r429 r565  
    1717{ 
    1818  'backend' : _editor_url + 'plugins/Linker/scan.php', 
     19  'backend_data' : null, 
    1920  'files' : null 
    2021}; 
     
    327328    { 
    328329        //get files from backend 
    329         HTMLArea._getback(linker.lConfig.backend, 
     330        HTMLArea._postback(linker.lConfig.backend, 
     331                          linker.lConfig.backend_data, 
    330332                          function(txt) { 
    331333                            try { 
  • trunk/plugins/Linker/scan.php

    r133 r565  
    11<?php 
    2  
    32    // /home/username/foo/public_html/ 
    4     $dir = dirname(__FILE__)."/../.."; 
     3    $dir          = dirname(__FILE__)."/../.."; 
    54    $include      = '/\.(php|shtml|html|htm|shtm|cgi|txt|doc|pdf|rtf|xls|csv)$/'; 
    65    $exclude      = ''; 
     
    87    $direxclude   = '/(^|\/)[._]|htmlarea/'; // Exclude the htmlarea tree by default 
    98 
     9    // New backend config data passing 
     10    //  if data was passed using xinha_pass_to_backend() we extract and use it 
     11    //  as the items above     
     12    require_once(realpath(dirname(__FILE__) . '/../../contrib/php-xinha.php')); 
     13    if($passed_data = xinha_read_passed_data()) 
     14    { 
     15      extract($passed_data);       
     16    } 
     17 
     18    // Old deprecated backend config data passing 
     19    //  not described because you shouldn't use it. 
     20    //------------------------------------------------------------------------     
    1021    $hash = ''; 
    1122    foreach(explode(',', 'dir,include,exclude,dirinclude,direxclude') as $k) 
     
    3344      } 
    3445    } 
     46    //------------------------------------------------------------------------ 
     47 
    3548 
    3649    function scan($dir, $durl = '') 
     
    89102      return strcmp(strtolower($a), strtolower($b)); 
    90103    } 
    91  
    92     function to_js($var, $tabs = 0) 
    93     { 
    94       if(is_numeric($var)) 
    95       { 
    96         return $var; 
    97       } 
    98  
    99       if(is_string($var)) 
    100       { 
    101         return "'" . js_encode($var) . "'"; 
    102       } 
    103  
    104       if(is_array($var)) 
    105       { 
    106         $useObject = false; 
    107         foreach(array_keys($var) as $k) { 
    108             if(!is_numeric($k)) $useObject = true; 
    109         } 
    110         $js = array(); 
    111         foreach($var as $k => $v) 
    112         { 
    113           $i = ""; 
    114           if($useObject) { 
    115             if(preg_match('#[a-zA-Z]+[a-zA-Z0-9]*#', $k)) { 
    116               $i .= "$k: "; 
    117             } else { 
    118               $i .= "'$k': "; 
    119             } 
    120           } 
    121           $i .= to_js($v, $tabs + 1); 
    122           $js[] = $i; 
    123         } 
    124         if($useObject) { 
    125             $ret = "{\n" . tabify(implode(",\n", $js), $tabs) . "\n}"; 
    126         } else { 
    127             $ret = "[\n" . tabify(implode(",\n", $js), $tabs) . "\n]"; 
    128         } 
    129         return $ret; 
    130       } 
    131  
    132       return 'null'; 
    133     } 
    134  
    135     function tabify($text, $tabs) 
    136     { 
    137       if($text) 
    138       { 
    139         return str_repeat("  ", $tabs) . preg_replace('/\n(.)/', "\n" . str_repeat("  ", $tabs) . "\$1", $text); 
    140       } 
    141     } 
    142  
    143     function js_encode($string) 
    144     { 
    145       static $strings = "\\,\",',%,&,<,>,{,},@,\n,\r"; 
    146  
    147       if(!is_array($strings)) 
    148       { 
    149         $tr = array(); 
    150         foreach(explode(',', $strings) as $chr) 
    151         { 
    152           $tr[$chr] = sprintf('\x%02X', ord($chr)); 
    153         } 
    154         $strings = $tr; 
    155       } 
    156  
    157       return strtr($string, $strings); 
    158     } 
    159  
    160  
    161     echo to_js(scan($dir)); 
     104    
     105    echo xinha_to_js(scan($dir)); 
    162106?> 
Note: See TracChangeset for help on using the changeset viewer.