Project

General

Profile

« Previous | Next » 

Revision 503

Added by ryan over 17 years ago

Created 2.6.6 tag

View differences:

tags/2.6.6/CHANGELOG
1
Change Log
2
===============================================================================
3
Please note: This change log may not be accurate
4

  
5
$Id$
6

  
7
Legend:
8
+ = Added
9
- = Removed
10
# = Bugfix
11
! = Update/Change
12

  
13
------------------------------------- 2.6.6 -------------------------------------
14
01-Jul-2007 Ryan Djurovich
15
#	Fixed bug where error message not displayed when script fails to create a page
16
#	Fixed bugs introduced in [484]
17
14-May-2007 Matthias Gallas
18
+	Added support for ISO-8859-6.(Thanks to thorn)
19
12-May-2007 Christian Sommer
20
+	Replaced functions page_css and page_javascript by register_frontend_modfiles
21
+	Added function register_backend_modfiles to allow backend modules to use optional CSS and JS files
22
+	Added the JS framework codepress to allow syntax highlighting for JS, HTML, PHP code (textarea)
23
+	Added the new function register_frontend_modfiles to the built in templates
24
08-May-2007 Matthias Gallas
25
+	Added wrapper to functions.php if mb_string is not available (Thanks to thorn)
26
+	Added new functions page_css and page_javascript to the built in templates
27
+	Added search highlight class to css files of the built in templates
28
30-Apr-2007 Matthias Gallas
29
#	Fixed ticket #392; root_parent not being set correctly (Thanks to eggsurplus)
30
10-Apr-2007 Matthias Gallas
31
+	Optimized search and highlighting funktions (Thanks to thorn)
32
03-Apr-2007 Matthias Gallas
33
#	Fixed a bug in menulink; if you deleted a menulink page the linked page was also deleted
34
	in the pages directory (Special thanks to "Funky_MF" for the fix)
35
01-Apr-2007 Matthias Gallas
36
#	Fixed issues with some languages when UTF8 is used. Removed all htmlentites
37
	from the code (revoked changeset 396) and added new functions instead. Adapted the
38
	search and the highlighting to use the new functions. With this changes WB can now
39
	be used with charset UTF8 for all languages. Very special thanks to Thorn who wrote
40
	and tested this changes.
41
12-Mar-2007 Matthias Gallas
42
+	Added multilingual support to search
43
03-Mar-2007 Matthias Gallas
44
+	Added new function for highlighting search results in the content area
45
	(Special thanks to "thorn" and "Funky_MF")
46
#	Fixed some issues in search with special chars
47
	(Special thanks to "thorn" and "Funky_MF")
48
22-Feb-2007 Christian Sommer
49
#	Fixed bug in changeset 428 (page files were not deleted in /pages folder due to a typo in wb/framework/function.php)
50
16-Feb-2007 Christian Sommer
51
!	Suppressed PHP warnings and errors when reading empty intro.php
52
16-Feb-2007 Christian Sommer
53
#	Applied fix to enable parsing of PHP code in the intro.php 
54
12-Feb-2007 Christian Sommer
55
!	Added functions page_css and page_javascript which allow to include optional
56
	module files module.css and module.js into the <head> section. This allows to 
57
	create valid (X)HTML, as CSS definitions of modules are included in the head section
58
12-Feb-2007 Christian Sommer
59
!	Security enhancement (reduced number of login trials from 50 to 3)
60
02-Feb-2007 Matthias Gallas
61
#	Applied fix for ticket #380 (Thanks to pcwacht)
62
30-Jan-2007 Ryan Djurovich
63
#	Applied fix for ticket #376
64
29-Jan-2007 Matthias Gallas
65
+	Added new variable $MODULE_DESCRIPTION wich allows to have optional a language
66
	specific description of the modules in the language files of the modules.
67
21-Jan-2007 Matthias Gallas
68
#	Fixed issue in the search table entries of form modul
69
13-Jan-2007 Matthias Gallas
70
#	Fixed some bugs in rss.php
71
07-Jan-2007 Matthias Gallas
72
#	Fixed error when uninstalling the news modul
73
02-Jan-2007 Matthias Gallas
74
+   Added id keywords to all missing files
75
#	Fixed issue with Permissions for pages sections
76
27-Dec-2006 Matthias Gallas
77
#	Fixed form modul stores empty records
78
------------------------------------- 2.6.5 -------------------------------------
79
25-Dec-2006 Ryan Djurovich
80
!	Changed links to WB help website
81
24-Dec-2006 Matthias Gallas
82
#	Fixed some minor javascript errors in admin (thanks to pcwacht)
83
#	Fixed root_parent doesn't get updated when moving item in menu (#305)
84
!	Changed all copyright notices to include now 2007
85
23-Dec-2006 Matthias Gallas
86
#	Fixed IE allows to set a page as parent of itself (#320)
87
#	Fixed problem with Page Title has to be escaped (#287)
88
#	Fixed the possibility to call the index.php of the templates directly in the browser (#291)
89
21-Dec-2006 Matthias Gallas
90
#	Fixed missing message when adding a site without page title (#300)
91
21-Dec-2006 Ryan Djurovich
92
#	Fixed bug with captcha script (#346)
93
20-Dec-2006 Matthias Gallas
94
#	Fixed Return to Search Results Page (#365)
95
!	Set Version to 2.6.5
96
-	Removed Changeset 365 because this will be a part of WB 2.7.x
97
#	Fixed a little typo error in class.admin.php (#364)
98
26-Nov-2006 Ryan Djurovich
99
+	Added new script that could possibly be apart of 2.7.x as a replacement
100
	for having the pages directory 
