source: branches/unified_backend/plugins/Linker/scan.php @ 121

Last change on this file since 121 was 121, checked in by yermol, 14 years ago

htmlarea.js

. more debugging messages added.
. added HTMLArea.Config.linkReplacementMode which can be either

fullyqualified (the old default behavior) or absolute.


When set to fullyqualified all absolute links (e.g. /somepath) will be changed to fullyqualified URLS (e.g. http://yoursite/somepth).


When set to absolute, all fullyqualified urls back to the current site
will be changed to absolute (e.g. httpyoursite/somepath to /somepath)
making the Xinha generated content portable between sites.


( see HTMLArea.prototype.outwardHtml() )


. bugfix - if plugin .js file has a parse error htmlarea will only try to load

it a configurable number of times before popping up an error message.


backends/backend.php

. initial unified backend created. Requests to this backend are routed

to the corresponding plugin specific backend.php file.


backends/backend_conf.php

. a central server side configuration file has been created for the use

of plugin serverside code.

. all backends hooked into this scheme must include the central config file.

ImageManager?

. modified the config to allow overriding default values.
. default image directory is now xinha/examples/images
. added debugging trace messages which are tagged with the ImageManager? name.
. now uses unified backend.

Linker

. includes central config.
. default directory is now the xinha/examples directory (to avoid scan.php security

problem)

. added debugging trace messages which are tagged with the Linker name.
. links selected from the tree are now displayed in absolute instead of fully qualified

fashion.

. on edit the link that was previously selected is highlighted.
. on edit the selected link is scrolled to if it's outside the viewable area.
. if scan.php returns some kind of error or invalid javascript Linker now pops up

a nice descriptive error message.


. bugfix - same pattern as in loading plugins. If there is some error in loading the directory listing Linker will only attempt it a few times before giving up and

displaying a nice error.


dTree.js

. added clear_s() method to clear the selection
. added getNodeElement() method to return the <a ..> element for a given node.

  • Property svn:eol-style set to native
  • Property svn:keywords set to LastChangedDate LastChangedRevision LastChangedBy HeadURL Id
File size: 5.1 KB
Line 
1<?php
2
3/**
4* scan.php Linker backend
5*
6* @author James Sleeman
7* @author Yermo Lamers http://www.formvista.com/contact.html unified backend modifications.
8* @copyright Gogo Code http://code.gogo.co.nz
9*/
10
11/**
12* Xinha PHP backend master config file
13*
14* we assume the current working directory is plugins/Linker
15*/
16
17require_once( "../../backends/backend_conf.php" );
18
19/**
20* debugging library
21*/
22
23require_once( "../../ddt/ddt.php" );
24
25// by default we'll point linker at the examples document directory
26
27$dir          = XINHA_INSTALL_ROOT . "/examples";
28
29$include      = '/\.(php|shtml|html|htm|shtm|cgi|txt|doc|pdf|rtf|xls|csv)$/';
30$exclude      = '';
31$dirinclude   = '';
32$direxclude   = '/(^|\/)[._]|htmlarea/'; // Exclude the htmlarea tree by default
33
34// -------------------------------------------------------------------------------
35
36_ddt( __FILE__, __LINE__, "scan.php: top" );
37
38$hash = '';
39foreach(explode(',', 'dir,include,exclude,dirinclude,direxclude') as $k)
40        {
41        if (isset($_REQUEST[$k]))
42                {
43
44                if (get_magic_quotes_gpc())
45                        {
46                        $_REQUEST[$k] = stripslashes($_REQUEST[$k]);
47                        }
48
49                $hash .= $k . '=' . $_REQUEST[$k];
50                $$k = $_REQUEST[$k];
51                }
52        }
53
54if ($hash)
55        {
56        session_start();
57        if (!isset($_SESSION[sha1($hash)]))
58                {
59                ?>
60                [ ];
61                <?php
62                exit;
63      }
64    }
65
66// --------------------------------------------------------------
67
68/**
69* scan a directory
70*/
71
72function scan($dir, $durl = '')
73        {
74        global $include, $exclude, $dirinclude, $direxclude;
75        static $seen = array();
76
77        _ddt( __FILE__, __LINE__, "scan(): to with dir '" . $dir . "' and durl '" . $durl . "'" );
78
79        $files = array();
80
81        $dir = realpath($dir);
82
83        if(isset($seen[$dir]))
84                {
85                return $files;
86                }
87
88        $seen[$dir] = TRUE;
89        $dh = @opendir($dir);
90
91        while($dh && ($file = readdir($dh)))
92                {
93                if($file !== '.' && $file !== '..')
94                        {
95                        $path = realpath($dir . '/' . $file);
96                        $url  = $durl . '/' . $file;
97
98                        if(($dirinclude && !preg_match($dirinclude, $url)) || ($direxclude && preg_match($direxclude, $url))) continue;
99                        if(is_dir($path))
100                                {
101                                if($subdir = scan($path, $url))
102                                        {
103                                        $files[] = array('url'=>$url, 'children'=>$subdir);
104                                        }
105                                }
106                        elseif(is_file($path))
107                                {
108                                if(($include && !preg_match($include, $url)) || ($exclude && preg_match($exclude, $url))) continue;
109                                $files[] = array('url'=>$url);
110                                }
111
112                        }
113                }
114
115        @closedir($dh);
116
117        return dirsort($files);
118
119        }       // end of scan()
120
121// ----------------------------------------------------------------------
122
123/**
124* sort a directory
125*/
126
127function dirsort($files)
128        {
129        usort($files, 'dircomp');
130        return $files;
131        }
132
133// -----------------------------------------------------------------------
134
135/**
136* compare directory entries
137*/
138
139function dircomp($a, $b)
140        {
141
142        _ddt( __FILE__, __LINE__, "dircomp(): top" );
143
144        if(is_array($a))
145                {
146                _ddt( __FILE__, __LINE__, "dircomp(): a is a directory" );
147
148                foreach ( $a as $name => $value )
149                        _ddt( __FILE__, __LINE__, "dircomp(): $name => $value" );
150
151                $a = $a["url"];
152                }
153
154        if(is_array($b))
155                {
156                _ddt( __FILE__, __LINE__, "dircomp(): b is a directory" );
157
158                $b = $b["url"];
159                }
160
161        _ddt( __FILE__, __LINE__, "dircomp(): comparing '$a' with '$b'" );
162
163        return strcmp(strtolower($a), strtolower($b));
164
165        }       // end of dircomp()
166
167// ----------------------------------------------------------------------
168
169/**
170* generate javascript array
171*/
172
173function to_js( $var, $tabs = 0)
174        {
175
176        _ddt( __FILE__, __LINE__, "to_js(): top with var '$var'" );
177
178        if(is_numeric($var))
179                {
180                return $var;
181                }
182
183        if(is_string($var))
184                {
185                return "'" . js_encode($var) . "'";
186                }
187
188        if(is_array($var))
189                {
190                $useObject = false;
191                foreach(array_keys($var) as $k)
192                        {
193                        if(!is_numeric($k)) $useObject = true;
194                        }
195
196                $js = array();
197
198                foreach($var as $k => $v)
199                        {
200                        $i = "";
201
202                        if($useObject)
203                                {
204                                if(preg_match('#[a-zA-Z]+[a-zA-Z0-9]*#', $k))
205                                        {
206                                        $i .= "$k: ";
207                                        }
208                                else
209                                        {
210                                        $i .= "'$k': ";
211                                        }
212                                }
213                       
214                        $i .= to_js($v, $tabs + 1);
215                        $js[] = $i;
216                        }
217
218        if ($useObject)
219                        {
220                        $ret = "{\n" . tabify(implode(",\n", $js), $tabs) . "\n}";
221                        }
222                else
223                        {
224                        $ret = "[\n" . tabify(implode(",\n", $js), $tabs) . "\n]";
225                        }
226                return $ret;
227
228                }
229
230        return 'null';
231       
232        }       // end of to_js()
233
234// ------------------------------------------------------------------------
235
236/**
237* tabify()
238*/
239
240function tabify($text, $tabs)
241        {
242        if($text)
243                {
244                return str_repeat("  ", $tabs) . preg_replace('/\n(.)/', "\n" . str_repeat("  ", $tabs) . "\$1", $text);
245                }
246        }
247
248// ---------------------------------------------------------------------
249
250/**
251* js_encode()
252*/
253
254function js_encode($string)
255        {
256        static $strings = "\\,\",',%,&,<,>,{,},@,\n,\r";
257
258        if(!is_array($strings))
259                {
260                $tr = array();
261                foreach(explode(',', $strings) as $chr)
262                        {
263                        $tr[$chr] = sprintf('\x%02X', ord($chr));
264                        }
265                $strings = $tr;
266                }
267
268        return strtr($string, $strings);
269        }
270
271/**
272* send out the resulting javascript array.
273*/
274
275$javascript_array = to_js(scan($dir));
276
277// if you want to see what's communicated back to the browser uncomment this. You will
278// get the output in an error popup.
279//
280// _ddtOn();
281
282_ddt( __FILE__, __LINE__, "scan.php: Resulting array is '" + $javascript_array + "'" );
283
284echo $javascript_array;
285
286// END
287?>
Note: See TracBrowser for help on using the repository browser.