101
17-Nov-2006 Matthias Gallas
102
#	Fixed fatal error in line 46 news/comment.php (thanks to eki)(#358)
103
15-Nov-2006 Matthias Gallas
104
#	Fixed again intropage doesn't work (#71)
105
20-Oct-2006 Matthias Gallas
106
+	Added phpmailer class (thanks to doc)
107
+	Added Remember-expanded-pages-in-admin (thanks to ephraimt)
108
+	Added List sorting in admin area (thanks to rsmith)
109
#	Fixed table width 100% are wrong displayed in container templates
110
	when IE is used (#350)
111
#	Fixed large space between menupoints in IE (#349)
112
#	Fixed Website description is not displayed when no page description
113
	available (#348)
114
#	Fixed group images in news modul cannot be stored (#342)
115
#	Fixed Typo in form/save_field.php (#341)
116
#	Fixed files in /pages/posts folder are not deleted (#340)
117
#	Fixed specialchars problem in the news modul (#339)
118
#	Fixed news modul stores empty records (#338)
119
#	Fixed Captcha didn't work in news comments (#337)
120
#	Fixed various php notices (#334)
121
+	Added new upgrade_function (thanks to kozmoz)
122
#	Fixed addons table isn't updated when a modul is updated (#332)
123
#	Fixed spelling errors in the signup2.php (#330)
124
#	Fixed MySQL 5.x missing default values for INT fields in all system
125
	and modules tables (#329)
126
#	Fixed installer does not insert admin user (#328)
127
+	Added support for getting page ID of page that referred search
128
	request (#327) (thanks to brofield)
129
#	Fixed search results generate invalid XHTML and notify warnings (#326)
130
Stefan Braunewell
131
#	Fixed Field 'last_reset' doesn't have a default value (#313)
132
+	Added get_post_escaped to wb class which automatically calls add_slashes
133
	on get_post output and used it in form/save_field.php
134
------------------------------------- 2.6.4 -------------------------------------
135
20-May-2006 Ryan Djurovich
136
#	Fixed security issues related to #237
137
#	Fixed typo in news save comment page (#282)
138
#	Fixed typo in news delete post page (#283)
139
!	Added multi-submission protection to form module (#119)
140
#	Added notice for when PHP Session Support appears to be disabled in installer,
141
	even if it is enabled and the problem actually lies in the users browser (#154)
142
19-May-2006 Ryan Djurovich
143
#	Fixed problem in forgotten login form where email field is too short (#207)
144
#	Fixed typo in forgotten login details email (#190)
145
15-May-2006 Stefan Braunewell
146
#	Fixed security issues (#237)
147
03-May-2006 Stefan Braunewell
148
#	Fixed problems with pre-2.6.0 modules in section list
149
#	Fixed e-mail bug caused by From: headers in internal mail function calls
150
	(#189)
151
#	E-mail validation in install script now accepts new top-level domains
152
	(#162)
153
#	Error status is now overwritten by next database query (#182)
154
#	Fixed obscure problem in htmlarea install script
155
------------------------------------- 2.6.3 -------------------------------------
156
19-Mar-2006 Stefan Braunewell
157
#	Fixed ticket #146: problems removing groups from viewers list of a page
158
16-Mar-2006 Stefan Braunewell
159
!	Changed link target selection. Now self, top and new. (Ticket #145)
160
#	Fixed ticket #143. Charset setting is now used in admin login and forgot
161
	password pages.
162
#	Some changes to the SQL code in the install script for improved 
163
	compatibility with new MySQL versions
164
#	Fixed ticket #134 - error on browsing media.
165
+	Improved backup module: new choice between full database or WB-related
166
	backup.
167
#	Fixed ticket #141 - admin now sees all folders in media
168
#	Fixed e-mail sending problems due to additional parameter in mail call.
169
#	Applied fix regarding ticket #138: new users now get deleted if
170
	sending e-mail fails.
171
#	Fixed ticket #137: Last Reset timer not reset in frontend forgotten 
172
	password process
173
#	Removed duplicate expression from modules/news/install.php which caused
174
	problems in installation
175

  
176
01-Mar-2006 Stefan Braunewell
177
#	Fixed ticket #68 - Safari problem with displaying all parents.
178
#	Fixed ticket #136 - mailing forgotten password in admin login screen leads 
179
	to fatal error.
180
!	Renamed tag [PROCESSTIME] to [PROCESS_TIME]
181
------------------------------------- 2.6.2 -------------------------------------
182
03-Feb-2006 Stefan Braunewell (very big special thanks to John and Alex)
183
#	Fixed ticket #104 - commas in form field descriptions not allowed.
184
#	Cookie REMEMBER_KEY wasn't cleared in account/logout 
185
	and expiration date is now set to time in the past.
186
#	Smart login not working.
187
!	Changed mail calls to new function $wb->mail.
188
#	Form: ticket 124 added captcha settings check 
189
#	Ticket 118 added formfield type to check for email/text 
190
#	Ticket 115 changed comparision /modules/form/view.php 
191
#	Added correct timecheck in form submissions
192
!	Changed captcha.php call to include timestamp
193
!	Changed the e-mail validation code and added a mail function to class wb.
194
!	Forgotten password: if sending of e-mail fails, restore old password.
195
	Ticket #110
196
!	Added more charset options. Ticket #102 - thanks to ruebenwurzel!
197
!	Character encoding setting also affects admin backend.
198
	Mentioned in ticket #102.
199
!	Reintroduced page languages setting. If switched to off, page
200
	languages are only used to determine the language file for the
201
	universal texts. If on, displayed page and menu are affected by
202
	the language session variable.
203
#	Fixed bugs in show_breadcrumbs code and added parameter "depth"
204
	to set the number of levels to be show.
205
#	Fixed a bug where access settings of registered and private pages
206
	were displayed incorrectly.
207
#	Fixed captcha being cached.
208
#	Added an exit call after every heading("Location:...")
209
	redirector to prevent unwanted execution of code.
210
#	Bug #122. Replaced empty field check by check that setting name is
211
	not "wb_version".
212
#	Replaced all remaining occurrences of '/media' by MEDIA_DIRECTORY - bug #108.
213
#	Fixed bug #99 and two additional instances of typo 
214
	catpcha instead of captcha.
215
#	Fixed some typos
216
#	Fixed some notices and warnings.
217
#	Fixed bug #105 - back buttons in addon detail pages not editable.
218
!	Replace 'admin' by 'wb' in all account pages. 
219
!/#	Moved print_success and print_error code to class.wb.php.
220
	Added correct parameters to these functions in account pages. 
221
------------------------------------- 2.6.1 -------------------------------------
222
12-Dec-2005 Ryan Djurovich
223
#	Fixed security vulnerability in class.login.php
224
#	Fixed typo in EN language file
225
#	Fixed captcha problems (when feature is disabled) in form module and sign-up
226
!	Added charset encoding to admin templates
227
!	Added extra code to check for selection of addon upon uninstalling
228
#	Fixed bugs in RSS news feeder
229
#	Fixed bug with PAGE_DESCRIPTION not being set on any page
230
------------------------------------- 2.6.0 -------------------------------------
231
28-Nov-2005 Ryan Djurovich
232
+	Added default charset option to (advanced) settings
233
#	Form module email fields now have email address validation
234
#	Fixed spacing in form submissions
235
27-Nov-2005 Ryan Djurovich
236
+	Added captcha verification to sign-up form
237
+	Added Captcha to News module
238
24-Nov-2005 Stefan Braunewell
239
!	Applied aportale's patch to use label instead of javascript toggle code
240
20-Nov-2005 Ryan Djurovich
241
!	News mod now hides read more link if no need for it (see ticket #56)
242
+	Added support for mailto: links in the menu link mod
243
#	Added direct-access redirection on some files (see ticket #37)
244
+	Added extra characters to convert.php (see ticket #64)
245
#	Fixed ticket #65 (last_reset check in account/forgot_form.php)
246
29-Sep-2005 Ryan Djurovich
247
!	Cleaned up form buttons in Settings
248
!	Moved some options into Advanced Settings
249
#	Semi-disabled "separate" page trash option
250
+	Created a backup module/tool for backing-up the database
251
	(thanks to John (pcwacht) for the original code)
252
+	Created new "blank template", which can be used in case where you don't
253
	want anything wrapping page-content.
254
19-Sep-2005 Ryan Djurovich
255
+	Added _license field for all add-ons to specify a license
256
!	Renamed _designed_for variables (for all addons) to _platform
257
+	Created addons table for faster internal referencing of installed addons
258
!	Fixed some links, including the "Help" button in Admin
259
#	Used nl2br to display body correctly when viewing form-submissions
260
15-Sep-2005 Stefan Braunewell
261
+	Added table module with columns 'name','type' and 'directory' as an
262
	index.
263
+	Added entry to settings table 'wb_version' which holds the version
264
	number and can be utilized in future upgrade scripts.
265
!	Added upgrade functionality also for templates and languages.
266
#/!	Template/modules installation now respects paths.
267
!	Moved updates from config.php to database.
268
	Created initialize.php (required by config.php) to read settings.
269
11-Sep-2005 Stefan Braunewell
270
!	HTMLArea is now a module instead of a core component. Files moved
271
	from "include" to "modules".
272
+	Implemented Installation of modules on top of an older version. This is 
273
	done via checking $module_version. Instead of install.php, upgrade.php
274
	is then called if it exists in the module package. 
275
	For module developers: $module_version and $new_module_version are 
276
	accessible in upgrade.php to find out what upgrade steps need to be taken.
277
!	Changed column names in mod_news_posts from short,long to content_short,
278
	content_long.
279
09-Sep-2005 Stefan Braunewell
280
+	Added new advanced setting "Rename Files On Upload". File extensions can be
281
	given so that respective files will have a ".txt" appended on media upload.
282
#	Fixed "None found" message bug when user has no top level page edit
283
	rights.
284
#	Fixed missing parent option 'none' - ticket #12 - and a minor scope bug.
285
+	Added breadcrumbs code. Call using $wb->breadcrumbs().
286
+	Added utf-8 character encoding meta tag into all stock templates.
287
#	Fixed bug when changing a page's parent
288
!	Changed the way blocks are treated. Added new frontend class attribute
289
	default_block_content that controls what is shown on pages such as
290
	search, login, etc. (Ticket #16)
291
+	Added support for WYSIWYG editor modules (wysiwygmod)
292
+	When trying to access a registered page, user is automatically redirected
293
	there on successful login.
294
#	Fixed various issues with system search (mainly related to stripslashes()
295
#	Removed stripslashes() in many places in the code. Added check for
296
	magic_quotes_gpc to new wb class method add_slashes(). Now database contest
297
	is independent of magic_quotes setting..
298
05-Sep-2005 Stefan Braunewell
299
#	Fixed bug concerning direct access of preferences page.
300
#	Reworked page visibility and menu item visibility code (frontend login
301
	problem).
302
#	Pages in link list in htmlarea popup are now correctly ordered.
303
#	Fixed bug where group with existing name can be added.
304
04-Sep-2005 Ryan Djurovich
305
+	Added and RSS newsfeed script to the News module
306
04-Sep-2005 Stefan Braunewell
307
!	Rewrote menu function. Parameters are now given as attributes to frontend class.
308
#	Fixed some occurrences of potential direct access path disclosure
309
#	Added directory check to browse.php to prevent xss exploit by trusted users.
310
!	Updated code to reflect move to Subversion repository system.
311
27-Aug-2005 Stefan Braunewell
312
#	Fixed bugs 4,5,6,8,9 in bug tracker
313
!	Removed 'USER_LANGUAGE' and 'GET_LANGUAGE' constants.
314
	A GET['lang'] now sets the session language variable.
315
26-Aug-2005 Stefan Braunewell
316
!	Moved redundant code into the new class functions. Created 
317
	'compatibility.php' for backward compatibility with
318
	modules and templates. Variables and functions can still be accessed
319
	in the old way.
320
!/+	Reorganized core frontend files, added new base class 'wb' from
321
	which 'admin' and the new 'frontend' class inherit. Moved all frontend
322
	function into new class. Completely rewrote core index.php.
323
	Now all variables and functions that are available to templates and
324
	modules are attributes and methods of the frontend and the wb classes
325
------------------------------------- 2.5.2 -------------------------------------
326
23-Jun-2005 Ryan Djurovich
327
!	create_access_file now creates all parent directories if needed
328
#	Fixed bug when moving page with subpages to another level
329
#	Fixed bug when saving "Settings" (in Admin) on Windows/IIS
330
#	Fixed bug where query was not setting error correctly in class.database.php
331
22-Jun-2005 Ryan Djurovich
332
#	Fixed bug where template permissions were not saved when a adding group
333
21-Jun-2005 Ryan Djurovich
334
#	Added htmlspecialchars for modifying WYSIWYG, news, etc. modules (Bug #78)
335
#	Fixed language problems in some area's of Admin. (Bug #70)
336
#	Added a space in website/page keywords (Bug #69)
337
#	Fixed bugs on settings2.php (Bug #52)
338
!	Links inserted with HTMLArea now use [wblink--PAGE_ID--] instead of raw URL
339
13-Jun-2005 Ryan Djurovich
340
#	Fixed bug (#88) with news module
341
!	Title of Administration login page now taken from language file (Bug #72)
342
#	Fixed redirection admin/home to admin/start on admin/index.php
343
#	Fixed bug with forgotten password page in admin (Bug #81)
344
25-Apr-2005 Ryan Djurovich
345
#	Fixed numerous bugs with module uninstallation
346
#	Fixed bug when uploading files in Administration -> Media
347
!	Installer no-longer requires you to accept the GNU GPL
348
------------------------------------- 2.5.1 -------------------------------------
349
16-Apr-2005 Ryan Djurovich
350
#	Fixed two bugs with account login/logout
351
------------------------------------- 2.5.1 -------------------------------------
352
15-Apr-2005 Ryan Djurovich
353
#	Fixed bug where non-english characters can get used in page filenames. Many
354
	measuers have been added (including a new file: wb/framework/convert.php),
355
	to prevent any possible errors that can occur in page filenames.
356
#	Fixed invalid meta tags in stock templates (meta tags were not closed)
357
#	Removed lines 401, 402, and 425 of wb/index.php - not needed
358
#	Fixed bug where search and account pages are shown in every block
359
	that is in a template
360
#	Fixed numerous bugs with media home directories feature
361
10-Apr-2005 Ryan Djurovich
362
#	Fixed bugs in account/login.php and logout.php where users
363
	gets redirected to /pages
364
------------------------------------- 2.5.0 -------------------------------------
365
08-Apr-2005 Ryan Djurovich
366
-	Removed section language feature
367
+	Added page language feature (replaces need for sections language feature)
368
#	Fixed bug where pages using menu_link module can have the URL changed
369
-	Page directory no longer stored in link field in pages table, it is now added
370
	when the page_link function is called - this makes changing the pages
371
	directory much easier and quicker
372
!	Pages with visibility of "none" are now no longer directly accessable
373
+	Added new visibility setting "hidden", acts exactly like none did previously
374
!	Template info file can now specify number of menu's available and relative names
375
!	Template info file can now specify number of blocks's available and relative names
376
------------------------------------- 2.4.3 -------------------------------------
377
07-Apr-2005 Ryan Djurovich
378
#	page_filename function has been rewritten using str_replace
379
	function, which should be faster and will allow characters
380
	from other languages into filenames
381
!	Created new media_filename function, which is now used
382
	by all media functions (create,upload,rename) to determine
383
	which characters should be removed from a desired filename
384
+	New button in Administration page list to view specific page
385
#	Updated the page_link function to now be compatible with menu link
386
	module when setting pages directory to root
387
#	Fixed bugs in search when using "Any Words" option
388
#	Fixed bug with news module when pages directory set to root
389
!	Changed URL of documentation website on Administration Start page
390
------------------------------------- 2.4.2 -------------------------------------
391
05-Apr-2005 Ryan Djurovich
392
#	Fixed bug where file could be renamed to nothing in Media
393
!	Optimised Media create folder, upload file, and rename functions
394
#	Fixed bug where stripslashes not run on news post titles in admin
395
05-Apr-2005 Stefan Braunewell
396
#	Fixed bug concerning usage of the private_sql variable
397
#	Fixed bug conerning sub-pages being displayed in menus incorrectly
398
------------------------------------- 2.4.1 -------------------------------------
399
04-Apr-2005 Ryan Djurovich
400
!	Pages with visibility of "none" are again directly accessable
401
#	Fixed bugs regarding renaming files and directories in Media section
402
!	When home folders disabled, all folders now visible in Media section
403
------------------------------------- 2.4.0 -------------------------------------
404
03-Apr-2005 Ryan Djurovich
405
-	Removed recently added visibility setting of "heading", and relative config vars
406
+	Added new "menu" field to pages table, and new setting "multiple menus"
407
	which replaces the need for the menu headings feature
408
+	Added links to top of groups and users sections, linking to each other
409
!	Change menu width in "Round" template to 170px (was 150px)
410
#	Change page "are you sure" deletion message to mention that it will delete
411
	all sub-pages as well
412
#	Fixed many bugs with news module when viewing posts by group
413
!	Pages with visibility of "none" are now no longer directly accessable
414
02-Apr-2005 Ryan Djurovich
415
-	Removed need to specify DB_URL when calling database class
416
#	Stopped fields without a type specified from being shown in form mod
417
#	Changed '/media' to MEDIA_DIRECTORY on HTMLArea popup windows
418
	for insert link and insert image
419
+	Added setting which allows you to specify the default WYSIWYG style
420
+	Added "Server Email" option, to specify what is used in "From" field when
421
	sending emails using the PHP mail function. Default is admins email address.
422
#	Search now excludes pages which have a visibility of none or heading
423
!	Pages are now given modified_when and modified_by when added
424
01-Apr-2005 Ryan Djurovich
425
+	Added option to News module to specify how many posts should be listed
426
	per page (by default it is set to unlimited, which functions like previous version)
427
#	Added stripslashes when display page titles in search
428
+	Page descriptions and last updated date now shown in search by default
429
30-Mar-2005 Ryan Djurovich
430
+	Added new feature for Media home folders, where a folder can be specified
431
	for a specific user or group of users only
432
!	Changed URL of Help button to http://www.websitebaker.org/docs/
433
+	Added new feature for "Page Trash" - two modes available: inline and separate
434
!	When pages are deleted, all sub-pages are now deleted (instead of being moved
435
	up a level)
436
29-Mar-2005 Ryan Djurovich
437
-	Removed Database Settings from Administration Settings (options will not be
438
	available in 3.x, so trying to match interface with WB 3.x plans
439
!	Changed the name of Path Settings to Filesystem Settings in Administration
440
	Settings, and removed ability to change path/url options - matching interface
441
	plans for WB 3.x
442
+	Added same options for OS and file permissions as installer to Settings
443
!	Sessions now named with APP_NAME.'_session_id' (e.g. default is wb_session_id)
444
28-Mar-2005 Ryan Djurovich
445
+	New functions available to templates to simplify creation of them. This aims
446
	to "future-proof" templates for WB 3.x plans.
447
!	Default templates updated to support some of the new functions
448
+	Added field to pages table "page_trail" which stores a list of the pages
449
	parents. This field was needed by the new page_menu function
450
+	Added option for page visibility "heading" to enabled support for multiple
451
	menu's. Also, this helps to "future-proof" templates for WB 3.x plans
452
+	Added option for page visibility "registered", which acts a little like
453
	private, but is still shown in the menu (although users need to log in to view
454
	the pages content)
455
+	Form module submissions now saved to database, and feature now added to
456
	limit number of submissions per hour to prevent spamming
457
+	New field for Form module: email. Allows you to specify their email in
458
	"from" field on module settings.
459
#	Fixed bug when displaying comments in News module (WB Bug #14)
460
+	New "under contruction" message if no pages exist
461
!	Cleaned-up wb/index.php
462
27-Mar-2005 Ryan Djurovich
463
+	Created advanced mkdir and chmod functions
464
#	Fixed bug in media where wrong file/folder is deleted
465
+	Complete overhall of installer - now only one step! It has been greatly
466
	simplified in many ways, has much better validation, reports error much more
467
	nicely, and automatically logs the user into the Administrations
468
+	Must now specify OS type - allows for customizable file permission settings
469
+	Sections can now have a language code assigned to them
470
+	Sections can now have a block name/id assigned to them
471
!	Home section of Administration renamed to Start, to save confusion with saying
472
	Homepage (because this term could either mean the main website or Home section
473
	in	Administration). Also, this aims to unify the interface with WB 3.x plans
474
!	Moved Users and Groups sections under Access section. This aims to unify the
475
	interface with WB 3.x plans, which help to unclutter the menu
476
!	Interface for Settings section has been imporved for usability purposes
477
#	Fixed HTMLArea where no scrollbar for "insert link" and "insert image" dialogs
478
	by placing media list inside an iframe
479
#	Fixed stripslashes problem for viewing news comments
480
!	Added code from Formesque module (an advanced version of the original Form
481
	module, modified by Rudolph Lartey from www.carbonect.com), and made further
482
	interface improvements for select box/checkbox group/radio group options.
483
#	Possibly fixed bugs where an S appears before file and dir modes
484
#	Fixed bug where users can be added with same emails (in Administration)
485
-	Removed support for PEAR, as it was deemed an unnecessary addition which only
486
	makes code more bulky, and removing it will decrease package size a lot
487
+	New "homepage redirect" option so first page is included and not redirected to
488
#	Fixed text not being shown when module uninstalled
489
!	Imporved interface for basic group permissions
490
26-Mar-2005 Stefan Braunewell
491
#	Fixed bug with front-end logins
492
#	Fixed bug when saving intro page 
493
+	Added check on sign-up if e-mail exists (thanks to P. Melief)
494
#	Fixed bugs concerning moving/deleting pages
495
#	Fixed list of parents in page settings
496
#	Fixed mkdir without mode parameter
497
#	Added a check on install to ensure PHP 4.1.x compatibility (thanks to Wanderer)
498
+	Added support for PAGES_DIRECTORY set to root
499
+	Search form now supports quotes (thanks to Manafta)
500
#	Fixed page section ordering
501
#	News items are displayed with name of poster instead of "Unknown"
502
#	Deletion confirmation popup window in media section now shows correct file name
503
------------------------------------- 2.3.1 -------------------------------------
504
03-Fed-2005 Ryan Djurovich
505
+	Now there is two types of "filesystem modes", one for directories and one
506
	for files. Having different settings is very common for most servers, so
507
	this addition should fix many problems people had with 2.3.0.
508
-	Removed filesystem mode options from installation
509
!	Removed duplicate text on installation step 3 for timezone
510
!	All "access files" for the news module now stored in pages/posts instead
511
	of a sub-dir relative to the page (this fixes many bugs)
512
#	Fixed major bugs when deleting pages with sub-pages
513
!	Removed the restrictions that prevent a user for changing a pages level
514
#	Fixed bug with "toggle" plus/minus in IE for pages list
515
#	Fixed some bugs where /pages was not replaced with PAGES_DIRECTORY constant
516
------------------------------------- 2.3.0 -------------------------------------
517
26-Jan-2005 Ryan Djurovich
518
#	Fixed bug in framework/functions.php that made root parent always equal 8
519
#	Added missing braces in lines 182 and 208 of admin/pages/settings2.php
520
#	Fixed SQL-query on line 172, placing a / after $old_link
521
#	Added eregi checks for PAGES_DIRECTORY on lines 140 and 150 of
522
	admin/pages/settings2.php
523
#	Added ordering cleaning to delete_post.php on line 53 for news module
524
!	GMT option is selected for "Default Timezone" in the installer, instead
525
	of the old "Please select" message (which had the same value as GMT)
526
28-Jan-2005 Ryan Djurovich
527
!	Ability to specify the chmod number when WB uploads files, etc.
528
!	Modified file headers (copyright/license notice) so they now look almost the
529
	same, independant of font. Also, it now covers copyright for 2005.
530
30-Jan-2005 Ryan Djurovich
531
#	Added code on wb/admin/pages/delete.php to remove sections from the sections
532
	table when a page is deleted.
533
+	New 'Smart Login' prevents users from using external password managers,
534
	and can be set to remember the users password using cookies.
535
!	SourceForge CVS module now called websitebaker2 (instead of just
536
	websitebaker). Also, all file versions have been reset.
537
01-Fed-2005 Ryan Djurovich
538
!	Added code to prevent from changing a pages level (it simply disables
539
	the select box), to prevent many possible bugs.
540
------------------------------------- 2.2.4 -------------------------------------
541
23-Dec-2004 Ryan Djurovich
542
!	Change 'EXACT_PHRASE' to 'EXACT_MATCH' on line 261 of wb/languages/EN.php
543
#	Fixed multi-language support in search
544
+	Added more detailed options to list of PHP error reporting level's
545
-	Removed ability to change language and PHP error reporting level
546
	on installation to make things easier for newbie's
547
+	Ability to select custom spacer for page filename's
548
!	Changed the way a language code is found on language installation
549
+	Added template permissions to groups
550
#	Fixed bug when trying to change email from Preferences (admin and frontend)
551
#	Fixed bug with auto-selection of "System Default" for Preferences
552
!	News module now use's WYSIWYG for modifying news posts
553
+	Ability to specify both the pages and media target directories
554
------------------------------------ 2.2.3-c ------------------------------------
555
22-Dec-2004 Ryan Djurovich
556
#	Fixed problem with DB password being reset if Settings saved in basic mode
557
------------------------------------ 2.2.3-b ------------------------------------
558
21-Dec-2004 Ryan Djurovich
559
#	Fixed minor bug on admin templates section
560
#	Fixed bug on rename.php and rename2.php in admin media section
561
------------------------------------- 2.2.3 -------------------------------------
562
20-Dec-2004 Ryan Djurovich
563
+	Added WB release version in Administration (top right corner)
564
!	New option to prevent users from adding level 0 pages
565
#	Fixed bug when deleting post's in News module
566
+	Added new field in pages table for "root" parent (level 0 parent), for
567
	extra flexability in creating templates
568
!	Round template now supports unlimited page levels
569
------------------------------------- 2.2.2 -------------------------------------
570
18-Dec-2004 Ryan Djurovich
571
+	New option under Search Settings for selecting custom template for search
572
+	New option when changing page settings to set the target
573
#	Fixed error when saving a user after editing
574
!	Users can now modify sub-page if they dont have permissions on the parent
575
------------------------------------- 2.2.1 -------------------------------------
576
15-Dec-2004 Ryan Djurovich
577
#	Fixed bug when changing password on preferences form (front-end)
578
#	Fixed bug when retrieving user details (administration)
579
#	Added check to see if module, template, or language is in use when deleting
580
#	Fixed up email that is sent to user from a submitted form
581
#	Fixed major problem with module permissions which stopped it from working
582
------------------------------------- 2.2.0 -------------------------------------
583
14-Dec-2004 (Correct date[s] unkown) Ryan Djurovich
584
+	Multiple-level page support
585
+	Multiple section's for pages (including interface)
586
!	Removed text created using two words on all areas
587
	(e.g. {Intro} {PAGE} is now {INTRO_PAGE})
588
	this is for better language support
589
+	Added Languages section
590
!	Moved Templates and Modules under Add-ons section
591
!	Changed name of "Default" template to "Round"
592
+	Added "All CSS" template
593
+	Added "Jump"
594
+	Added 
595
!	Modified "Box" template to support multiple page levels
596
+	Added "Menu Link" module
597
+	Added "News" module
598
+	Added "Code" module
599
+	Added "Form" module
600
+	Added "Wrapper" module
601
!	Changed name of "Normal Page" module to "WYSIWYG"
602
+	Created new admin wrapper script to ease module develpment
603
+	Media now automatically creates index.php file for every
604
	sub-folder made (for security purposes)
605
!	Change "Help" link in Administration menu so it now directs
606
	to the the new Website Baker documentation website found at:
607
	http://www.websitebaker.org/documentation
608
!	Password is now required to change email in preferences
609
+	User can now select custom Language and Date & Time Formats
610
+	Added search functionality, with three different "methods":
611
	1. Using all words  2. Using any words  3. Exact match
612
+	Added native MySQL database support
0 613

  
tags/2.6.6/wb/framework/functions.php
1
<?php
2

  
3
// $Id$
4

  
5
/*
6

  
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2007, Ryan Djurovich
9

  
10
 Website Baker is free software; you can redistribute it and/or modify
11
 it under the terms of the GNU General Public License as published by
12
 the Free Software Foundation; either version 2 of the License, or
13
 (at your option) any later version.
14

  
15
 Website Baker is distributed in the hope that it will be useful,
16
 but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 GNU General Public License for more details.
19

  
20
 You should have received a copy of the GNU General Public License
21
 along with Website Baker; if not, write to the Free Software
22
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23

  
24
*/
25

  
26
/*
27

  
28
Website Baker functions file
29
This file contains general functions used in Website Baker
30

  
31
*/
32

  
33
// Stop this file from being accessed directly
34
if(!defined('WB_URL')) {
35
	header('Location: ../index.php');
36
	exit(0);
37
}
38

  
39
// Define that this file has been loaded
40
define('FUNCTIONS_FILE_LOADED', true);
41

  
42
// Function to remove a non-empty directory
43
function rm_full_dir($directory)
44
{
45
    // If suplied dirname is a file then unlink it
46
    if (is_file($directory)) {
47
        return unlink($directory);
48
    }
49

  
50
    // Empty the folder
51
    $dir = dir($directory);
52
    while (false !== $entry = $dir->read()) {
53
        // Skip pointers
54
        if ($entry == '.' || $entry == '..') {
55
            continue;
56
        }
57

  
58
        // Deep delete directories      
59
        if (is_dir("$directory/$entry")) {
60
            rm_full_dir("$directory/$entry");
61
        } else {
62
            unlink("$directory/$entry");
63
        }
64
    }
65

  
66
    // Now delete the folder
67
    $dir->close();
68
    return rmdir($directory);
69
}
70

  
71
// Function to open a directory and add to a dir list
72
function directory_list($directory) {
73
	
74
	$list = array();
75

  
76
	// Open the directory then loop through its contents
77
	$dir = dir($directory);
78
	while (false !== $entry = $dir->read()) {
79
		// Skip pointers
80
		if(substr($entry, 0, 1) == '.' || $entry == '.svn') {
81
			continue;
82
		}
83
		// Add dir and contents to list
84
		if (is_dir("$directory/$entry")) {
85
			$list = array_merge($list, directory_list("$directory/$entry"));
86
			$list[] = "$directory/$entry";
87
		}
88
	}
89

  
90
	// Now return the list
91
	return $list;
92
}
93

  
94
// Function to open a directory and add to a dir list
95
function chmod_directory_contents($directory, $file_mode) {
96
	
97
	// Set the umask to 0
98
	$umask = umask(0);
99
	
100
	// Open the directory then loop through its contents
101
	$dir = dir($directory);
102
	while (false !== $entry = $dir->read()) {
103
		// Skip pointers
104
		if(substr($entry, 0, 1) == '.' || $entry == '.svn') {
105
			continue;
106
		}
107
		// Chmod the sub-dirs contents
108
		if(is_dir("$directory/$entry")) {
109
			chmod_directory_contents("$directory/$entry", $file_mode);
110
		}
111
		change_mode($directory.'/'.$entry, 'file');
112
	}
113
	
114
	// Restore the umask
115
	umask($umask);
116

  
117
}
118

  
119
// Function to open a directory and add to a file list
120
function file_list($directory, $skip = array()) {
121
	
122
	$list = array();
123
	$skip_file = false;
124
	
125
	// Open the directory then loop through its contents
126
	$dir = dir($directory);
127
	while (false !== $entry = $dir->read()) {
128
		// Skip pointers
129
		if($entry == '.' || $entry == '..') {
130
			$skip_file = true;
131
		}
132
		// Check if we to skip anything else
133
		if($skip != array()) {
134
			foreach($skip AS $skip_name) {
135
				if($entry == $skip_name) {
136
					$skip_file = true;
137
				}
138
			}
139
		}
140
		// Add dir and contents to list
141
		if($skip_file != true AND is_file("$directory/$entry")) {
142
			$list[] = "$directory/$entry";
143
		}
144
		
145
		// Reset the skip file var
146
		$skip_file = false;
147
	}
148

  
149
	// Now delete the folder
150
	return $list;
151
}
152

  
153
// Function to get a list of home folders not to show
154
function get_home_folders() {
155
	global $database, $admin;
156
	$home_folders = array();
157
	// Only return home folders is this feature is enabled
158
	// and user is not admin
159
	if(HOME_FOLDERS AND ($_SESSION['GROUP_ID']!='1')) {
160
		$query_home_folders = $database->query("SELECT home_folder FROM ".TABLE_PREFIX."users WHERE home_folder != '".$admin->get_home_folder()."'");
161
		if($query_home_folders->numRows() > 0) {
162
			while($folder = $query_home_folders->fetchRow()) {
163
				$home_folders[$folder['home_folder']] = $folder['home_folder'];
164
			}
165
		}
166
		function remove_home_subs($directory = '/', $home_folders) {
167
			if($handle = opendir(WB_PATH.MEDIA_DIRECTORY.$directory)) {
168
				// Loop through the dirs to check the home folders sub-dirs are not shown
169
			   while(false !== ($file = readdir($handle))) {
170
					if(substr($file, 0, 1) != '.' AND $file != '.svn' AND $file != 'index.php') {
171
						if(is_dir(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$file)) {
172
							if($directory != '/') { $file = $directory.'/'.$file; } else { $file = '/'.$file; }
173
							foreach($home_folders AS $hf) {
174
								$hf_length = strlen($hf);
175
								if($hf_length > 0) {
176
									if(substr($file, 0, $hf_length+1) == $hf) {
177
										$home_folders[$file] = $file;
178
									}
179
								}
180
							}
181
							$home_folders = remove_home_subs($file, $home_folders);
182
						}
183
					}
184
				}
185
			}
186
			return $home_folders;
187
		}
188
		$home_folders = remove_home_subs('/', $home_folders);
189
	}
190
	return $home_folders;
191
}
192

  
193
// Function to create directories
194
function make_dir($dir_name, $dir_mode = OCTAL_DIR_MODE) {
195
	if(!file_exists($dir_name)) {
196
		$umask = umask(0);
197
		mkdir($dir_name, $dir_mode);
198
		umask($umask);
199
		return true;
200
	} else {
201
		return false;	
202
	}
203
}
204

  
205
// Function to chmod files and directories
206
function change_mode($name) {
207
	if(OPERATING_SYSTEM != 'windows') {
208
		// Only chmod if os is not windows
209
		if(is_dir($name)) {
210
			$mode = OCTAL_DIR_MODE;
211
		} else {
212
			$mode = OCTAL_FILE_MODE;
213
		}
214
		if(file_exists($name)) {
215
			$umask = umask(0);
216
			chmod($name, $mode);
217
			umask($umask);
218
			return true;
219
		} else {
220
			return false;	
221
		}
222
	} else {
223
		return true;
224
	}
225
}
226

  
227
// Function to figure out if a parent exists
228
function is_parent($page_id) {
229
	global $database;
230
	// Get parent
231
	$query = $database->query("SELECT parent FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'");
232
	$fetch = $query->fetchRow();
233
	// If parent isnt 0 return its ID
234
	if($fetch['parent'] == '0') {
235
		return false;
236
	} else {
237
		return $fetch['parent'];
238
	}
239
}
240

  
241
// Function to work out level
242
function level_count($page_id) {
243
	global $database;
244
	// Get page parent
245
	$query_page = $database->query("SELECT parent FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id' LIMIT 1");
246
	$fetch_page = $query_page->fetchRow();
247
	$parent = $fetch_page['parent'];
248
	if($parent > 0) {
249
		// Get the level of the parent
250
		$query_parent = $database->query("SELECT level FROM ".TABLE_PREFIX."pages WHERE page_id = '$parent' LIMIT 1");
251
		$fetch_parent = $query_parent->fetchRow();
252
		$level = $fetch_parent['level'];
253
		return $level+1;
254
	} else {
255
		return 0;
256
	}
257
}
258

  
259
// Function to work out root parent
260
function root_parent($page_id) {
261
	global $database;
262
	// Get page details
263
	$query_page = $database->query("SELECT parent,level FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id' LIMIT 1");
264
	$fetch_page = $query_page->fetchRow();
265
	$parent = $fetch_page['parent'];
266
	$level = $fetch_page['level'];	
267
	if($level == 1) {
268
		return $parent;
269
	} elseif($parent == 0) {
270
		return $page_id;
271
	} else {
272
		// Figure out what the root parents id is
273
		$parent_ids = array_reverse(get_parent_ids($page_id));
274
		return $parent_ids[0];
275
	}
276
}
277

  
278
// Function to get page title
279
function get_page_title($id) {
280
	global $database;
281
	// Get title
282
	$query = $database->query("SELECT page_title FROM ".TABLE_PREFIX."pages WHERE page_id = '$id'");
283
	$fetch = $query->fetchRow();
284
	// Return title
285
	return $fetch['page_title'];
286
}
287

  
288
// Function to get a pages menu title
289
function get_menu_title($id) {
290
	// Connect to the database
291
	$database = new database();
292
	// Get title
293
	$query = $database->query("SELECT menu_title FROM ".TABLE_PREFIX."pages WHERE page_id = '$id'");
294
	$fetch = $query->fetchRow();
295
	// Return title
296
	return $fetch['menu_title'];
297
}
298

  
299
// Function to get all parent page titles
300
function get_parent_titles($parent_id) {
301
	$titles[] = get_menu_title($parent_id);
302
	if(is_parent($parent_id) != false) {
303
		$parent_titles = get_parent_titles(is_parent($parent_id));
304
		$titles = array_merge($titles, $parent_titles);
305
	}
306
	return $titles;
307
}
308

  
309
// Function to get all parent page id's
310
function get_parent_ids($parent_id) {
311
	$ids[] = $parent_id;
312
	if(is_parent($parent_id) != false) {
313
		$parent_ids = get_parent_ids(is_parent($parent_id));
314
		$ids = array_merge($ids, $parent_ids);
315
	}
316
	return $ids;
317
}
318

  
319
// Function to genereate page trail
320
function get_page_trail($page_id) {
321
	return implode(',', array_reverse(get_parent_ids($page_id)));
322
}
323

  
324
// Function to get all sub pages id's
325
function get_subs($parent, $subs) {
326
	// Connect to the database
327
	$database = new database();
328
	// Get id's
329
	$query = $database->query("SELECT page_id FROM ".TABLE_PREFIX."pages WHERE parent = '$parent'");
330
	if($query->numRows() > 0) {
331
		while($fetch = $query->fetchRow()) {
332
			$subs[] = $fetch['page_id'];
333
			// Get subs of this sub
334
			$subs = get_subs($fetch['page_id'], $subs);
335
		}
336
	}
337
	// Return subs array
338
	return $subs;
339
}
340

  
341
// Function as replecement for php's htmlspecialchars()
342
function my_htmlspecialchars($string) {
343
	$string = preg_replace("/&(?=[#a-z0-9]+;)/i", "_x_", $string);
344
	$string = strtr($string, array("<"=>"&lt;", ">"=>"&gt;", "&"=>"&amp;", "\""=>"&quot;", "\'"=>"&#39;"));
345
	$string = preg_replace("/_x_(?=[#a-z0-9]+;)/i", "&", $string);
346
	return($string);
347
}
348

  
349
// Function to convert a string from $from- to $to-encoding, using mysql
350
function my_mysql_iconv($string, $from, $to) {
351
	// keep current character set values
352
	global $database;
353
	$query = $database->query("SELECT @@character_set_client");
354
	if($query->numRows() > 0) {
355
		$res = $query->fetchRow();
356
		$character_set_database = $res['@@character_set_client'];
357
	}	else { echo mysql_error()."\n<br />"; }
358
	$query = $database->query("SELECT @@character_set_results");
359
	if($query->numRows() > 0) {
360
		$res = $query->fetchRow();
361
		$character_set_results = $res['@@character_set_results'];
362
	}	else { echo mysql_error()."\n<br />"; }
363
	$query = $database->query("SELECT @@collation_connection");
364
	if($query->numRows() > 0) {
365
		$res = $query->fetchRow();
366
		$collation_results = $res['@@collation_connection'];
367
	}	else { echo mysql_error()."\n<br />"; }
368
	// set new character set values
369
	$query = $database->query("SET character_set_client=$from");
370
	$query = $database->query("SET character_set_results=$to");
371
	$query = $database->query("SET collation_connection=utf8_unicode_ci");
372
	$string_escaped = mysql_real_escape_string($string);
373
	// convert the string
374
	$query = $database->query("SELECT '$string_escaped'");
375
	if($query->numRows() > 0) {
376
		$res = $query->fetchRow();
377
		$converted_string = $res[0];
378
	}	else { echo mysql_error()."\n<br />"; }
379
	// restore previous character set values
380
	$query = $database->query("SET character_set_client=$character_set_database");
381
	$query = $database->query("SET character_set_results=$character_set_results");
382
	$query = $database->query("SET collation_connection=$collation_results");
383
	return $converted_string;
384
}
385

  
386
// Function as wrapper for mb_convert_encoding
387
// converts $charset_in to $charset_out or 
388
// UTF-8 to HTML-ENTITIES or HTML-ENTITIES to UTF-8
389
function mb_convert_encoding_wrapper($string, $charset_out, $charset_in) {
390
	if ($charset_out == $charset_in) {
391
		return $string;
392
	}
393
	$use_iconv = true;
394
	$use_mbstring = true;
395
	/*
396
	if(version_compare(PHP_VERSION, "5.1.0", "<")) {
397
		$use_mbstring = false; // don't rely on mb_convert_encoding if php<5.1.0
398
		$use_iconv = false; // don't rely on iconv neither
399
	}
400
	*/
401
	
402
	// try mb_convert_encoding(). This can handle to or from HTML-ENTITIES, too
403
	if ($use_mbstring && function_exists('mb_convert_encoding')) {
404
		// there's no GB2312 or ISO-8859-11 encoding in php's mb_* functions
405
		if ($charset_in=='ISO-8859-11' || $charset_in=='GB2312') {
406
			if ($use_iconv && function_exists('iconv')) {
407
				$string = iconv($charset_in, 'UTF-8', $string);
408
			}
409
			else {
410
				if ($charset_in == 'GB2312') {
411
					$string=my_mysql_iconv($string, 'gb2312', 'utf8');
412
				} else {
413
					$string=my_mysql_iconv($string, 'tis620', 'utf8');
414
				}
415
			}
416
			$charset_in='UTF-8';
417
			if ($charset_out == 'UTF-8') {
418
				return $string;
419
			}
420
		}
421
		if ($charset_out=='ISO-8859-11' || $charset_out=='GB2312') {
422
			$string=mb_convert_encoding($string, 'UTF-8', $charset_in);
423
			if ($use_iconv && function_exists('iconv')) {
424
				$string = iconv('UTF-8', $charset_out, $string);
425
			}
426
			else {
427
				if ($charset_out == 'GB2312') {
428
					$string=my_mysql_iconv($string, 'utf8', 'gb2312');
429
				} else {
430
					$string=my_mysql_iconv($string, 'utf8', 'tis620');
431
				}
432
			}
433
		} else {
434
			$string = strtr($string, array("&lt;"=>"&_lt;", "&gt;"=>"&_gt;", "&amp;"=>"&_amp;", "&quot;"=>"&_quot;", "&#39;"=>"&_#39;"));
435
			$string=mb_convert_encoding($string, $charset_out, $charset_in);
436
			$string = strtr($string, array("&_lt;"=>"&lt;", "&_gt;"=>"&gt;", "&_amp;"=>"&amp;", "&_quot;"=>"&quot;", "&_#39;"=>"&#39;"));
437
		}
438
		return $string;
439
	}
440

  
441
	// try iconv(). This can't handle to or from HTML-ENTITIES.
442
	if ($use_iconv && function_exists('iconv') && $charset_out!='HTML-ENTITIES' && $charset_in!='HTML-ENTITIES' ) {
443
		$string = iconv($charset_in, $charset_out, $string);
444
		return $string;
445
	}
446

  
447
	// do the UTF-8->HTML-ENTITIES or HTML-ENTITIES->UTF-8 translation if mb_convert_encoding isn't available
448
	if (($charset_in=='HTML-ENTITIES' && $charset_out=='UTF-8') || ($charset_in=='UTF-8' && $charset_out=='HTML-ENTITIES')) {
449
		$string = string_decode_encode_entities($string, $charset_out, $charset_in);
450
		return $string;
451
	}
452

  
453
	// mb_convert_encoding() and iconv() aren't available, so use my_mysql_iconv()
454
	if ($charset_in == 'ISO-8859-1') { $mysqlcharset_from = 'latin1'; }
455
	elseif ($charset_in == 'ISO-8859-2') { $mysqlcharset_from = 'latin2'; }
456
	elseif ($charset_in == 'ISO-8859-3') { $mysqlcharset_from = 'latin1'; }
457
	elseif ($charset_in == 'ISO-8859-4') { $mysqlcharset_from = 'latin7'; }
458
	elseif ($charset_in == 'ISO-8859-5') { $string = convert_cyr_string ($string, "iso8859-5", "windows-1251" ); $mysqlcharset_from = 'cp1251'; }
459
	elseif ($charset_in == 'ISO-8859-6') { $mysqlcharset_from = ''; } //?
460
	elseif ($charset_in == 'ISO-8859-7') { $mysqlcharset_from = 'greek'; }
461
	elseif ($charset_in == 'ISO-8859-8') { $mysqlcharset_from = 'hebrew'; }
462
	elseif ($charset_in == 'ISO-8859-9') { $mysqlcharset_from = 'latin5'; }
463
	elseif ($charset_in == 'ISO-8859-10') { $mysqlcharset_from = 'latin1'; }
464
	elseif ($charset_in == 'BIG5') { $mysqlcharset_from = 'big5'; }
465
	elseif ($charset_in == 'ISO-2022-JP') { $mysqlcharset_from = ''; } //?
466
	elseif ($charset_in == 'ISO-2022-KR') { $mysqlcharset_from = ''; } //?
467
	elseif ($charset_in == 'GB2312') { $mysqlcharset_from = 'gb2312'; }
468
	elseif ($charset_in == 'ISO-8859-11') { $mysqlcharset_from = 'tis620'; }
469
	elseif ($charset_in == 'UTF-8') { $mysqlcharset_from = 'utf8'; }
470
	else { $mysqlcharset_from = 'latin1'; }
471

  
472
	if ($charset_out == 'ISO-8859-1') { $mysqlcharset_to = 'latin1'; }
473
	elseif ($charset_out == 'ISO-8859-2') { $mysqlcharset_to = 'latin2'; }
474
	elseif ($charset_out == 'ISO-8859-3') { $mysqlcharset_to = 'latin1'; }
475
	elseif ($charset_out == 'ISO-8859-4') { $mysqlcharset_to = 'latin7'; }
476
	elseif ($charset_out == 'ISO-8859-5') { $mysqlcharset_to = 'cp1251'; } // use convert_cyr_string afterwards
477
	elseif ($charset_out == 'ISO-8859-6') { $mysqlcharset_to = ''; } //?
478
	elseif ($charset_out == 'ISO-8859-7') { $mysqlcharset_to = 'greek'; }
479
	elseif ($charset_out == 'ISO-8859-8') { $mysqlcharset_to = 'hebrew'; }
480
	elseif ($charset_out == 'ISO-8859-9') { $mysqlcharset_to = 'latin5'; }
481
	elseif ($charset_out == 'ISO-8859-10') { $mysqlcharset_to = 'latin1'; }
482
	elseif ($charset_out == 'BIG5') { $mysqlcharset_to = 'big5'; }
483
	elseif ($charset_out == 'ISO-2022-JP') { $mysqlcharset_to = ''; } //?
484
	elseif ($charset_out == 'ISO-2022-KR') { $mysqlcharset_to = ''; } //?
485
	elseif ($charset_out == 'GB2312') { $mysqlcharset_to = 'gb2312'; }
486
	elseif ($charset_out == 'ISO-8859-11') { $mysqlcharset_to = 'tis620'; }
487
	elseif ($charset_out == 'UTF-8') { $mysqlcharset_to = 'utf8'; }
488
	else { $mysqlcharset_to = 'latin1'; }
489

  
490
	if ($mysqlcharset_from!="" && $mysqlcharset_to!="" && $mysqlcharset_from!=$mysqlcharset_to) {
491
		$string=my_mysql_iconv($string, $mysqlcharset_from, $mysqlcharset_to);
492
		if ($mysqlcharset_to == 'cp1251') { 
493
			$string = convert_cyr_string ($string, "windows-1251", "iso-8859-5" );
494
		}
495
		return($string);
496
	}
497

  
498
	// $string is unchanged. This will happen if we have to deal with ISO-8859-6 or ISO-2022-JP or -KR
499
	// and mbstring _and_ iconv aren't available.
500
	return $string;
501
}
502

  
503
// Decodes or encodes html-entities. Works for utf-8 only!
504
function string_decode_encode_entities($string, $out='HTML-ENTITIES', $in='UTF-8') {
505
	if(!(($in=='UTF-8' || $in=='HTML-ENTITIES') && ($out=='UTF-8' || $out=='HTML-ENTITIES'))) {
506
		return $string;
507
	}
508
	$named_to_numbered_entities=array(
509
		'&Aacute;'=>'&#193;','&aacute;'=>'&#225;',
510
		'&Acirc;'=>'&#194;','&acirc;'=>'&#226;','&acute;'=>'&#180;','&AElig;'=>'&#198;','&aelig;'=>'&#230;',
511
		'&Agrave;'=>'&#192;','&agrave;'=>'&#224;','&alefsym;'=>'&#8501;','&Alpha;'=>'&#913;','&alpha;'=>'&#945;',
512
		'&and;'=>'&#8743;','&ang;'=>'&#8736;','&apos;'=>'&#39;','&Aring;'=>'&#197;','&aring;'=>'&#229;',
513
		'&asymp;'=>'&#8776;','&Atilde;'=>'&#195;','&atilde;'=>'&#227;','&Auml;'=>'&#196;','&auml;'=>'&#228;',
514
		'&bdquo;'=>'&#8222;','&Beta;'=>'&#914;','&beta;'=>'&#946;','&brvbar;'=>'&#166;','&bull;'=>'&#8226;',
515
		'&cap;'=>'&#8745;','&Ccedil;'=>'&#199;','&ccedil;'=>'&#231;','&cedil;'=>'&#184;','&cent;'=>'&#162;',
516
		'&Chi;'=>'&#935;','&chi;'=>'&#967;','&circ;'=>'&#710;','&clubs;'=>'&#9827;','&cong;'=>'&#8773;',
517
		'&copy;'=>'&#169;','&crarr;'=>'&#8629;','&cup;'=>'&#8746;','&curren;'=>'&#164;','&Dagger;'=>'&#8225;',
518
		'&dagger;'=>'&#8224;','&dArr;'=>'&#8659;','&darr;'=>'&#8595;','&deg;'=>'&#176;','&Delta;'=>'&#916;',
519
		'&delta;'=>'&#948;','&diams;'=>'&v#9830;','&divide;'=>'&#247;','&Eacute;'=>'&#201;','&eacute;'=>'&#233;',
520
		'&Ecirc;'=>'&#202;','&ecirc;'=>'&#234;','&Egrave;'=>'&#200;','&egrave;'=>'&#232;','&empty;'=>'&#8709;',
521
		'&emsp;'=>'&#8195;','&ensp;'=>'&#8194;','&Epsilon;'=>'&#917;','&epsilon;'=>'&#949;','&equiv;'=>'&#8801;',
522
		'&Eta;'=>'&#919;','&eta;'=>'&#951;','&ETH;'=>'&#208;','&eth;'=>'&#240;','&Euml;'=>'&#203;','&euml;'=>'&#235;',
523
		'&euro;'=>'&#8364;','&exist;'=>'&#8707;','&fnof;'=>'&#402;','&forall;'=>'&#8704;','&frac12;'=>'&#189;',
524
		'&frac14;'=>'&#188;','&frac34;'=>'&#190;','&frasl;'=>'&#8260;','&Gamma;'=>'&#915;','&gamma;'=>'&#947;',
525
		'&ge;'=>'&#8805;','&hArr;'=>'&#8660;','&harr;'=>'&#8596;','&hearts;'=>'&#9829;',
526
		'&hellip;'=>'&#8230;','&Iacute;'=>'&#205;','&iacute;'=>'&#237;','&Icirc;'=>'&#206;','&icirc;'=>'&#238;',
527
		'&iexcl;'=>'&#161;','&Igrave;'=>'&#204;','&igrave;'=>'&#236;','&image;'=>'&#8465;','&infin;'=>'&#8734;',
528
		'&int;'=>'&#8747;','&Iota;'=>'&#921;','&iota;'=>'&#953;','&iquest;'=>'&#191;','&isin;'=>'&#8712;',
529
		'&Iuml;'=>'&#207;','&iuml;'=>'&#239;','&Kappa;'=>'&#922;','&kappa;'=>'&#954;','&Lambda;'=>'&#923;',
530
		'&lambda;'=>'&#955;','&lang;'=>'&#9001;','&laquo;'=>'&#171;','&lArr;'=>'&#8656;','&larr;'=>'&#8592;',
531
		'&lceil;'=>'&#8968;','&ldquo;'=>'&#8220;','&le;'=>'&#8804;','&lfloor;'=>'&#8970;','&lowast;'=>'&#8727;',
532
		'&loz;'=>'&#9674;','&lrm;'=>'&#8206;','&lsaquo;'=>'&#8249;','&lsquo;'=>'&#8216;',
533
		'&macr;'=>'&#175;','&mdash;'=>'&#8212;','&micro;'=>'&#181;','&middot;'=>'&#183;','&minus;'=>'&#8722;',
534
		'&Mu;'=>'&#924;','&mu;'=>'&#956;','&nabla;'=>'&#8711;','&nbsp;'=>'&#160;','&ndash;'=>'&#8211;',
535
		'&ne;'=>'&#8800;','&ni;'=>'&#8715;','&not;'=>'&#172;','&notin;'=>'&#8713;','&nsub;'=>'&#8836;',
536
		'&Ntilde;'=>'&#209;','&ntilde;'=>'&#241;','&Nu;'=>'&#925;','&nu;'=>'&#957;','&Oacute;'=>'&#211;',
537
		'&oacute;'=>'&#243;','&Ocirc;'=>'&#212;','&ocirc;'=>'&#244;','&OElig;'=>'&#338;','&oelig;'=>'&#339;',
538
		'&Ograve;'=>'&#210;','&ograve;'=>'&#242;','&oline;'=>'&#8254;','&Omega;'=>'&#937;','&omega;'=>'&#969;',
539
		'&Omicron;'=>'&#927;','&omicron;'=>'&#959;','&oplus;'=>'&#8853;','&or;'=>'&#8744;','&ordf;'=>'&#170;',
540
		'&ordm;'=>'&#186;','&Oslash;'=>'&#216;','&oslash;'=>'&#248;','&Otilde;'=>'&#213;','&otilde;'=>'&#245;',
541
		'&otimes;'=>'&#8855;','&Ouml;'=>'&#214;','&ouml;'=>'&#246;','&para;'=>'&#182;','&part;'=>'&#8706;',
542
		'&permil;'=>'&#8240;','&perp;'=>'&#8869;','&Phi;'=>'&#934;','&phi;'=>'&#966;','&Pi;'=>'&#928;',
543
		'&pi;'=>'&#960;','&piv;'=>'&#982;','&plusmn;'=>'&#177;','&pound;'=>'&#163;','&Prime;'=>'&#8243;',
544
		'&prime;'=>'&#8242;','&prod;'=>'&#8719;','&prop;'=>'&#8733;','&Psi;'=>'&#936;','&psi;'=>'&#968;',
545
		'&quot;'=>'&#34;','&radic;'=>'&#8730;','&rang;'=>'&#9002;','&raquo;'=>'&#187;','&rArr;'=>'&#8658;',
546
		'&rarr;'=>'&#8594;','&rceil;'=>'&#8969;','&rdquo;'=>'&#8221;','&real;'=>'&#8476;','&reg;'=>'&#174;',
547
		'&rfloor;'=>'&#8971;','&Rho;'=>'&#929;','&rho;'=>'&#961;','&rlm;'=>'&#8207;','&rsaquo;'=>'&#8250;',
548
		'&rsquo;'=>'&#8217;','&sbquo;'=>'&#8218;','&Scaron;'=>'&#352;','&scaron;'=>'&#353;','&sdot;'=>'&#8901;',
549
		'&sect;'=>'&#167;','&shy;'=>'&#173;','&Sigma;'=>'&#931;','&sigma;'=>'&#963;','&sigmaf;'=>'&#962;',
550
		'&sim;'=>'&#8764;','&spades;'=>'&#9824;','&sub;'=>'&#8834;','&sube;'=>'&#8838;','&sum;'=>'&#8721;',
551
		'&sup;'=>'&#8835;','&sup1;'=>'&#185;','&sup2;'=>'&#178;','&sup3;'=>'&#179;','&supe;'=>'&#8839;',
552
		'&szlig;'=>'&#223;','&Tau;'=>'&#932;','&tau;'=>'&#964;','&there4;'=>'&#8756;','&Theta;'=>'&#920;',
553
		'&theta;'=>'&#952;','&thetasym;'=>'&#977;','&thinsp;'=>'&#8201;','&THORN;'=>'&#222;','&thorn;'=>'&#254;',
554
		'&tilde;'=>'&#732;','&times;'=>'&#215;','&trade;'=>'&#8482;','&Uacute;'=>'&#218;','&uacute;'=>'&#250;',
555
		'&uArr;'=>'&#8657;','&uarr;'=>'&#8593;','&Ucirc;'=>'&#219;','&ucirc;'=>'&#251;','&Ugrave;'=>'&#217;',
556
		'&ugrave;'=>'&#249;','&uml;'=>'&#168;','&upsih;'=>'&#978;','&Upsilon;'=>'&#933;','&upsilon;'=>'&#965;',
557
		'&Uuml;'=>'&#220;','&uuml;'=>'&#252;','&weierp;'=>'&#8472;','&Xi;'=>'&#926;','&xi;'=>'&#958;',
558
		'&Yacute;'=>'&#221;','&yacute;'=>'&#253;','&yen;'=>'&#165;','&Yuml;'=>'&#376;','&yuml;'=>'&#255;',
559
		'&Zeta;'=>'&#918;','&zeta;'=>'&#950;','&zwj;'=>'&#8205;','&zwnj;'=>'&#8204;'
560
	);
561
	$numbered_to_named_entities=array(
562
		'&#193;'=>'&Aacute;','&#225;'=>'&aacute;','&#194;'=>'&Acirc;','&#226;'=>'&acirc;','&#180;'=>'&acute;',
563
		'&#198;'=>'&AElig;','&#230;'=>'&aelig;','&#192;'=>'&Agrave;','&#224;'=>'&agrave;','&#8501;'=>'&alefsym;',
564
		'&#913;'=>'&Alpha;','&#945;'=>'&alpha;','&#8743;'=>'&and;','&#8736;'=>'&ang;',
565
		'&#39;'=>'&apos;','&#197;'=>'&Aring;','&#229;'=>'&aring;','&#8776;'=>'&asymp;','&#195;'=>'&Atilde;',
566
		'&#227;'=>'&atilde;','&#196;'=>'&Auml;','&#228;'=>'&auml;','&#8222;'=>'&bdquo;','&#914;'=>'&Beta;',
567
		'&#946;'=>'&beta;','&#166;'=>'&brvbar;','&#8226;'=>'&bull;','&#8745;'=>'&cap;','&#199;'=>'&Ccedil;',
568
		'&#231;'=>'&ccedil;','&#184;'=>'&cedil;','&#162;'=>'&cent;','&#935;'=>'&Chi;','&#967;'=>'&chi;',
569
		'&#710;'=>'&circ;','&#9827;'=>'&clubs;','&#8773;'=>'&cong;','&#169;'=>'&copy;','&#8629;'=>'&crarr;',
570
		'&#8746;'=>'&cup;','&#164;'=>'&curren;','&#8225;'=>'&Dagger;','&#8224;'=>'&dagger;','&#8659;'=>'&dArr;',
571
		'&#8595;'=>'&darr;','&#176;'=>'&deg;','&#916;'=>'&Delta;','&#948;'=>'&delta;','&v#9830;'=>'&diams;',
572
		'&#247;'=>'&divide;','&#201;'=>'&Eacute;','&#233;'=>'&eacute;','&#202;'=>'&Ecirc;','&#234;'=>'&ecirc;',
573
		'&#200;'=>'&Egrave;','&#232;'=>'&egrave;','&#8709;'=>'&empty;','&#8195;'=>'&emsp;','&#8194;'=>'&ensp;',
574
		'&#917;'=>'&Epsilon;','&#949;'=>'&epsilon;','&#8801;'=>'&equiv;','&#919;'=>'&Eta;','&#951;'=>'&eta;',
575
		'&#208;'=>'&ETH;','&#240;'=>'&eth;','&#203;'=>'&Euml;','&#235;'=>'&euml;','&#8364;'=>'&euro;',
576
		'&#8707;'=>'&exist;','&#402;'=>'&fnof;','&#8704;'=>'&forall;','&#189;'=>'&frac12;','&#188;'=>'&frac14;',
577
		'&#190;'=>'&frac34;','&#8260;'=>'&frasl;','&#915;'=>'&Gamma;','&#947;'=>'&gamma;','&#8805;'=>'&ge;',
578
		'&#8660;'=>'&hArr;','&#8596;'=>'&harr;','&#9829;'=>'&hearts;','&#8230;'=>'&hellip;',
579
		'&#205;'=>'&Iacute;','&#237;'=>'&iacute;','&#206;'=>'&Icirc;','&#238;'=>'&icirc;','&#161;'=>'&iexcl;',
580
		'&#204;'=>'&Igrave;','&#236;'=>'&igrave;','&#8465;'=>'&image;','&#8734;'=>'&infin;','&#8747;'=>'&int;',
581
		'&#921;'=>'&Iota;','&#953;'=>'&iota;','&#191;'=>'&iquest;','&#8712;'=>'&isin;','&#207;'=>'&Iuml;',
582
		'&#239;'=>'&iuml;','&#922;'=>'&Kappa;','&#954;'=>'&kappa;','&#923;'=>'&Lambda;','&#955;'=>'&lambda;',
583
		'&#9001;'=>'&lang;','&#171;'=>'&laquo;','&#8656;'=>'&lArr;','&#8592;'=>'&larr;','&#8968;'=>'&lceil;',
584
		'&#8220;'=>'&ldquo;','&#8804;'=>'&le;','&#8970;'=>'&lfloor;','&#8727;'=>'&lowast;','&#9674;'=>'&loz;',
585
		'&#8206;'=>'&lrm;','&#8249;'=>'&lsaquo;','&#8216;'=>'&lsquo;','&#175;'=>'&macr;',
586
		'&#8212;'=>'&mdash;','&#181;'=>'&micro;','&#183;'=>'&middot;','&#8722;'=>'&minus;','&#924;'=>'&Mu;',
587
		'&#956;'=>'&mu;','&#8711;'=>'&nabla;','&#160;'=>'&nbsp;','&#8211;'=>'&ndash;','&#8800;'=>'&ne;',
588
		'&#8715;'=>'&ni;','&#172;'=>'&not;','&#8713;'=>'&notin;','&#8836;'=>'&nsub;','&#209;'=>'&Ntilde;',
589
		'&#241;'=>'&ntilde;','&#925;'=>'&Nu;','&#957;'=>'&nu;','&#211;'=>'&Oacute;','&#243;'=>'&oacute;',
590
		'&#212;'=>'&Ocirc;','&#244;'=>'&ocirc;','&#338;'=>'&OElig;','&#339;'=>'&oelig;','&#210;'=>'&Ograve;',
591
		'&#242;'=>'&ograve;','&#8254;'=>'&oline;','&#937;'=>'&Omega;','&#969;'=>'&omega;','&#927;'=>'&Omicron;',
592
		'&#959;'=>'&omicron;','&#8853;'=>'&oplus;','&#8744;'=>'&or;','&#170;'=>'&ordf;','&#186;'=>'&ordm;',
593
		'&#216;'=>'&Oslash;','&#248;'=>'&oslash;','&#213;'=>'&Otilde;','&#245;'=>'&otilde;','&#8855;'=>'&otimes;',
594
		'&#214;'=>'&Ouml;','&#246;'=>'&ouml;','&#182;'=>'&para;','&#8706;'=>'&part;','&#8240;'=>'&permil;',
595
		'&#8869;'=>'&perp;','&#934;'=>'&Phi;','&#966;'=>'&phi;','&#928;'=>'&Pi;','&#960;'=>'&pi;','&#982;'=>'&piv;',
596
		'&#177;'=>'&plusmn;','&#163;'=>'&pound;','&#8243;'=>'&Prime;','&#8242;'=>'&prime;','&#8719;'=>'&prod;',
597
		'&#8733;'=>'&prop;','&#936;'=>'&Psi;','&#968;'=>'&psi;','&#34;'=>'&quot;','&#8730;'=>'&radic;',
598
		'&#9002;'=>'&rang;','&#187;'=>'&raquo;','&#8658;'=>'&rArr;','&#8594;'=>'&rarr;','&#8969;'=>'&rceil;',
599
		'&#8221;'=>'&rdquo;','&#8476;'=>'&real;','&#174;'=>'&reg;','&#8971;'=>'&rfloor;','&#929;'=>'&Rho;',
600
		'&#961;'=>'&rho;','&#8207;'=>'&rlm;','&#8250;'=>'&rsaquo;','&#8217;'=>'&rsquo;','&#8218;'=>'&sbquo;',
601
		'&#352;'=>'&Scaron;','&#353;'=>'&scaron;','&#8901;'=>'&sdot;','&#167;'=>'&sect;','&#173;'=>'&shy;',
602
		'&#931;'=>'&Sigma;','&#963;'=>'&sigma;','&#962;'=>'&sigmaf;','&#8764;'=>'&sim;','&#9824;'=>'&spades;',
603
		'&#8834;'=>'&sub;','&#8838;'=>'&sube;','&#8721;'=>'&sum;','&#8835;'=>'&sup;','&#185;'=>'&sup1;',
604
		'&#178;'=>'&sup2;','&#179;'=>'&sup3;','&#8839;'=>'&supe;','&#223;'=>'&szlig;','&#932;'=>'&Tau;',
605
		'&#964;'=>'&tau;','&#8756;'=>'&there4;','&#920;'=>'&Theta;','&#952;'=>'&theta;','&#977;'=>'&thetasym;',
606
		'&#8201;'=>'&thinsp;','&#222;'=>'&THORN;','&#254;'=>'&thorn;','&#732;'=>'&tilde;','&#215;'=>'&times;',
607
		'&#8482;'=>'&trade;','&#218;'=>'&Uacute;','&#250;'=>'&uacute;','&#8657;'=>'&uArr;','&#8593;'=>'&uarr;',
608
		'&#219;'=>'&Ucirc;','&#251;'=>'&ucirc;','&#217;'=>'&Ugrave;','&#249;'=>'&ugrave;','&#168;'=>'&uml;',
609
		'&#978;'=>'&upsih;','&#933;'=>'&Upsilon;','&#965;'=>'&upsilon;','&#220;'=>'&Uuml;','&#252;'=>'&uuml;',
610
		'&#8472;'=>'&weierp;','&#926;'=>'&Xi;','&#958;'=>'&xi;','&#221;'=>'&Yacute;','&#253;'=>'&yacute;',
611
		'&#165;'=>'&yen;','&#376;'=>'&Yuml;','&#255;'=>'&yuml;','&#918;'=>'&Zeta;','&#950;'=>'&zeta;','&#8205;'=>'&zwj;',
612
		'&#8204;'=>'&zwnj;'
613
	);
614
		
615
	if ($in == 'HTML-ENTITIES') {
616
		$string = strtr($string, array('&#039;'=>'&#39;')); // fix a broken entity
617
		$string = strtr($string, $named_to_numbered_entities);
618
		$string = preg_replace("/&#([0-9]+);/e", "code_to_utf8($1)", $string);
619
	}
620
	elseif ($out == 'HTML-ENTITIES') {
621
		//$string = preg_replace("/&#([0-9]+);/e", "code_to_utf8($1)", $string);
622
		$char = "";
623
		while (strlen($string) > 0) {
624
			preg_match("/^(.)(.*)$/su", $string, $match);
625
			if (strlen($match[1]) > 1) {
626
				$char .= "&#".uniord($match[1]).";";
627
			} else $char .= $match[1];
628
			$string = $match[2];
629
		}
630
		$string = $char;
631
		$string = strtr($string, $numbered_to_named_entities);
632
		// do ' and "
633
		$string = strtr($string, array('\''=>'&#39;', '\"'=>'&quot;'));
634
	}
635
	return $string;
636
}
637

  
638
// support-function for string_decode_encode_entities()
639
function uniord($c) {
640
        $ud = 0;
641
        if (ord($c{0}) >= 0 && ord($c{0}) <= 127) $ud = ord($c{0});
642
        if (ord($c{0}) >= 192 && ord($c{0}) <= 223) $ud = (ord($c{0})-192)*64 + (ord($c{1})-128);
643
        if (ord($c{0}) >= 224 && ord($c{0}) <= 239) $ud = (ord($c{0})-224)*4096 + (ord($c{1})-128)*64 + (ord($c{2})-128);
644
        if (ord($c{0}) >= 240 && ord($c{0}) <= 247) $ud = (ord($c{0})-240)*262144 + (ord($c{1})-128)*4096 + (ord($c{2})-128)*64 + (ord($c{3})-128);
645
        if (ord($c{0}) >= 248 && ord($c{0}) <= 251) $ud = (ord($c{0})-248)*16777216 + (ord($c{1})-128)*262144 + (ord($c{2})-128)*4096 + (ord($c{3})-128)*64 + (ord($c{4})-128);
646
        if (ord($c{0}) >= 252 && ord($c{0}) <= 253) $ud = (ord($c{0})-252)*1073741824 + (ord($c{1})-128)*16777216 + (ord($c{2})-128)*262144 + (ord($c{3})-128)*4096 + (ord($c{4})-128)*64 + (ord($c{5})-128);
647
        if (ord($c{0}) >= 254 && ord($c{0}) <= 255) $ud = false; // error
648
        return $ud;
649
}
650
// support-function for mb_convert_encoding_wrapper()
651
function code_to_utf8($num) {
652
	if ($num <= 0x7F) {
653
		return chr($num);
654
	} elseif ($num <= 0x7FF) {
655
		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
656
	} elseif ($num <= 0xFFFF) {
657
		 return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
658
	} elseif ($num <= 0x1FFFFF) {
659
		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
660
	}
661
	return " ";
662
}
663

  
664
// Function to convert a string from mixed html-entities/umlauts to pure utf-8-umlauts
665
function string_to_utf8($string, $charset=DEFAULT_CHARSET) {
666
	$charset = strtoupper($charset);
667
	if ($charset == '') { $charset = 'ISO-8859-1'; }
668

  
669
	if (!is_UTF8($string)) {
670
		$string=mb_convert_encoding_wrapper($string, 'UTF-8', $charset);
671
	}
672
	// check if we really get UTF-8. We don't get UTF-8 if charset is ISO-8859-6 or ISO-2022-JP/KR
673
	// and mb_string AND iconv aren't available.
674
	if (is_UTF8($string)) {
675
		$string=mb_convert_encoding_wrapper($string, 'HTML-ENTITIES', 'UTF-8');
676
		$string=mb_convert_encoding_wrapper($string, 'UTF-8', 'HTML-ENTITIES');
677
	} else {
678
		// nothing we can do here :-(
679
	}
680
	return($string);
681
}
682

  
683
// function to check if a string is UTF-8
684
function is_UTF8 ($str) {
685
	if (strlen($str) < 4000) {
686
		// see http://bugs.php.net/bug.php?id=24460 and http://bugs.php.net/bug.php?id=27070 and http://ilia.ws/archives/5-Top-10-ways-to-crash-PHP.html for this.
687
		// 4000 works for me ...
688
		return preg_match('/^(?:[\x09\x0A\x0D\x20-\x7E]|[\xC2-\xDF][\x80-\xBF]|\xE0[\xA0-\xBF][\x80-\xBF]|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}|\xED[\x80-\x9F][\x80-\xBF]|\xF0[\x90-\xBF][\x80-\xBF]{2}|[\xF1-\xF3][\x80-\xBF]{3}|\xF4[\x80-\x8F][\x80-\xBF]{2})*$/s', $str);
689
	}	else {
690
		$isUTF8 = true;
691
		while($str{0}) {
692
			if (preg_match("/^[\x09\x0A\x0D\x20-\x7E]/", $str)) { $str = substr($str, 1); continue; }
693
			if (preg_match("/^[\xC2-\xDF][\x80-\xBF]/", $str)) { $str = substr($str, 2); continue; }
694
			if (preg_match("/^\xE0[\xA0-\xBF][\x80-\xBF]/", $str)) { $str = substr($str, 3); continue; }
695
			if (preg_match("/^[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}/", $str)) { $str = substr($str, 3); continue; }
696
			if (preg_match("/^\xED[\x80-\x9F][\x80-\xBF]/", $str)) { $str = substr($str, 3); continue; }
697
			if (preg_match("/^\xF0[\x90-\xBF][\x80-\xBF]{2}/", $str)) { $str = substr($str, 4); continue; }
698
			if (preg_match("/^[\xF1-\xF3][\x80-\xBF]{3}/", $str)) { $str = substr($str, 4); continue; }
699
			if (preg_match("/^\xF4[\x80-\x8F][\x80-\xBF]{2}/", $str)) { $str = substr($str, 4); continue; }
700
			if (preg_match("/^$/", $str)) { break; }
701
			$isUTF8 = false;
702
			break;
703
		}
704
		return ($isUTF8);
705
	}
706
}
707

  
708
// Function to convert a string from mixed html-entities/umlauts to pure $charset_out-umlauts
709
function entities_to_umlauts($string, $charset_out=DEFAULT_CHARSET, $convert_htmlspecialchars=0) {
710
	$charset_out = strtoupper($charset_out);
711
	if ($charset_out == '') { $charset_out = 'ISO-8859-1'; }
712
	$charset_in = strtoupper(DEFAULT_CHARSET);
713
	
714
	// string to utf-8
715
	if ($charset_in == 'ISO-8859-1' || $charset_in == 'UTF-8') {
716
		if ($charset_in == 'ISO-8859-1') {
717
			$string=utf8_encode($string);
718
		}
719
		// decode html-entities
720
		if(preg_match("/&[#a-zA-Z0-9]+;/", $string)) {
721
			$string=string_decode_encode_entities($string, 'UTF-8', 'HTML-ENTITIES');
722
			//$string=mb_convert_encoding_wrapper($string, 'HTML-ENTITIES', 'UTF-8');
723
			//$string=mb_convert_encoding_wrapper($string, 'UTF-8', 'HTML-ENTITIES');
724
		}
725
	}
726
	else {
727
		$string = string_to_utf8($string); // will decode html-entities, too.
728
	}
729
	// string to $charset_out
730
	if($charset_out == 'ISO-8859-1') {
731
			$string=utf8_decode($string);
732
	}
733
	elseif($charset_out != 'UTF-8' && is_UTF8($string)) {
734
		$string=mb_convert_encoding_wrapper($string, $charset_out, 'UTF-8');
735
	}
736
	return $string;
737
}	
738

  
739
// Function to convert a string from mixed html-entitites/$charset_in-umlauts to pure html-entities
740
function umlauts_to_entities($string, $charset_in=DEFAULT_CHARSET, $convert_htmlspecialchars=0) {
741
	$charset_in = strtoupper($charset_in);
742
	if ($charset_in == "") { $charset_in = 'ISO-8859-1'; }
743

  
744
	// string to utf-8
745
	if ($charset_in == 'ISO-8859-1' || $charset_in == 'UTF-8') {
746
		if ($charset_in == 'ISO-8859-1') {
747
			$string=utf8_encode($string);
748
		}
749
		// encode html-entities
750
		$string=string_decode_encode_entities($string, 'HTML-ENTITIES', 'UTF-8'); // this is very slow!
751
		//$string=mb_convert_encoding_wrapper($string, 'HTML-ENTITIES', 'UTF-8');
752
	}
753
	else {
754
		$string = string_to_utf8($string, $charset_in);
755
		// encode html-entities
756
		if (is_UTF8($string)) {
757
			$string=string_decode_encode_entities($string, 'HTML-ENTITIES', 'UTF-8');
758
			//$string=mb_convert_encoding_wrapper($string, 'HTML-ENTITIES', 'UTF-8');
759
		}
760
	}
761
	return $string;
762
}
763

  
764
function umlauts_to_defcharset($string, $charset) {
765
		$charset_out = strtoupper(DEFAULT_CHARSET);
766
		if ($charset_out == "") { $charset_out = 'ISO-8859-1'; }
767
		
768
		if($charset_out == $charset) {
769
			return $string;
770
		}
771
		if($charset_out == 'ISO-8859-1' && $charset == 'UTF-8') {
772
			$string = utf8_decode($string);
773
		}
774
		else {
775
			$string=mb_convert_encoding_wrapper($string, $charset_out, 'UTF-8');
776
		}
777
		
778
	return $string;
779
}
780
	
781
// translate any latin/greek/cyrillic html-entities to their plain 7bit equivalents
782
// and numbered-entities into hex
783
function entities_to_7bit($string) {
784
	require(WB_PATH.'/framework/convert.php');
785
	$string = strtr($string, $conversion_array);
786
	$string = preg_replace('/&#([0-9]+);/e', "dechex('$1')",  $string);
787
	return($string);
788
}
789

  
790
// Function to convert a page title to a page filename
791
function page_filename($string) {
792
	$string = entities_to_7bit(umlauts_to_entities($string));
793
	// Now replace spaces with page spcacer
794
	$string = str_replace(' ', PAGE_SPACER, $string);
795
	// Now remove all bad characters
796
	$bad = array(
797
	'\'', /* /  */ '"', /* " */	'<', /* < */	'>', /* > */
798
	'{', /* { */	'}', /* } */	'[', /* [ */	']', /* ] */	'`', /* ` */
799
	'!', /* ! */	'@', /* @ */	'#', /* # */	'$', /* $ */	'%', /* % */
800
	'^', /* ^ */	'&', /* & */	'*', /* * */	'(', /* ( */	')', /* ) */
801
	'=', /* = */	'+', /* + */	'|', /* | */	'/', /* / */	'\\', /* \ */
802
	';', /* ; */	':', /* : */	',', /* , */	'?' /* ? */
803
	);
804
	$string = str_replace($bad, '', $string);
805
	// Now convert to lower-case
806
	$string = strtolower($string);
807
	// Now remove multiple page spacers
808
	$string = str_replace(PAGE_SPACER.PAGE_SPACER, PAGE_SPACER, $string);
809
	// Clean any page spacers at the end of string
810
	$string = str_replace(PAGE_SPACER, ' ', $string);
811
	$string = trim($string);
812
	$string = str_replace(' ', PAGE_SPACER, $string);
813
	// If there are any weird language characters, this will protect us against possible problems they could cause
814
	$string = str_replace(array('%2F', '%'), array('/', ''), urlencode($string));
815
	// Finally, return the cleaned string
816
	return $string;
817
}
818

  
819
// Function to convert a desired media filename to a clean filename
820
function media_filename($string) {
821
	$string = entities_to_7bit(umlauts_to_entities($string));
822
	// Now remove all bad characters
823
	$bad = array(
824
	'\'', // '
825
	'"', // "
826
	'`', // `
827
	'!', // !
828
	'@', // @
829
	'#', // #
830
	'$', // $
831
	'%', // %
832
	'^', // ^
833
	'&', // &
834
	'*', // *
835
	'=', // =
836
	'+', // +
837
	'|', // |
838
	'/', // /
839
	'\\', // \
840
	';', // ;
841
	':', // :
842
	',', // ,
843
	'?' // ?
844
	);
845
	$string = str_replace($bad, '', $string);
846
	// Clean any page spacers at the end of string
847
	$string = trim($string);
848
	// Finally, return the cleaned string
849
	return $string;
850
}
851

  
852
// Function to work out a page link
853
if(!function_exists('page_link')) {
854
	function page_link($link) {
855
		global $admin;
856
		return $admin->page_link($link);
857
	}
858
}
859

  
860
// Create a new file in the pages directory
861
function create_access_file($filename,$page_id,$level) {
862
	global $admin, $MESSAGE;
863
	if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/')) {
864
		$admin->print_error($MESSAGE['PAGES']['CANNOT_CREATE_ACCESS_FILE']);
865
	} else {
866
		// First make sure parent folder exists
867
		$parent_folders = explode('/',str_replace(WB_PATH.PAGES_DIRECTORY, '', dirname($filename)));
868
		$parents = '';
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff