Merge lp:~quam-plures-core/quam-plures/qp5_next_branch into lp:quam-plures
- qp5_next_branch
- Merge into trunk
Proposed by
EdB
Status: | Merged |
---|---|
Merged at revision: | 7661 |
Proposed branch: | lp:~quam-plures-core/quam-plures/qp5_next_branch |
Merge into: | lp:quam-plures |
Diff against target: |
63542 lines (+22188/-23862) 219 files modified
a_notemplate.php (+0/-1) admin.php (+69/-120) qp_config/_advanced.php (+1/-1) qp_config/_locales.php (+1/-1) qp_config/_upgrade.php (+0/-28) qp_inc/_application.php (+1/-1) qp_inc/_core/__core.init.php (+30/-19) qp_inc/_core/_class.funcs.php (+0/-10) qp_inc/_core/_misc.funcs.php (+5/-3) qp_inc/_core/_param.funcs.php (+21/-8) qp_inc/_core/model/__core.install.php (+32/-32) qp_inc/_core/model/_pagecache.class.php (+119/-150) qp_inc/_core/model/_timer.class.php (+52/-76) qp_inc/_core/model/dataobjects/_dataobject.class.php (+250/-233) qp_inc/_core/model/dataobjects/_dataobjectcache.class.php (+140/-174) qp_inc/_core/model/dataobjects/_dataobjectlist.class.php (+43/-48) qp_inc/_core/model/dataobjects/_dataobjectlist2.class.php (+64/-93) qp_inc/_core/model/db/_db.class.php (+405/-379) qp_inc/_core/model/db/_upgrade.funcs.php (+368/-333) qp_inc/_core/ui/_menu.class.php (+96/-117) qp_inc/_core/ui/_uiwidget.class.php (+9/-9) qp_inc/_core/ui/forms/_form.class.php (+816/-738) qp_inc/_core/ui/results/_results.class.php (+595/-583) qp_inc/_core/ui/results/_resultsel.class.php (+274/-266) qp_inc/_vars.inc.php (+50/-100) qp_inc/antispam/views/_ban.form.php (+1/-1) qp_inc/blogs/model/_blog.funcs.php (+4/-8) qp_inc/blogs/views/_blog_list.view.php (+43/-38) qp_inc/blogs/views/_blog_urls.form.php (+1/-1) qp_inc/blogs/views/_blog_user_perm.form.php (+0/-5) qp_inc/categories/views/_category.form.php (+1/-1) qp_inc/categories/views/_category_list.view.php (+92/-84) qp_inc/categories/views/_category_move.form.php (+1/-1) qp_inc/comments/model/_comment.funcs.php (+95/-110) qp_inc/comments/views/_comment.form.php (+1/-1) qp_inc/cron/_cron.funcs.php (+30/-43) qp_inc/cron/cronjobs.ctrl.php (+123/-165) qp_inc/cron/jobs/_prune_hits_sessions.job.php (+8/-7) qp_inc/cron/model/_cronjob.class.php (+49/-48) qp_inc/cron/views/_cronjob.form.php (+23/-48) qp_inc/cron/views/_cronjob.view.php (+43/-65) qp_inc/cron/views/_cronjob_list.view.php (+72/-73) qp_inc/dashboard/dashboard.ctrl.php (+1/-1) qp_inc/files/model/_filecache.class.php (+36/-50) qp_inc/files/model/_filelist.class.php (+260/-309) qp_inc/files/model/_fileroot.class.php (+94/-114) qp_inc/files/model/_filerootcache.class.php (+34/-55) qp_inc/files/model/_filetype.class.php (+72/-70) qp_inc/files/model/_filetypecache.class.php (+37/-58) qp_inc/files/views/_file_browse.view.php (+307/-337) qp_inc/files/views/_file_browse_set.form.php (+1/-1) qp_inc/files/views/_file_copy_move.form.php (+30/-76) qp_inc/files/views/_file_delete.form.php (+30/-66) qp_inc/files/views/_file_download.form.php (+31/-55) qp_inc/files/views/_file_edit.form.php (+21/-46) qp_inc/files/views/_file_links.view.php (+101/-127) qp_inc/files/views/_file_permissions.form.php (+85/-112) qp_inc/files/views/_file_properties.form.php (+44/-60) qp_inc/files/views/_file_rename.form.php (+26/-55) qp_inc/files/views/_file_upload.view.php (+298/-357) qp_inc/files/views/_filetype.form.php (+65/-100) qp_inc/files/views/_filetype_list.view.php (+79/-103) qp_inc/generic/model/_genericcache.class.php (+23/-38) qp_inc/generic/model/_genericcategory.class.php (+27/-54) qp_inc/generic/model/_genericcategorycache.class.php (+117/-137) qp_inc/generic/model/_genericelement.class.php (+37/-72) qp_inc/generic/model/_genericordered.class.php (+30/-61) qp_inc/generic/model/_genericorderedcache.class.php (+26/-55) qp_inc/generic/views/_generic_category.form.php (+24/-49) qp_inc/generic/views/_generic_list.inc.php (+63/-82) qp_inc/generic/views/_generic_ordered_list.inc.php (+69/-87) qp_inc/items/item_statuses.ctrl.php (+1/-1) qp_inc/items/items.ctrl.php (+13/-24) qp_inc/items/model/_item.class.php (+5/-5) qp_inc/items/model/_itemlight.class.php (+1/-1) qp_inc/items/model/_link.class.php (+36/-45) qp_inc/items/model/_linkcache.class.php (+36/-62) qp_inc/items/views/_item_history.view.php (+32/-55) qp_inc/items/views/_item_list_full.view.php (+182/-213) qp_inc/items/views/_item_list_sidebar.view.php (+117/-152) qp_inc/items/views/_item_list_table.view.php (+88/-96) qp_inc/items/views/_item_list_track.view.php (+194/-201) qp_inc/items/views/inc/_item_links.inc.php (+54/-83) qp_inc/locales/_charset.funcs.php (+0/-1) qp_inc/locales/_locale.funcs.php (+37/-29) qp_inc/locales/locales.ctrl.php (+14/-17) qp_inc/plugins/model/_plugins.class.php (+2/-2) qp_inc/plugins/model/_plugins_admin.class.php (+14/-14) qp_inc/plugins/model/_plugins_admin_no_db.class.php (+24/-35) qp_inc/plugins/model/_pluginsettings.class.php (+16/-37) qp_inc/plugins/model/_pluginusersettings.class.php (+35/-54) qp_inc/plugins/plugins.ctrl.php (+745/-928) qp_inc/plugins/views/_plugin_list.view.php (+161/-226) qp_inc/plugins/views/_plugin_list_available.view.php (+34/-62) qp_inc/plugins/views/_plugin_settings.form.php (+87/-143) qp_inc/sessions/_sessions.init.php (+46/-71) qp_inc/sessions/goals.ctrl.php (+140/-167) qp_inc/sessions/model/_goal.class.php (+50/-43) qp_inc/sessions/model/_hit.class.php (+2/-2) qp_inc/sessions/model/_hitlist.class.php (+1/-1) qp_inc/sessions/model/_hitlog.funcs.php (+15/-40) qp_inc/sessions/model/_sessions.install.php (+32/-55) qp_inc/sessions/views/_goal.form.php (+30/-40) qp_inc/sessions/views/_goal_hitsummary.view.php (+47/-58) qp_inc/sessions/views/_stats_browserhits.view.php (+57/-73) qp_inc/sessions/views/_stats_direct.view.php (+48/-66) qp_inc/sessions/views/_stats_goalhits.view.php (+139/-129) qp_inc/sessions/views/_stats_goals.view.php (+74/-79) qp_inc/sessions/views/_stats_hit_list.view.php (+128/-141) qp_inc/sessions/views/_stats_refdomains.view.php (+88/-100) qp_inc/sessions/views/_stats_refsearches.view.php (+71/-84) qp_inc/sessions/views/_stats_robots.view.php (+80/-101) qp_inc/sessions/views/_stats_search_keywords.view.php (+154/-147) qp_inc/sessions/views/_stats_sessions.view.php (+34/-51) qp_inc/sessions/views/_stats_sessions_list.view.php (+65/-80) qp_inc/sessions/views/_stats_summary.view.php (+120/-140) qp_inc/sessions/views/_stats_syndication.view.php (+38/-55) qp_inc/sessions/views/_stats_useragents.view.php (+78/-93) qp_inc/settings/model/_abstractsettings.class.php (+316/-357) qp_inc/templates/model/_template.class.php (+11/-11) qp_inc/templates/model/_templatecache.class.php (+2/-2) qp_inc/templates/views/_template.form.php (+2/-2) qp_inc/templates/views/_template_list_available.view.php (+1/-1) qp_inc/templates/views/_template_list_installed.view.php (+4/-4) qp_inc/templates/views/_template_select.view.php (+3/-3) qp_inc/tools/tools.ctrl.php (+10/-6) qp_inc/tools/views/_phpinfo.view.php (+7/-4) qp_inc/tools/views/_system_list.view.php (+123/-194) qp_inc/users/model/_group.class.php (+334/-288) qp_inc/users/model/_user.class.php (+2/-2) qp_inc/users/model/_user.funcs.php (+127/-113) qp_inc/users/model/_usercache.class.php (+63/-83) qp_inc/users/model/_usersettings.class.php (+58/-85) qp_inc/users/views/_group.form.php (+114/-156) qp_inc/users/views/_user.form.php (+1/-1) qp_inc/users/views/_user_list.view.php (+186/-214) qp_inc/widgets/_bloglist.widget.php (+19/-0) qp_inc/widgets/_category_list.widget.php (+34/-7) qp_inc/widgets/_comment_list.widget.php (+28/-2) qp_inc/widgets/_common_links.widget.php (+22/-1) qp_inc/widgets/_free_html.widget.php (+19/-0) qp_inc/widgets/_item_list.widget.php (+47/-2) qp_inc/widgets/_link_list.widget.php (+28/-3) qp_inc/widgets/_linkblog.widget.php (+34/-3) qp_inc/widgets/_logo.widget.php (+28/-2) qp_inc/widgets/_longdesc.widget.php (+16/-0) qp_inc/widgets/_media_index.widget.php (+52/-2) qp_inc/widgets/_menu_link.widget.php (+39/-5) qp_inc/widgets/_page_list.widget.php (+28/-3) qp_inc/widgets/_post_list.widget.php (+28/-3) qp_inc/widgets/_related_post_list.widget.php (+28/-3) qp_inc/widgets/_search_form.widget.php (+19/-0) qp_inc/widgets/_single_item.widget.php (+28/-3) qp_inc/widgets/_tag_cloud.widget.php (+27/-2) qp_inc/widgets/_tagline.widget.php (+18/-3) qp_inc/widgets/_title.widget.php (+18/-2) qp_inc/widgets/_user_tools.widget.php (+23/-0) qp_inc/widgets/_xml_feeds.widget.php (+22/-0) qp_inc/widgets/model/_widget.class.php (+3/-3) qp_inc/widgets/model/_widgetcache.class.php (+2/-2) qp_inc/widgets/views/_widget.form.php (+1/-1) qp_inc/widgets/views/_widget_list.view.php (+24/-27) qp_inc/widgets/widgets.ctrl.php (+6/-6) qp_inc/xmlrpc/apis/_blogger.api.php (+166/-177) qp_inc/xmlrpc/model/_xmlrpc.funcs.php (+11/-8) qp_install/_functions_create.php (+29/-49) qp_install/_functions_install.php (+32/-28) qp_install/index.php (+5/-10) qp_locales/de/_global.php (+2511/-0) qp_locales/de/de-DE.locale.php (+27/-0) qp_locales/en/en-AU.locale.php (+27/-0) qp_locales/en/en-CA.locale.php (+27/-0) qp_locales/en/en-GB.locale.php (+27/-0) qp_locales/en/en-IL.locale.php (+27/-0) qp_locales/en/en-NZ.locale.php (+27/-0) qp_locales/en/en-SG.locale.php (+27/-0) qp_locales/fr/_global.php (+2335/-0) qp_locales/fr/fr-BE.locale.php (+27/-0) qp_locales/fr/fr-CA.locale.php (+27/-0) qp_locales/fr/fr-FR.locale.php (+27/-0) qp_locales/php/de/_global.php (+0/-2507) qp_locales/php/de/de-DE.locale.php (+0/-21) qp_locales/php/en/en-AU.locale.php (+0/-21) qp_locales/php/en/en-CA.locale.php (+0/-21) qp_locales/php/en/en-GB.locale.php (+0/-21) qp_locales/php/en/en-IL.locale.php (+0/-21) qp_locales/php/en/en-NZ.locale.php (+0/-21) qp_locales/php/en/en-SG.locale.php (+0/-21) qp_locales/php/fr/_global.php (+0/-2331) qp_locales/php/fr/fr-BE.locale.php (+0/-21) qp_locales/php/fr/fr-CA.locale.php (+0/-21) qp_locales/php/fr/fr-FR.locale.php (+0/-21) qp_locales/php/ru/_global.php (+0/-2465) qp_locales/php/ru/ru-RU.locale.php (+0/-21) qp_locales/php/tr/_global.php (+0/-2137) qp_locales/php/tr/tr-TR.locale.php (+0/-21) qp_locales/ru/_global.php (+2469/-0) qp_locales/ru/ru-RU.locale.php (+27/-0) qp_locales/tr/_global.php (+2141/-0) qp_locales/tr/tr-TR.locale.php (+27/-0) qp_plugins/twitter_plugin/_twitter.plugin.php (+1/-1) qp_rsc/js/communication.js (+2/-4) qp_srvc/comment_post.php (+34/-45) qp_srvc/cron_exec.php (+46/-39) qp_srvc/login.php (+316/-317) qp_srvc/track.php (+33/-40) qp_view_admin/_access_denied.main.php (+10/-8) qp_view_admin/_adminUI_general.class.php (+3/-3) qp_view_admin/_html_footer.inc.php (+27/-46) qp_view_admin/admin.global.css (+1/-1) qp_view_admin/conf_error.main.php (+20/-26) qp_view_admin/earth/_adminUI.class.php (+22/-33) qp_view_admin/earth/style.css (+4/-76) qp_view_admin/fire/_adminUI.class.php (+22/-33) qp_view_admin/fire/style.css (+5/-86) qp_view_admin/water/_adminUI.class.php (+22/-33) qp_view_admin/water/style.css (+5/-77) qp_view_admin/wind/_adminUI.class.php (+22/-33) qp_view_admin/wind/style.css (+4/-75) |
To merge this branch: | bzr merge lp:~quam-plures-core/quam-plures/qp5_next_branch |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Quam Plures Core Team | Pending | ||
Review via email: mp+153917@code.launchpad.net |
Commit message
Description of the change
http://
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'a_notemplate.php' | |||
2 | --- a_notemplate.php 2012-07-29 20:36:41 +0000 | |||
3 | +++ a_notemplate.php 2013-03-20 18:13:29 +0000 | |||
4 | @@ -51,7 +51,6 @@ | |||
5 | 51 | // --------------------- PAGE LEVEL CACHING SUPPORT --------------------- | 51 | // --------------------- PAGE LEVEL CACHING SUPPORT --------------------- |
6 | 52 | // This is totally optional. General caching must be enabled | 52 | // This is totally optional. General caching must be enabled |
7 | 53 | // in Global settings, otherwise this will do nothing. | 53 | // in Global settings, otherwise this will do nothing. |
8 | 54 | load_class( '_core/model/_pagecache.class.php' ); | ||
9 | 55 | $PageCache = new PageCache( NULL ); | 54 | $PageCache = new PageCache( NULL ); |
10 | 56 | 55 | ||
11 | 57 | // Check for cached content & Start caching if needed: | 56 | // Check for cached content & Start caching if needed: |
12 | 58 | 57 | ||
13 | === modified file 'admin.php' | |||
14 | --- admin.php 2011-01-09 17:19:59 +0000 | |||
15 | +++ admin.php 2013-03-20 18:13:29 +0000 | |||
16 | @@ -1,183 +1,131 @@ | |||
17 | 1 | <?php | 1 | <?php |
18 | 2 | /** | 2 | /** |
53 | 3 | * This is the main dispatcher for the admin interface. | 3 | * This is the main dispatcher for the admin interface |
54 | 4 | * | 4 | * |
55 | 5 | * IF YOU ARE READING THIS IN YOUR WEB BROWSER, IT MEANS THAT PHP IS NOT PROPERLY INSTALLED | 5 | * IF YOU ARE READING THIS IN YOUR WEB BROWSER, IT MEANS THAT PHP IS NOT PROPERLY |
56 | 6 | * ON YOUR WEB SERVER. IF YOU DON'T KNOW WHAT THIS MEANS, CONTACT YOUR SERVER ADMINISTRATOR | 6 | * INSTALLED ON YOUR WEB SERVER. IF YOU DON'T KNOW WHAT THIS MEANS, CONTACT YOUR |
57 | 7 | * OR YOUR HOSTING COMPANY. | 7 | * SERVER ADMINISTRATOR OR YOUR HOSTING COMPANY. |
58 | 8 | * | 8 | * |
59 | 9 | * This file is part of Quam Plures - {@link http://quamplures.net/} | 9 | * @todo (3048) EdB> this file is 1 of 2 that sets the default admin template (part of "Get the Admin template") |
60 | 10 | * See also {@link https://launchpad.net/quam-plures}. | 10 | * @todo (1111) the "Redirect old-style URLs" check is probably obsolete |
61 | 11 | * | 11 | * @author {@link http://wonderwinds.com/ Ed Bennett} |
62 | 12 | * @copyright (c) 2009 - 2011 by the Quam Plures developers - {@link http://quamplures.net/} | 12 | * @author {@link http://progidistri.com/ PROGIDISTRI} |
63 | 13 | * @copyright (c)2003-2009 by Francois PLANQUE - {@link http://fplanque.net/} | 13 | * @author {@link http://daniel.hahler.de/ Daniel HAHLER} |
64 | 14 | * Parts of this file are copyright (c)2004-2006 by Daniel HAHLER - {@link http://thequod.de/contact}. | 14 | * @author {@link http://fplanque.net/ Francois PLANQUE} |
65 | 15 | * Parts of this file are copyright (c)2005-2006 by PROGIDISTRI - {@link http://progidistri.com/}. | 15 | * @copyright (c) 2009 by {@link http://quamplures.net/ the Quam Plures project} |
66 | 16 | * | 16 | * @license http://www.gnu.org/licenses/gpl.txt GNU General Public License v3 |
67 | 17 | * {@internal License choice | 17 | * @package admin |
34 | 18 | * - If you have received this file as part of a package, please find the license.txt file in | ||
35 | 19 | * the same folder or the closest folder above for complete license terms. | ||
36 | 20 | * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/) | ||
37 | 21 | * then you must choose one of the following licenses before using the file: | ||
38 | 22 | * - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php | ||
39 | 23 | * - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php | ||
40 | 24 | * }} | ||
41 | 25 | * | ||
42 | 26 | * {@internal Open Source relicensing agreement: | ||
43 | 27 | * Daniel HAHLER grants Francois PLANQUE the right to license | ||
44 | 28 | * Daniel HAHLER's contributions to this file and the b2evolution project | ||
45 | 29 | * under any OSI approved OSS license (http://www.opensource.org/licenses/). | ||
46 | 30 | * | ||
47 | 31 | * PROGIDISTRI S.A.S. grants Francois PLANQUE the right to license | ||
48 | 32 | * PROGIDISTRI S.A.S.'s contributions to this file and the b2evolution project | ||
49 | 33 | * under any OSI approved OSS license (http://www.opensource.org/licenses/). | ||
50 | 34 | * }} | ||
51 | 35 | * | ||
52 | 36 | * @package pond | ||
68 | 37 | */ | 18 | */ |
69 | 38 | 19 | ||
70 | 39 | |||
71 | 40 | /** | 20 | /** |
73 | 41 | * Do the MAIN initializations: | 21 | * Load the configuration minimum |
74 | 42 | */ | 22 | */ |
75 | 43 | require_once dirname(__FILE__).'/qp_config/_config.php'; | 23 | require_once dirname(__FILE__).'/qp_config/_config.php'; |
76 | 44 | 24 | ||
81 | 45 | 25 | // Is this an admin page? Use is_admin_page() to query it because it may change | |
78 | 46 | /** | ||
79 | 47 | * @global boolean Is this an admin page? Use {@link is_admin_page()} to query it, because it may change. | ||
80 | 48 | */ | ||
82 | 49 | $is_admin_page = true; | 26 | $is_admin_page = true; |
83 | 50 | |||
84 | 51 | |||
85 | 52 | $login_required = true; | 27 | $login_required = true; |
86 | 28 | |||
87 | 29 | /** | ||
88 | 30 | * Main initialization, without a specific blog identified | ||
89 | 31 | */ | ||
90 | 53 | require_once $inc_path.'_main.inc.php'; | 32 | require_once $inc_path.'_main.inc.php'; |
91 | 54 | 33 | ||
94 | 55 | 34 | // Check global permission | |
93 | 56 | // Check global permission: | ||
95 | 57 | if( ! $current_User->check_perm( 'admin', 'any' ) ) | 35 | if( ! $current_User->check_perm( 'admin', 'any' ) ) |
97 | 58 | { // No permission to access admin... | 36 | { |
98 | 37 | // No permission to access admin... | ||
99 | 59 | require $admintemplates_path.'_access_denied.main.php'; | 38 | require $admintemplates_path.'_access_denied.main.php'; |
100 | 60 | } | 39 | } |
101 | 61 | 40 | ||
104 | 62 | 41 | /** | |
103 | 63 | /* | ||
105 | 64 | * Asynchronous processing options that may be required on any page | 42 | * Asynchronous processing options that may be required on any page |
106 | 65 | */ | 43 | */ |
107 | 66 | require_once $inc_path.'_async.inc.php'; | 44 | require_once $inc_path.'_async.inc.php'; |
108 | 67 | 45 | ||
115 | 68 | 46 | // Get the blog from param, defaulting to the last selected one for this user: | |
116 | 69 | /* | 47 | // we need it for quite a few of the menu urls |
117 | 70 | * Get the blog from param, defaulting to the last selected one for this user: | 48 | $user_selected_blog = (int)$UserSettings->get( 'selected_blog' ); |
112 | 71 | * we need it for quite a few of the menu urls | ||
113 | 72 | */ | ||
114 | 73 | $user_selected_blog = (int)$UserSettings->get('selected_blog'); | ||
118 | 74 | $BlogCache = & get_Cache( 'BlogCache' ); | 49 | $BlogCache = & get_Cache( 'BlogCache' ); |
122 | 75 | if( param( 'blog', 'integer', NULL, true ) === NULL // We got no explicit blog choice (not even '0' for 'no blog'): | 50 | if( param( 'blog', 'integer', NULL, true ) === NULL // no explicit blog choice, not even '0' for 'no blog' |
123 | 76 | || ($blog > 0 && ! ($Blog = & $BlogCache->get_by_ID( $blog, false, false )) )) // or we requested a nonexistent blog | 51 | || ( $blog > 0 && ! ( $Blog = & $BlogCache->get_by_ID( $blog, false, false ) ) ) ) // we requested a nonexistent blog |
124 | 77 | { // Try the memorized blog from the previous action: | 52 | { |
125 | 53 | // Try the memorized blog from the previous action | ||
126 | 78 | $blog = $user_selected_blog; | 54 | $blog = $user_selected_blog; |
129 | 79 | if( ! ($Blog = & $BlogCache->get_by_ID( $blog, false, false ) ) ) | 55 | if( ! ( $Blog = & $BlogCache->get_by_ID( $blog, false, false ) ) ) |
130 | 80 | { // That one doesn't exist either... | 56 | { |
131 | 57 | // That one doesn't exist either... | ||
132 | 81 | $blog = 0; | 58 | $blog = 0; |
133 | 82 | } | 59 | } |
134 | 83 | } | 60 | } |
135 | 84 | elseif( $blog != $user_selected_blog ) | 61 | elseif( $blog != $user_selected_blog ) |
137 | 85 | { // We have selected a new & valid blog. Update UserSettings for selected blog: | 62 | { |
138 | 63 | // We have selected a new & valid blog. Update UserSettings for selected blog | ||
139 | 86 | set_working_blog( $blog ); | 64 | set_working_blog( $blog ); |
140 | 87 | } | 65 | } |
141 | 88 | 66 | ||
144 | 89 | 67 | // bookmarklet, upload (upload actually means sth like: select img for post) | |
143 | 90 | // bookmarklet, upload (upload actually means sth like: select img for post): | ||
145 | 91 | param( 'mode', 'string', '', true ); | 68 | param( 'mode', 'string', '', true ); |
146 | 92 | 69 | ||
152 | 93 | 70 | // Get the Admin template | |
148 | 94 | /* | ||
149 | 95 | * Get the Admin template | ||
150 | 96 | * TODO: Allow setting through GET param (dropdown in backoffice), respecting a checkbox "Use different setting on each computer" (if cookie_state handling is ready) | ||
151 | 97 | */ | ||
153 | 98 | $admin_template = $UserSettings->get( 'admin_template' ); | 71 | $admin_template = $UserSettings->get( 'admin_template' ); |
154 | 99 | $admin_template_path = $admintemplates_path.'%s/_adminUI.class.php'; | 72 | $admin_template_path = $admintemplates_path.'%s/_adminUI.class.php'; |
155 | 100 | 73 | ||
156 | 101 | if( ! $admin_template || ! file_exists( sprintf( $admin_template_path, $admin_template ) ) ) | 74 | if( ! $admin_template || ! file_exists( sprintf( $admin_template_path, $admin_template ) ) ) |
167 | 102 | { // there's no template for the user | 75 | { |
168 | 103 | if( !$admin_template ) | 76 | // there's no template for the user |
159 | 104 | { | ||
160 | 105 | $Debuglog->add( 'The user has no admin template set.', 'template' ); | ||
161 | 106 | } | ||
162 | 107 | else | ||
163 | 108 | { | ||
164 | 109 | $Debuglog->add( 'The admin template ['.$admin_template.'] set by the user does not exist.', 'template' ); | ||
165 | 110 | } | ||
166 | 111 | |||
169 | 112 | $admin_template = $Settings->get( 'default_admin_template' ); | 77 | $admin_template = $Settings->get( 'default_admin_template' ); |
170 | 113 | 78 | ||
184 | 114 | if( !$admin_template || !file_exists( sprintf( $admin_template_path, $admin_template ) ) ) | 79 | if( ! $admin_template || ! file_exists( sprintf( $admin_template_path, $admin_template ) ) ) |
185 | 115 | { // even the default template does not exist! | 80 | { |
186 | 116 | if( !$admin_template ) | 81 | // even the default template does not exist! |
187 | 117 | { | 82 | // set 'wind' as the admin template if it exists |
188 | 118 | $Debuglog->add( 'There is no default admin template set!', 'template' ); | 83 | if( file_exists( sprintf( $admin_template_path, 'wind' ) ) ) |
189 | 119 | } | 84 | { |
177 | 120 | else | ||
178 | 121 | { | ||
179 | 122 | $Debuglog->add( 'The default admin template ['.$admin_template.'] does not exist!', array('template','error') ); | ||
180 | 123 | } | ||
181 | 124 | |||
182 | 125 | if( file_exists(sprintf( $admin_template_path, 'wind' )) ) | ||
183 | 126 | { // 'wind' - the official starting template - exist | ||
190 | 127 | $admin_template = 'wind'; | 85 | $admin_template = 'wind'; |
191 | 128 | |||
192 | 129 | $Debuglog->add( 'Falling back to "wind" admin template.', 'template' ); | ||
193 | 130 | } | 86 | } |
194 | 131 | else | 87 | else |
196 | 132 | { // get the first one available one | 88 | { |
197 | 89 | // get the first one available one | ||
198 | 133 | $admin_template_dirs = get_admin_templates(); | 90 | $admin_template_dirs = get_admin_templates(); |
199 | 134 | 91 | ||
200 | 135 | if( $admin_template_dirs === false ) | 92 | if( $admin_template_dirs === false ) |
201 | 136 | { | 93 | { |
203 | 137 | $Debuglog->add( 'No admin template found! Check that the path '.$admintemplates_path.' exists.', array('template','error') ); | 94 | // debuglog->add removed |
204 | 138 | } | 95 | } |
208 | 139 | elseif( empty($admin_template_dirs) ) | 96 | elseif( empty( $admin_template_dirs ) ) |
209 | 140 | { // No admin template directories found | 97 | { |
210 | 141 | $Debuglog->add( 'No admin template found! Check that there are templates in '.$admintemplates_path.'.', array('template','error') ); | 98 | // No admin template directories found |
211 | 99 | // debuglog->add removed | ||
212 | 142 | } | 100 | } |
213 | 143 | else | 101 | else |
214 | 144 | { | 102 | { |
217 | 145 | $admin_template = array_shift($admin_template_dirs); | 103 | $admin_template = array_shift( $admin_template_dirs ); |
216 | 146 | $Debuglog->add( 'Falling back to first available template.', 'template' ); | ||
218 | 147 | } | 104 | } |
219 | 148 | } | 105 | } |
220 | 149 | } | 106 | } |
221 | 150 | } | 107 | } |
222 | 108 | |||
223 | 109 | // we die without an admin template | ||
224 | 151 | if( ! $admin_template ) | 110 | if( ! $admin_template ) |
225 | 152 | { | 111 | { |
226 | 153 | $Debuglog->display( 'No admin template available!', '', true, 'template' ); | 112 | $Debuglog->display( 'No admin template available!', '', true, 'template' ); |
227 | 154 | die(1); | 113 | die(1); |
228 | 155 | } | 114 | } |
229 | 156 | 115 | ||
230 | 157 | $Debuglog->add( 'Using admin template «'.$admin_template.'»', 'template' ); | ||
231 | 158 | |||
232 | 159 | /** | 116 | /** |
234 | 160 | * Load the AdminUI class for the template. | 117 | * Load the AdminUI class for the template |
235 | 161 | */ | 118 | */ |
236 | 162 | require_once $admintemplates_path.$admin_template.'/_adminUI.class.php'; | 119 | require_once $admintemplates_path.$admin_template.'/_adminUI.class.php'; |
242 | 163 | /** | 120 | |
243 | 164 | * This is the Admin UI object which handles the UI for the backoffice. | 121 | // This is the Admin UI object which handles the UI for the backoffice |
239 | 165 | * | ||
240 | 166 | * @global AdminUI | ||
241 | 167 | */ | ||
244 | 168 | $AdminUI = new AdminUI(); | 122 | $AdminUI = new AdminUI(); |
245 | 169 | 123 | ||
252 | 170 | 124 | // Pass over to controller ... get requested controller and memorize it | |
247 | 171 | /* | ||
248 | 172 | * Pass over to controller... | ||
249 | 173 | */ | ||
250 | 174 | |||
251 | 175 | // Get requested controller and memorize it: | ||
253 | 176 | param( 'ctrl', '/^[a-z0-9_]+$/', 'dashboard', true ); | 125 | param( 'ctrl', '/^[a-z0-9_]+$/', 'dashboard', true ); |
254 | 177 | 126 | ||
258 | 178 | 127 | // Redirect old-style URLs (e.g. /admin/plugins.php), if they come here because the webserver | |
259 | 179 | // Redirect old-style URLs (e.g. /admin/plugins.php), if they come here because the webserver maps "/admin/" to "/admin.php" | 128 | // maps "/admin/" to "/admin.php" NOTE: this is just meant as a transformation from pre-1.8 to 1.8! |
257 | 180 | // NOTE: this is just meant as a transformation from pre-1.8 to 1.8! | ||
260 | 181 | if( ! empty( $_SERVER['PATH_INFO'] ) && $_SERVER['PATH_INFO'] != $_SERVER['PHP_SELF'] ) // the "!= PHP_SELF" check seems needed by IIS.. | 129 | if( ! empty( $_SERVER['PATH_INFO'] ) && $_SERVER['PATH_INFO'] != $_SERVER['PHP_SELF'] ) // the "!= PHP_SELF" check seems needed by IIS.. |
261 | 182 | { | 130 | { |
262 | 183 | // Try to find the appropriate controller (ctrl) setting | 131 | // Try to find the appropriate controller (ctrl) setting |
263 | @@ -196,7 +144,7 @@ | |||
264 | 196 | $query_string = explode( '&', $_SERVER['QUERY_STRING'] ); | 144 | $query_string = explode( '&', $_SERVER['QUERY_STRING'] ); |
265 | 197 | foreach( $query_string as $k => $v ) | 145 | foreach( $query_string as $k => $v ) |
266 | 198 | { | 146 | { |
268 | 199 | $query_string[$k] = strip_tags($v); | 147 | $query_string[$k] = strip_tags( $v ); |
269 | 200 | } | 148 | } |
270 | 201 | $query_string = '&'.implode( '&', $query_string ); | 149 | $query_string = '&'.implode( '&', $query_string ); |
271 | 202 | } | 150 | } |
272 | @@ -209,14 +157,15 @@ | |||
273 | 209 | exit(0); | 157 | exit(0); |
274 | 210 | } | 158 | } |
275 | 211 | 159 | ||
279 | 212 | 160 | // Check matching controller file | |
280 | 213 | // Check matching controller file: | 161 | if( ! isset( $ctrl_mappings[$ctrl] ) ) |
278 | 214 | if( !isset($ctrl_mappings[$ctrl]) ) | ||
281 | 215 | { | 162 | { |
282 | 216 | debug_die( 'The requested controller ['.$ctrl.'] does not exist.' ); | 163 | debug_die( 'The requested controller ['.$ctrl.'] does not exist.' ); |
283 | 217 | } | 164 | } |
284 | 218 | 165 | ||
286 | 219 | // Call the requested controller: | 166 | /** |
287 | 167 | * Call the requested controller | ||
288 | 168 | */ | ||
289 | 220 | require $inc_path.$ctrl_mappings[$ctrl]; | 169 | require $inc_path.$ctrl_mappings[$ctrl]; |
290 | 221 | 170 | ||
291 | 222 | ?> | 171 | ?> |
292 | 223 | 172 | ||
293 | === modified file 'qp_config/_advanced.php' | |||
294 | --- qp_config/_advanced.php 2011-09-05 06:55:25 +0000 | |||
295 | +++ qp_config/_advanced.php 2013-03-20 18:13:29 +0000 | |||
296 | @@ -515,7 +515,7 @@ | |||
297 | 515 | /** | 515 | /** |
298 | 516 | * File extensions that the admin will not be able to enable in the Settings | 516 | * File extensions that the admin will not be able to enable in the Settings |
299 | 517 | */ | 517 | */ |
301 | 518 | $force_upload_forbiddenext = array( 'cgi', 'exe', 'htaccess', 'htpasswd', 'php', 'php3', 'php4', 'php5', 'php6', 'phtml', 'pl', 'vbs' ); | 518 | $forbidden_upload_exts = array( 'cgi', 'exe', 'htaccess', 'htpasswd', 'php', 'php3', 'php4', 'php5', 'php6', 'phtml', 'pl', 'vbs' ); |
302 | 519 | 519 | ||
303 | 520 | /** | 520 | /** |
304 | 521 | * Admin can configure max file upload size, but he won't be able to set it higher than this "max max" value. | 521 | * Admin can configure max file upload size, but he won't be able to set it higher than this "max max" value. |
305 | 522 | 522 | ||
306 | === modified file 'qp_config/_locales.php' | |||
307 | --- qp_config/_locales.php 2013-02-28 16:40:18 +0000 | |||
308 | +++ qp_config/_locales.php 2013-03-20 18:13:29 +0000 | |||
309 | @@ -88,7 +88,7 @@ | |||
310 | 88 | * - 'datefmt' : The date format for this language. See {@link date_i18n()}. | 88 | * - 'datefmt' : The date format for this language. See {@link date_i18n()}. |
311 | 89 | * - 'timefmt' : The time format for this language. See {@link date_i18n()}. | 89 | * - 'timefmt' : The time format for this language. See {@link date_i18n()}. |
312 | 90 | * - 'startofweek': Start of week for this locale. 0 means Sunday, 1 Monday etc. | 90 | * - 'startofweek': Start of week for this locale. 0 means Sunday, 1 Monday etc. |
314 | 91 | * - 'messages' : The locale's directory name (contains php/_global.php; ONLY USED HERE). | 91 | * - 'messages' : The locale's directory name (contains _global.php; ONLY USED HERE). |
315 | 92 | * - 'enabled' : Is the locale visible to the user (ONLY USED HERE)? | 92 | * - 'enabled' : Is the locale visible to the user (ONLY USED HERE)? |
316 | 93 | */ | 93 | */ |
317 | 94 | $locales['en-US'] = array( | 94 | $locales['en-US'] = array( |
318 | 95 | 95 | ||
319 | === removed file 'qp_config/_upgrade.php' | |||
320 | --- qp_config/_upgrade.php 2010-12-31 12:12:03 +0000 | |||
321 | +++ qp_config/_upgrade.php 1970-01-01 00:00:00 +0000 | |||
322 | @@ -1,28 +0,0 @@ | |||
323 | 1 | <?php | ||
324 | 2 | /** | ||
325 | 3 | * This file includes upgrade settings for Quam Plures. | ||
326 | 4 | * | ||
327 | 5 | * Quam Plures - {@link http://quamplures.net/} | ||
328 | 6 | * Released under GNU GPL License - {@link http://quamplures.net/license.html} | ||
329 | 7 | * @copyright (c) 2009 - 2011 by the Quam Plures developers - {@link http://quamplures.net/} | ||
330 | 8 | * @copyright (c)2003-2009 by Francois PLANQUE - {@link http://fplanque.net/} | ||
331 | 9 | * | ||
332 | 10 | * @package pond | ||
333 | 11 | */ | ||
334 | 12 | if( !defined('QP_CONFIG_LOADED') ) die( 'Please, do not access this page directly.' ); | ||
335 | 13 | |||
336 | 14 | |||
337 | 15 | /**#@+ | ||
338 | 16 | * Old b2 tables used exclusively by the cafelog upgrade mode of the install script. | ||
339 | 17 | * | ||
340 | 18 | * @global string | ||
341 | 19 | */ | ||
342 | 20 | $oldtableposts = 'b2posts'; | ||
343 | 21 | $oldtableusers = 'b2users'; | ||
344 | 22 | $oldtablesettings = 'b2settings'; | ||
345 | 23 | $oldtablecategories = 'b2categories'; | ||
346 | 24 | $oldtablecomments = 'b2comments'; | ||
347 | 25 | /**#@-*/ | ||
348 | 26 | |||
349 | 27 | |||
350 | 28 | ?> | ||
351 | 29 | 0 | ||
352 | === modified file 'qp_inc/_application.php' | |||
353 | --- qp_inc/_application.php 2013-03-12 06:26:03 +0000 | |||
354 | +++ qp_inc/_application.php 2013-03-20 18:13:29 +0000 | |||
355 | @@ -30,7 +30,7 @@ | |||
356 | 30 | $app_date = '2013-03-21'; | 30 | $app_date = '2013-03-21'; |
357 | 31 | 31 | ||
358 | 32 | // Displayed on the login screen | 32 | // Displayed on the login screen |
360 | 33 | $app_banner = '<a href="'.$app_homepage.'"><img src="'.$rsc_url.'img/qp-logo.jpg" width="337" height="76" alt="'.$app_name.'" /></a>'; | 33 | $app_banner = '<a href="'.$app_homepage.'"><img src="'.$rsc_url.'logo.jpg" width="337" height="76" alt="'.$app_name.'" /></a>'; |
361 | 34 | 34 | ||
362 | 35 | // Displayed on admin pages (footer) | 35 | // Displayed on admin pages (footer) |
363 | 36 | $app_footer_text = '<a href="'.$app_homepage.'" title="'.sprintf( T_('visit %s\' website'), $app_name ).'"><strong>'.$app_name.' v'.$app_version.'</strong></a>' | 36 | $app_footer_text = '<a href="'.$app_homepage.'" title="'.sprintf( T_('visit %s\' website'), $app_name ).'"><strong>'.$app_name.' v'.$app_version.'</strong></a>' |
364 | 37 | 37 | ||
365 | === modified file 'qp_inc/_core/__core.init.php' | |||
366 | --- qp_inc/_core/__core.init.php 2013-03-13 02:35:35 +0000 | |||
367 | +++ qp_inc/_core/__core.init.php 2013-03-20 18:13:29 +0000 | |||
368 | @@ -30,33 +30,47 @@ | |||
369 | 30 | 'T_antispam' => $app_db_tableprefix.'antispam', | 30 | 'T_antispam' => $app_db_tableprefix.'antispam', |
370 | 31 | 'T_blogs' => $app_db_tableprefix.'blogs', | 31 | 'T_blogs' => $app_db_tableprefix.'blogs', |
371 | 32 | 'T_categories' => $app_db_tableprefix.'categories', | 32 | 'T_categories' => $app_db_tableprefix.'categories', |
374 | 33 | 'T_coll_group_perms' => $app_db_tableprefix.'bloggroups', | 33 | 'T_blog_groups' => $app_db_tableprefix.'bloggroups', // new |
375 | 34 | 'T_coll_user_perms' => $app_db_tableprefix.'blogusers', | 34 | 'T_coll_group_perms' => $app_db_tableprefix.'bloggroups', // old, going away |
376 | 35 | 'T_blog_users' => $app_db_tableprefix.'blogusers', // new | ||
377 | 36 | 'T_coll_user_perms' => $app_db_tableprefix.'blogusers', // old, going away | ||
378 | 35 | 'T_comments' => $app_db_tableprefix.'comments', | 37 | 'T_comments' => $app_db_tableprefix.'comments', |
381 | 36 | 'T_cron__log' => $app_db_tableprefix.'cron__log', | 38 | 'T_cron_log' => $app_db_tableprefix.'cron__log', // new |
382 | 37 | 'T_cron__task' => $app_db_tableprefix.'cron__task', | 39 | 'T_cron__log' => $app_db_tableprefix.'cron__log', // old, going away |
383 | 40 | 'T_cron_task' => $app_db_tableprefix.'cron__task', // new | ||
384 | 41 | 'T_cron__task' => $app_db_tableprefix.'cron__task', // old, going away | ||
385 | 38 | 'T_files' => $app_db_tableprefix.'files', | 42 | 'T_files' => $app_db_tableprefix.'files', |
386 | 39 | 'T_filetypes' => $app_db_tableprefix.'filetypes', | 43 | 'T_filetypes' => $app_db_tableprefix.'filetypes', |
387 | 40 | 'T_groups' => $app_db_tableprefix.'groups', | 44 | 'T_groups' => $app_db_tableprefix.'groups', |
388 | 41 | 'T_global__cache' => $app_db_tableprefix.'global__cache', | 45 | 'T_global__cache' => $app_db_tableprefix.'global__cache', |
392 | 42 | 'T_items__prerendering' => $app_db_tableprefix.'items__prerendering', | 46 | 'T_item_prerendering' => $app_db_tableprefix.'items__prerendering', // new |
393 | 43 | 'T_items__status' => $app_db_tableprefix.'items__status', | 47 | 'T_items__prerendering' => $app_db_tableprefix.'items__prerendering', // old, going away |
394 | 44 | 'T_items__version' => $app_db_tableprefix.'items__version', | 48 | 'T_item_status' => $app_db_tableprefix.'items__status', // new |
395 | 49 | 'T_items__status' => $app_db_tableprefix.'items__status', // old, going away | ||
396 | 50 | 'T_item_versions' => $app_db_tableprefix.'items__version', // new | ||
397 | 51 | 'T_items__version' => $app_db_tableprefix.'items__version', // old, going away | ||
398 | 45 | 'T_links' => $app_db_tableprefix.'links', | 52 | 'T_links' => $app_db_tableprefix.'links', |
399 | 46 | 'T_locales' => $app_db_tableprefix.'locales', | 53 | 'T_locales' => $app_db_tableprefix.'locales', |
400 | 47 | 'T_plugins' => $app_db_tableprefix.'plugins', | 54 | 'T_plugins' => $app_db_tableprefix.'plugins', |
404 | 48 | 'T_pluginevents' => $app_db_tableprefix.'pluginevents', | 55 | 'T_plugin_events' => $app_db_tableprefix.'pluginevents', // new |
405 | 49 | 'T_pluginsettings' => $app_db_tableprefix.'pluginsettings', | 56 | 'T_pluginevents' => $app_db_tableprefix.'pluginevents', // old, going away |
406 | 50 | 'T_pluginusersettings' => $app_db_tableprefix.'pluginusersettings', | 57 | 'T_plugin_settings' => $app_db_tableprefix.'pluginsettings', // new |
407 | 58 | 'T_pluginsettings' => $app_db_tableprefix.'pluginsettings', // old, going away | ||
408 | 59 | 'T_plugin_usersettings' => $app_db_tableprefix.'pluginusersettings', // new | ||
409 | 60 | 'T_pluginusersettings' => $app_db_tableprefix.'pluginusersettings', // old, going away | ||
410 | 51 | 'T_settings' => $app_db_tableprefix.'settings', | 61 | 'T_settings' => $app_db_tableprefix.'settings', |
413 | 52 | 'T_templates__container' => $app_db_tableprefix.'templates__container', | 62 | 'T_template_containers' => $app_db_tableprefix.'templates__container', // new |
414 | 53 | 'T_templates__template' => $app_db_tableprefix.'templates__template', | 63 | 'T_templates__container' => $app_db_tableprefix.'templates__container', // old, going away |
415 | 64 | 'T_templates' => $app_db_tableprefix.'templates__template', // new | ||
416 | 65 | 'T_templates__template' => $app_db_tableprefix.'templates__template', // old, going away | ||
417 | 54 | 'T_subscriptions' => $app_db_tableprefix.'subscriptions', | 66 | 'T_subscriptions' => $app_db_tableprefix.'subscriptions', |
418 | 55 | 'T_users' => $app_db_tableprefix.'users', | 67 | 'T_users' => $app_db_tableprefix.'users', |
419 | 56 | 'T_plugin_sharedfields' => $app_db_tableprefix.'plugin_sharedfields', | 68 | 'T_plugin_sharedfields' => $app_db_tableprefix.'plugin_sharedfields', |
420 | 57 | 'T_plugin_sharedvalues' => $app_db_tableprefix.'plugin_sharedvalues', | 69 | 'T_plugin_sharedvalues' => $app_db_tableprefix.'plugin_sharedvalues', |
423 | 58 | 'T_usersettings' => $app_db_tableprefix.'usersettings', | 70 | 'T_user_settings' => $app_db_tableprefix.'usersettings', // new |
424 | 59 | 'T_widget' => $app_db_tableprefix.'widget', | 71 | 'T_usersettings' => $app_db_tableprefix.'usersettings', // old, going away |
425 | 72 | 'T_widgets' => $app_db_tableprefix.'widget', // new | ||
426 | 73 | 'T_widget' => $app_db_tableprefix.'widget', // old, going away | ||
427 | 60 | // old ones that leave after monster branch is done | 74 | // old ones that leave after monster branch is done |
428 | 61 | 'T_blog_settings' => $app_db_tableprefix.'coll_settings', | 75 | 'T_blog_settings' => $app_db_tableprefix.'coll_settings', |
429 | 62 | 'T_coll_settings' => $app_db_tableprefix.'coll_settings', // old | 76 | 'T_coll_settings' => $app_db_tableprefix.'coll_settings', // old |
430 | @@ -100,10 +114,11 @@ | |||
431 | 100 | 'users' => 'users/users.ctrl.php', | 114 | 'users' => 'users/users.ctrl.php', |
432 | 101 | 'upload' => 'files/upload.ctrl.php', | 115 | 'upload' => 'files/upload.ctrl.php', |
433 | 102 | 'widgets' => 'widgets/widgets.ctrl.php', | 116 | 'widgets' => 'widgets/widgets.ctrl.php', |
435 | 103 | ); | 117 | ); |
436 | 104 | 118 | ||
437 | 105 | /** | 119 | /** |
438 | 106 | * _core_Module class | 120 | * _core_Module class |
439 | 121 | * | ||
440 | 107 | * @package core | 122 | * @package core |
441 | 108 | */ | 123 | */ |
442 | 109 | class _core_Module | 124 | class _core_Module |
443 | @@ -229,10 +244,6 @@ | |||
444 | 229 | 'text' => T_('Intros').'…', | 244 | 'text' => T_('Intros').'…', |
445 | 230 | 'href' => $items_url.'tab=intros', | 245 | 'href' => $items_url.'tab=intros', |
446 | 231 | ), | 246 | ), |
447 | 232 | 'item_podcasts' => array( | ||
448 | 233 | 'text' => T_('Podcasts').'…', | ||
449 | 234 | 'href' => $items_url.'tab=podcasts', | ||
450 | 235 | ), | ||
451 | 236 | 'item_links' => array( | 247 | 'item_links' => array( |
452 | 237 | 'text' => T_('Sidebar links').'…', | 248 | 'text' => T_('Sidebar links').'…', |
453 | 238 | 'href' => $items_url.'tab=links', | 249 | 'href' => $items_url.'tab=links', |
454 | 239 | 250 | ||
455 | === modified file 'qp_inc/_core/_class.funcs.php' | |||
456 | --- qp_inc/_core/_class.funcs.php 2013-03-12 21:17:25 +0000 | |||
457 | +++ qp_inc/_core/_class.funcs.php 2013-03-20 18:13:29 +0000 | |||
458 | @@ -138,14 +138,4 @@ | |||
459 | 138 | } | 138 | } |
460 | 139 | } | 139 | } |
461 | 140 | 140 | ||
462 | 141 | /** | ||
463 | 142 | * Load class file. No-op for PHP5, uses __autoload(). | ||
464 | 143 | * | ||
465 | 144 | * @deprecated - after "monster" all the load_class() calls will be removed | ||
466 | 145 | */ | ||
467 | 146 | function load_class( $class_path ) | ||
468 | 147 | { | ||
469 | 148 | return true; | ||
470 | 149 | } | ||
471 | 150 | |||
472 | 151 | ?> | 141 | ?> |
473 | 152 | 142 | ||
474 | === modified file 'qp_inc/_core/_misc.funcs.php' | |||
475 | --- qp_inc/_core/_misc.funcs.php 2013-03-12 21:17:25 +0000 | |||
476 | +++ qp_inc/_core/_misc.funcs.php 2013-03-20 18:13:29 +0000 | |||
477 | @@ -83,7 +83,7 @@ | |||
478 | 83 | return $FiletypeCache; | 83 | return $FiletypeCache; |
479 | 84 | 84 | ||
480 | 85 | case 'GoalCache'; | 85 | case 'GoalCache'; |
482 | 86 | $GoalCache = new DataObjectCache( 'Goal', false, 'T_track__goal', 'goal_', 'goal_ID', 'goal_name', 'goal_name' ); // COPY (FUNC) | 86 | $GoalCache = new DataObjectCache( 'Goal', false, 'T_goals', 'goal_', 'goal_ID', 'goal_name', 'goal_name' ); // COPY (FUNC) |
483 | 87 | return $GoalCache; | 87 | return $GoalCache; |
484 | 88 | 88 | ||
485 | 89 | case 'GroupCache': | 89 | case 'GroupCache': |
486 | @@ -111,7 +111,7 @@ | |||
487 | 111 | return $ItemCatsCache; | 111 | return $ItemCatsCache; |
488 | 112 | 112 | ||
489 | 113 | case 'ItemStatusCache': | 113 | case 'ItemStatusCache': |
491 | 114 | $Plugins->get_object_from_cacheplugin_or_create( 'ItemStatusCache', 'new GenericCache( \'GenericElement\', true, \'T_items__status\', \'pst_\', \'pst_ID\', NULL, \'\', T_(\'No status\') )' ); | 114 | $Plugins->get_object_from_cacheplugin_or_create( 'ItemStatusCache', 'new GenericCache( \'GenericElement\', true, \'T_item_status\', \'pst_\', \'pst_ID\', NULL, \'\', T_(\'No status\') )' ); |
492 | 115 | return $ItemStatusCache; | 115 | return $ItemStatusCache; |
493 | 116 | 116 | ||
494 | 117 | case 'ItemTypeCache': | 117 | case 'ItemTypeCache': |
495 | @@ -1134,7 +1134,7 @@ | |||
496 | 1134 | * @param string Format to use ('simple', 'rfc') | 1134 | * @param string Format to use ('simple', 'rfc') |
497 | 1135 | * - 'simple': Single email address. | 1135 | * - 'simple': Single email address. |
498 | 1136 | * - 'rfc': Full email address, may include name (RFC2822) like example@example.org | 1136 | * - 'rfc': Full email address, may include name (RFC2822) like example@example.org |
500 | 1137 | * or Me <example@example.org> or "Me" <example@example.org> | 1137 | * or Me <example@example.org> or "Me" <example@example.org> |
501 | 1138 | * | 1138 | * |
502 | 1139 | * @see Plugin::IsValidRawEmail() | 1139 | * @see Plugin::IsValidRawEmail() |
503 | 1140 | * @see Plugin::IsValidFilteredEmail() | 1140 | * @see Plugin::IsValidFilteredEmail() |
504 | @@ -3170,6 +3170,8 @@ | |||
505 | 3170 | global $app_shortname; | 3170 | global $app_shortname; |
506 | 3171 | global $app_version; | 3171 | global $app_version; |
507 | 3172 | 3172 | ||
508 | 3173 | return ''; | ||
509 | 3174 | |||
510 | 3173 | if( $Settings->get( 'webhelp_enabled' ) ) | 3175 | if( $Settings->get( 'webhelp_enabled' ) ) |
511 | 3174 | { | 3176 | { |
512 | 3175 | $manual_url = 'http://codex.quamplures.net/onlinehelp.php/'.$topic.'?lang='.$current_locale.'&app='.$app_shortname.'&version='.$app_version; | 3177 | $manual_url = 'http://codex.quamplures.net/onlinehelp.php/'.$topic.'?lang='.$current_locale.'&app='.$app_shortname.'&version='.$app_version; |
513 | 3176 | 3178 | ||
514 | === modified file 'qp_inc/_core/_param.funcs.php' | |||
515 | --- qp_inc/_core/_param.funcs.php 2013-03-12 21:17:25 +0000 | |||
516 | +++ qp_inc/_core/_param.funcs.php 2013-03-20 18:13:29 +0000 | |||
517 | @@ -38,9 +38,10 @@ | |||
518 | 38 | * - '' (does nothing) | 38 | * - '' (does nothing) |
519 | 39 | * - '/^...$/' check regexp pattern match (string) | 39 | * - '/^...$/' check regexp pattern match (string) |
520 | 40 | * - boolean (will force type to boolean, but you can't use 'true' as a default | 40 | * - boolean (will force type to boolean, but you can't use 'true' as a default |
524 | 41 | * since it has special meaning. There is no real reason to pass booleans on a | 41 | * since it has special meaning. There is no real reason to pass booleans on a |
525 | 42 | * URL though. Passing 0 and 1 as integers seems to be best practice). | 42 | * URL though. Passing 0 and 1 as integers seems to be best practice). |
526 | 43 | * Value type will be forced only if resulting value (probably from default then) is !== NULL | 43 | * Value type will be forced only if resulting value (probably from default then) |
527 | 44 | * is !== NULL | ||
528 | 44 | * @param mixed Default value or TRUE if user input required | 45 | * @param mixed Default value or TRUE if user input required |
529 | 45 | * @param boolean Do we need to memorize this to regenerate the URL for this page? | 46 | * @param boolean Do we need to memorize this to regenerate the URL for this page? |
530 | 46 | * @param boolean Override if variable already set | 47 | * @param boolean Override if variable already set |
531 | @@ -1622,7 +1623,7 @@ | |||
532 | 1622 | /** | 1623 | /** |
533 | 1623 | * Checks for sanitized code | 1624 | * Checks for sanitized code |
534 | 1624 | * | 1625 | * |
536 | 1625 | * WARNING: this does *NOT* (necessarilly) make the HTML code safe. It only checks | 1626 | * WARNING: this does *NOT* (necessarily) make the HTML code safe. It only checks |
537 | 1626 | * on it and produces error messages. It is NOT (necessarily) safe to use the output. | 1627 | * on it and produces error messages. It is NOT (necessarily) safe to use the output. |
538 | 1627 | * | 1628 | * |
539 | 1628 | * @param string param name | 1629 | * @param string param name |
540 | @@ -1743,8 +1744,9 @@ | |||
541 | 1743 | $allow_javascript = false; | 1744 | $allow_javascript = false; |
542 | 1744 | $allow_iframes = false; | 1745 | $allow_iframes = false; |
543 | 1745 | $allow_objects = false; | 1746 | $allow_objects = false; |
546 | 1746 | // fp> I don't know if it makes sense to bypass antispam in commenting context if the user | 1747 | // fp> I don't know if it makes sense to bypass antispam in commenting context |
547 | 1747 | // has that kind of permissions. If so, then we also need to bypass in several other places. | 1748 | // if the user has that kind of permissions. If so, then we also need to bypass |
548 | 1749 | // in several other places. | ||
549 | 1748 | $bypass_antispam = false; | 1750 | $bypass_antispam = false; |
550 | 1749 | break; | 1751 | break; |
551 | 1750 | 1752 | ||
552 | @@ -1825,7 +1827,9 @@ | |||
553 | 1825 | { | 1827 | { |
554 | 1826 | // We want to validate XHTML | 1828 | // We want to validate XHTML |
555 | 1827 | 1829 | ||
557 | 1828 | // figure out what we want to validate against | 1830 | // figure out what we want to validate against. $skip lets us bypass checks |
558 | 1831 | // when they don't matter, $flavor lets us validate against xhtml or html5 | ||
559 | 1832 | // (eventually!), and $source gives us info about where we are checking from | ||
560 | 1829 | $skip = false; | 1833 | $skip = false; |
561 | 1830 | $flavor = 'xhtml'; | 1834 | $flavor = 'xhtml'; |
562 | 1831 | $source = array_merge( array( | 1835 | $source = array_merge( array( |
563 | @@ -1839,7 +1843,16 @@ | |||
564 | 1839 | $skip = true; | 1843 | $skip = true; |
565 | 1840 | } | 1844 | } |
566 | 1841 | 1845 | ||
568 | 1842 | // if we come from param_check_html() we're almost done | 1846 | // we can skip if we're just changing locales on a user. $flavor will be xhtml |
569 | 1847 | // because we're in admin and admin doesn't do or need html5 stuff | ||
570 | 1848 | if( array_key_exists( 'userupdate', $_POST['actionArray'] ) | ||
571 | 1849 | && array_key_exists( 'ctrl', $_POST ) ) | ||
572 | 1850 | { | ||
573 | 1851 | $flavor = 'xhtml'; | ||
574 | 1852 | $skip = true; | ||
575 | 1853 | } | ||
576 | 1854 | |||
577 | 1855 | // if we come from param_check_html() (but not on a user update) we're almost done | ||
578 | 1843 | if( ! $skip && $source['param_check_html'] ) | 1856 | if( ! $skip && $source['param_check_html'] ) |
579 | 1844 | { | 1857 | { |
580 | 1845 | global $Blog; | 1858 | global $Blog; |
581 | 1846 | 1859 | ||
582 | === modified file 'qp_inc/_core/model/__core.install.php' | |||
583 | --- qp_inc/_core/model/__core.install.php 2013-03-13 02:35:35 +0000 | |||
584 | +++ qp_inc/_core/model/__core.install.php 2013-03-20 18:13:29 +0000 | |||
585 | @@ -2,8 +2,9 @@ | |||
586 | 2 | /** | 2 | /** |
587 | 3 | * This is the install file for the core modules | 3 | * This is the install file for the core modules |
588 | 4 | * | 4 | * |
591 | 5 | * This gets updated through {@link db_delta()} which generates the queries needed | 5 | * $schema_queries gets updated through {@link db_delta()} which generates the |
592 | 6 | * to get to this scheme. Please see {@link db_delta()} for things to take care of. | 6 | * queries needed to get to this scheme. Please see {@link db_delta()} for things |
593 | 7 | * to take care of. | ||
594 | 7 | * | 8 | * |
595 | 8 | * @author {@link http://wonderwinds.com/ Ed Bennett} | 9 | * @author {@link http://wonderwinds.com/ Ed Bennett} |
596 | 9 | * @author {@link http://fplanque.net/ Francois PLANQUE} | 10 | * @author {@link http://fplanque.net/ Francois PLANQUE} |
597 | @@ -15,9 +16,8 @@ | |||
598 | 15 | 16 | ||
599 | 16 | global $db_storage_charset; | 17 | global $db_storage_charset; |
600 | 17 | 18 | ||
601 | 18 | // This gets updated through db_delta() which generates the queries needed to get to this scheme | ||
602 | 19 | $schema_queries = array( | 19 | $schema_queries = array( |
604 | 20 | 'T_antispam' => array( 'Creating table for Antispam Blacklist', | 20 | 'T_antispam' => array( 'Creating table for antispam', |
605 | 21 | "CREATE TABLE T_antispam ( | 21 | "CREATE TABLE T_antispam ( |
606 | 22 | aspm_ID bigint(11) NOT NULL auto_increment, | 22 | aspm_ID bigint(11) NOT NULL auto_increment, |
607 | 23 | aspm_string VARCHAR(80) NOT NULL, | 23 | aspm_string VARCHAR(80) NOT NULL, |
608 | @@ -65,8 +65,8 @@ | |||
609 | 65 | UNIQUE KEY blog_urlname (blog_urlname) | 65 | UNIQUE KEY blog_urlname (blog_urlname) |
610 | 66 | ) ENGINE = innodb DEFAULT CHARSET = $db_storage_charset" ), | 66 | ) ENGINE = innodb DEFAULT CHARSET = $db_storage_charset" ), |
611 | 67 | 67 | ||
614 | 68 | 'T_coll_group_perms' => array( 'Creating blog-group permissions table', | 68 | 'T_blog_groups' => array( 'Creating blog-group permissions table', |
615 | 69 | "CREATE TABLE T_coll_group_perms ( | 69 | "CREATE TABLE T_blog_groups ( |
616 | 70 | bloggroup_blog_ID INT(11) unsigned NOT NULL default 0, | 70 | bloggroup_blog_ID INT(11) unsigned NOT NULL default 0, |
617 | 71 | bloggroup_group_ID INT(11) unsigned NOT NULL default 0, | 71 | bloggroup_group_ID INT(11) unsigned NOT NULL default 0, |
618 | 72 | bloggroup_ismember TINYINT NOT NULL default 0, | 72 | bloggroup_ismember TINYINT NOT NULL default 0, |
619 | @@ -91,8 +91,8 @@ | |||
620 | 91 | PRIMARY KEY ( cset_blog_ID, cset_name ) | 91 | PRIMARY KEY ( cset_blog_ID, cset_name ) |
621 | 92 | ) ENGINE = innodb DEFAULT CHARSET = $db_storage_charset" ), | 92 | ) ENGINE = innodb DEFAULT CHARSET = $db_storage_charset" ), |
622 | 93 | 93 | ||
625 | 94 | 'T_coll_user_perms' => array( 'Creating blog-user permissions table', | 94 | 'T_blog_users' => array( 'Creating blog-user permissions table', |
626 | 95 | "CREATE TABLE T_coll_user_perms ( | 95 | "CREATE TABLE T_blog_users ( |
627 | 96 | bloguser_blog_ID INT(11) unsigned NOT NULL default 0, | 96 | bloguser_blog_ID INT(11) unsigned NOT NULL default 0, |
628 | 97 | bloguser_user_ID INT(11) unsigned NOT NULL default 0, | 97 | bloguser_user_ID INT(11) unsigned NOT NULL default 0, |
629 | 98 | bloguser_ismember TINYINT NOT NULL default 0, | 98 | bloguser_ismember TINYINT NOT NULL default 0, |
630 | @@ -150,8 +150,8 @@ | |||
631 | 150 | KEY comment_type (comment_type) | 150 | KEY comment_type (comment_type) |
632 | 151 | ) ENGINE = innodb DEFAULT CHARSET = $db_storage_charset" ), | 151 | ) ENGINE = innodb DEFAULT CHARSET = $db_storage_charset" ), |
633 | 152 | 152 | ||
636 | 153 | 'T_cron__log' => array( 'Creating cron log table', | 153 | 'T_cron_log' => array( 'Creating cron log table', |
637 | 154 | "CREATE TABLE T_cron__log( | 154 | "CREATE TABLE T_cron_log( |
638 | 155 | clog_ctsk_ID INT(10) unsigned not null, | 155 | clog_ctsk_ID INT(10) unsigned not null, |
639 | 156 | clog_realstart_datetime DATETIME not null DEFAULT '2000-01-01 00:00:00', | 156 | clog_realstart_datetime DATETIME not null DEFAULT '2000-01-01 00:00:00', |
640 | 157 | clog_realstop_datetime DATETIME, | 157 | clog_realstop_datetime DATETIME, |
641 | @@ -160,8 +160,8 @@ | |||
642 | 160 | PRIMARY KEY ( clog_ctsk_ID ) | 160 | PRIMARY KEY ( clog_ctsk_ID ) |
643 | 161 | ) ENGINE = innodb DEFAULT CHARSET = $db_storage_charset" ), | 161 | ) ENGINE = innodb DEFAULT CHARSET = $db_storage_charset" ), |
644 | 162 | 162 | ||
647 | 163 | 'T_cron__task' => array( 'Creating cron tasks table', | 163 | 'T_cron_task' => array( 'Creating cron tasks table', |
648 | 164 | "CREATE TABLE T_cron__task( | 164 | "CREATE TABLE T_cron_task( |
649 | 165 | ctsk_ID INT(10) unsigned not null AUTO_INCREMENT, | 165 | ctsk_ID INT(10) unsigned not null AUTO_INCREMENT, |
650 | 166 | ctsk_start_datetime DATETIME not null DEFAULT '2000-01-01 00:00:00', | 166 | ctsk_start_datetime DATETIME not null DEFAULT '2000-01-01 00:00:00', |
651 | 167 | ctsk_repeat_after INT(10) unsigned, | 167 | ctsk_repeat_after INT(10) unsigned, |
652 | @@ -275,8 +275,8 @@ | |||
653 | 275 | UNIQUE catpost ( postcat_cat_ID, postcat_post_ID ) | 275 | UNIQUE catpost ( postcat_cat_ID, postcat_post_ID ) |
654 | 276 | ) ENGINE = innodb DEFAULT CHARSET = $db_storage_charset" ), | 276 | ) ENGINE = innodb DEFAULT CHARSET = $db_storage_charset" ), |
655 | 277 | 277 | ||
658 | 278 | 'T_items__prerendering' => array( 'Creating item prerendering table', | 278 | 'T_item_prerendering' => array( 'Creating item prerendering table', |
659 | 279 | "CREATE TABLE T_items__prerendering( | 279 | "CREATE TABLE T_item_prerendering( |
660 | 280 | itpr_itm_ID INT(11) UNSIGNED NOT NULL, | 280 | itpr_itm_ID INT(11) UNSIGNED NOT NULL, |
661 | 281 | itpr_format ENUM('htmlbody','entityencoded','xml','text') NOT NULL, | 281 | itpr_format ENUM('htmlbody','entityencoded','xml','text') NOT NULL, |
662 | 282 | itpr_renderers TEXT NOT NULL, | 282 | itpr_renderers TEXT NOT NULL, |
663 | @@ -285,8 +285,8 @@ | |||
664 | 285 | PRIMARY KEY ( itpr_itm_ID, itpr_format ) | 285 | PRIMARY KEY ( itpr_itm_ID, itpr_format ) |
665 | 286 | ) ENGINE = innodb DEFAULT CHARSET = $db_storage_charset" ), | 286 | ) ENGINE = innodb DEFAULT CHARSET = $db_storage_charset" ), |
666 | 287 | 287 | ||
669 | 288 | 'T_items__status' => array( 'Creating item statuses table', | 288 | 'T_item_status' => array( 'Creating item statuses table', |
670 | 289 | "CREATE TABLE T_items__status ( | 289 | "CREATE TABLE T_item_status ( |
671 | 290 | pst_ID INT(11) unsigned not null AUTO_INCREMENT, | 290 | pst_ID INT(11) unsigned not null AUTO_INCREMENT, |
672 | 291 | pst_name VARCHAR(30) not null, | 291 | pst_name VARCHAR(30) not null, |
673 | 292 | PRIMARY KEY ( pst_ID ) | 292 | PRIMARY KEY ( pst_ID ) |
674 | @@ -307,8 +307,8 @@ | |||
675 | 307 | PRIMARY KEY ( ptyp_ID ) | 307 | PRIMARY KEY ( ptyp_ID ) |
676 | 308 | ) ENGINE = innodb DEFAULT CHARSET = $db_storage_charset" ), | 308 | ) ENGINE = innodb DEFAULT CHARSET = $db_storage_charset" ), |
677 | 309 | 309 | ||
680 | 310 | 'T_items__version' => array( 'Creating item versions table', | 310 | 'T_item_versions' => array( 'Creating item versions table', |
681 | 311 | "CREATE TABLE T_items__version ( | 311 | "CREATE TABLE T_item_versions ( |
682 | 312 | iver_itm_ID INT UNSIGNED NOT NULL, | 312 | iver_itm_ID INT UNSIGNED NOT NULL, |
683 | 313 | iver_edit_user_ID INT UNSIGNED NULL, | 313 | iver_edit_user_ID INT UNSIGNED NULL, |
684 | 314 | iver_edit_datetime DATETIME NOT NULL, | 314 | iver_edit_datetime DATETIME NOT NULL, |
685 | @@ -369,24 +369,24 @@ | |||
686 | 369 | INDEX plug_status( plug_status ) | 369 | INDEX plug_status( plug_status ) |
687 | 370 | ) ENGINE = innodb DEFAULT CHARSET = $db_storage_charset" ), | 370 | ) ENGINE = innodb DEFAULT CHARSET = $db_storage_charset" ), |
688 | 371 | 371 | ||
691 | 372 | 'T_pluginevents' => array( 'Creating plugin events table', | 372 | 'T_plugin_events' => array( 'Creating plugin events table', |
692 | 373 | "CREATE TABLE T_pluginevents( | 373 | "CREATE TABLE T_plugin_events( |
693 | 374 | pevt_plug_ID INT(11) UNSIGNED NOT NULL, | 374 | pevt_plug_ID INT(11) UNSIGNED NOT NULL, |
694 | 375 | pevt_event VARCHAR(40) NOT NULL, | 375 | pevt_event VARCHAR(40) NOT NULL, |
695 | 376 | pevt_enabled TINYINT NOT NULL DEFAULT 1, | 376 | pevt_enabled TINYINT NOT NULL DEFAULT 1, |
696 | 377 | PRIMARY KEY ( pevt_plug_ID, pevt_event ) | 377 | PRIMARY KEY ( pevt_plug_ID, pevt_event ) |
697 | 378 | ) ENGINE = innodb DEFAULT CHARSET = $db_storage_charset" ), | 378 | ) ENGINE = innodb DEFAULT CHARSET = $db_storage_charset" ), |
698 | 379 | 379 | ||
701 | 380 | 'T_pluginsettings' => array( 'Creating plugin settings table', | 380 | 'T_plugin_settings' => array( 'Creating plugin settings table', |
702 | 381 | "CREATE TABLE T_pluginsettings ( | 381 | "CREATE TABLE T_plugin_settings ( |
703 | 382 | pset_plug_ID INT(11) UNSIGNED NOT NULL, | 382 | pset_plug_ID INT(11) UNSIGNED NOT NULL, |
704 | 383 | pset_name VARCHAR(30) NOT NULL, | 383 | pset_name VARCHAR(30) NOT NULL, |
705 | 384 | pset_value TEXT NULL, | 384 | pset_value TEXT NULL, |
706 | 385 | PRIMARY KEY ( pset_plug_ID, pset_name ) | 385 | PRIMARY KEY ( pset_plug_ID, pset_name ) |
707 | 386 | ) ENGINE = innodb DEFAULT CHARSET = $db_storage_charset" ), | 386 | ) ENGINE = innodb DEFAULT CHARSET = $db_storage_charset" ), |
708 | 387 | 387 | ||
711 | 388 | 'T_pluginusersettings' => array( 'Creating plugin user settings table', | 388 | 'T_plugin_usersettings' => array( 'Creating plugin user settings table', |
712 | 389 | "CREATE TABLE T_pluginusersettings ( | 389 | "CREATE TABLE T_plugin_usersettings ( |
713 | 390 | puset_plug_ID INT(11) UNSIGNED NOT NULL, | 390 | puset_plug_ID INT(11) UNSIGNED NOT NULL, |
714 | 391 | puset_user_ID INT(11) UNSIGNED NOT NULL, | 391 | puset_user_ID INT(11) UNSIGNED NOT NULL, |
715 | 392 | puset_name VARCHAR(30) NOT NULL, | 392 | puset_name VARCHAR(30) NOT NULL, |
716 | @@ -418,8 +418,8 @@ | |||
717 | 418 | UNIQUE tag_name( tag_name ) | 418 | UNIQUE tag_name( tag_name ) |
718 | 419 | ) ENGINE = innodb DEFAULT CHARSET = $db_storage_charset" ), | 419 | ) ENGINE = innodb DEFAULT CHARSET = $db_storage_charset" ), |
719 | 420 | 420 | ||
722 | 421 | 'T_templates__template' => array( 'Creating templates table', | 421 | 'T_templates' => array( 'Creating templates table', |
723 | 422 | "CREATE TABLE T_templates__template ( | 422 | "CREATE TABLE T_templates ( |
724 | 423 | template_ID INT(10) unsigned NOT NULL auto_increment, | 423 | template_ID INT(10) unsigned NOT NULL auto_increment, |
725 | 424 | template_name VARCHAR(32) NOT NULL, | 424 | template_name VARCHAR(32) NOT NULL, |
726 | 425 | template_type ENUM('xhtml','html5','feed','other') NOT NULL default 'xhtml', | 425 | template_type ENUM('xhtml','html5','feed','other') NOT NULL default 'xhtml', |
727 | @@ -429,8 +429,8 @@ | |||
728 | 429 | KEY template_name( template_name ) | 429 | KEY template_name( template_name ) |
729 | 430 | ) ENGINE = innodb DEFAULT CHARSET = $db_storage_charset" ), | 430 | ) ENGINE = innodb DEFAULT CHARSET = $db_storage_charset" ), |
730 | 431 | 431 | ||
733 | 432 | 'T_templates__container' => array( 'Creating template containers table', | 432 | 'T_template_containers' => array( 'Creating template containers table', |
734 | 433 | "CREATE TABLE T_templates__container ( | 433 | "CREATE TABLE T_template_containers ( |
735 | 434 | sco_template_ID INT(10) unsigned NOT NULL, | 434 | sco_template_ID INT(10) unsigned NOT NULL, |
736 | 435 | sco_name VARCHAR(40) NOT NULL, | 435 | sco_name VARCHAR(40) NOT NULL, |
737 | 436 | sco_order TINYINT NOT NULL default 0, | 436 | sco_order TINYINT NOT NULL default 0, |
738 | @@ -473,16 +473,16 @@ | |||
739 | 473 | PRIMARY KEY ( cach_name ) | 473 | PRIMARY KEY ( cach_name ) |
740 | 474 | ) ENGINE = innodb DEFAULT CHARSET = $db_storage_charset" ), | 474 | ) ENGINE = innodb DEFAULT CHARSET = $db_storage_charset" ), |
741 | 475 | 475 | ||
744 | 476 | 'T_usersettings' => array( 'Creating user settings table', | 476 | 'T_user_settings' => array( 'Creating user settings table', |
745 | 477 | "CREATE TABLE T_usersettings ( | 477 | "CREATE TABLE T_user_settings ( |
746 | 478 | uset_user_ID INT(11) UNSIGNED NOT NULL, | 478 | uset_user_ID INT(11) UNSIGNED NOT NULL, |
747 | 479 | uset_name VARCHAR(30) NOT NULL, | 479 | uset_name VARCHAR(30) NOT NULL, |
748 | 480 | uset_value VARCHAR(255) NULL, | 480 | uset_value VARCHAR(255) NULL, |
749 | 481 | PRIMARY KEY ( uset_user_ID, uset_name ) | 481 | PRIMARY KEY ( uset_user_ID, uset_name ) |
750 | 482 | ) ENGINE = innodb DEFAULT CHARSET = $db_storage_charset" ), | 482 | ) ENGINE = innodb DEFAULT CHARSET = $db_storage_charset" ), |
751 | 483 | 483 | ||
754 | 484 | 'T_widget' => array( 'Creating widgets table', | 484 | 'T_widgets' => array( 'Creating widgets table', |
755 | 485 | "CREATE TABLE T_widget ( | 485 | "CREATE TABLE T_widgets ( |
756 | 486 | wi_ID INT(10) UNSIGNED auto_increment, | 486 | wi_ID INT(10) UNSIGNED auto_increment, |
757 | 487 | wi_widget_blog_ID INT(11) UNSIGNED NOT NULL, | 487 | wi_widget_blog_ID INT(11) UNSIGNED NOT NULL, |
758 | 488 | wi_sco_name VARCHAR(40) NOT NULL, | 488 | wi_sco_name VARCHAR(40) NOT NULL, |
759 | 489 | 489 | ||
760 | === modified file 'qp_inc/_core/model/_pagecache.class.php' | |||
761 | --- qp_inc/_core/model/_pagecache.class.php 2010-12-31 12:12:03 +0000 | |||
762 | +++ qp_inc/_core/model/_pagecache.class.php 2013-03-20 18:13:29 +0000 | |||
763 | @@ -1,72 +1,62 @@ | |||
764 | 1 | <?php | 1 | <?php |
765 | 2 | /** | 2 | /** |
788 | 3 | * This file implements the PageCache class, which caches HTML pages genereated by the app. | 3 | * This file implements the PageCache class |
789 | 4 | * | 4 | * |
790 | 5 | * This file is part of Quam Plures - {@link http://quamplures.net/} | 5 | * This caches HTML pages genereated by the app. |
791 | 6 | * See also {@link https://launchpad.net/quam-plures}. | 6 | * |
792 | 7 | * | 7 | * @todo (1111) vars type 'foo' need useful/valid descriptions |
793 | 8 | * @copyright (c) 2009 - 2011 by the Quam Plures developers - {@link http://quamplures.net/} | 8 | * @author {@link http://wonderwinds.com/ Ed Bennett} |
794 | 9 | * @copyright (c)2003-2009 by Francois PLANQUE - {@link http://fplanque.net/} | 9 | * @author {@link http://daniel.hahler.de/ Daniel HAHLER} |
795 | 10 | * Parts of this file are copyright (c)2004-2006 by Daniel HAHLER - {@link http://thequod.de/contact}. | 10 | * @author {@link http://fplanque.net/ Francois PLANQUE} |
796 | 11 | * | 11 | * @copyright (c) 2009 by {@link http://quamplures.net/ the Quam Plures project} |
797 | 12 | * {@internal License choice | 12 | * @license http://www.gnu.org/licenses/gpl.txt GNU General Public License v3 |
798 | 13 | * - If you have received this file as part of a package, please find the license.txt file in | 13 | * @package core |
777 | 14 | * the same folder or the closest folder above for complete license terms. | ||
778 | 15 | * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/) | ||
779 | 16 | * then you must choose one of the following licenses before using the file: | ||
780 | 17 | * - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php | ||
781 | 18 | * - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php | ||
782 | 19 | * }} | ||
783 | 20 | * | ||
784 | 21 | * {@internal Open Source relicensing agreement: | ||
785 | 22 | * }} | ||
786 | 23 | * | ||
787 | 24 | * @package pond | ||
799 | 25 | */ | 14 | */ |
802 | 26 | if( !defined('QP_MAIN_INIT') ) die( 'Please, do not access this page directly.' ); | 15 | if(!defined('QP_MAIN_INIT')) die('fail'); |
801 | 27 | |||
803 | 28 | 16 | ||
804 | 29 | /** | 17 | /** |
806 | 30 | * Page Cache. | 18 | * PageCache class |
807 | 31 | * | 19 | * |
809 | 32 | * @package pond | 20 | * @package core |
810 | 33 | */ | 21 | */ |
811 | 34 | class PageCache | 22 | class PageCache |
812 | 35 | { | 23 | { |
814 | 36 | /** | 24 | /** |
815 | 37 | * How old can a cached object get before we consider it outdated | 25 | * How old can a cached object get before we consider it outdated |
816 | 26 | * @var foo | ||
817 | 38 | */ | 27 | */ |
822 | 39 | var $max_age_seconds = 300; // 5 minutes for now | 28 | var $max_age_seconds = 300; |
823 | 40 | 29 | /** | |
824 | 41 | /** | 30 | * After how many bytes should we output sth live while collecting cache content |
825 | 42 | * After how many bytes should we output sth live while collecting cache content: | 31 | * @var foo |
826 | 43 | */ | 32 | */ |
827 | 44 | var $output_chunk_size = 2000; | 33 | var $output_chunk_size = 2000; |
828 | 45 | |||
829 | 46 | /** | 34 | /** |
830 | 47 | * By default we consider caching not to be enabled | 35 | * By default we consider caching not to be enabled |
831 | 36 | * @var foo | ||
832 | 48 | */ | 37 | */ |
833 | 49 | var $is_enabled = false; | 38 | var $is_enabled = false; |
834 | 50 | |||
835 | 51 | /** | 39 | /** |
837 | 52 | * | 40 | * FIX THIS |
838 | 41 | * @var foo | ||
839 | 53 | */ | 42 | */ |
840 | 54 | var $ads_collcache_path; | 43 | var $ads_collcache_path; |
841 | 55 | |||
842 | 56 | /** | 44 | /** |
843 | 57 | * Filename of cache for current page | 45 | * Filename of cache for current page |
844 | 46 | * @var foo | ||
845 | 58 | */ | 47 | */ |
846 | 59 | var $cache_filepath; | 48 | var $cache_filepath; |
847 | 60 | /** | 49 | /** |
849 | 61 | * Progressively caching the content of the current page: | 50 | * Progressively caching the content of the current page |
850 | 51 | * @var foo | ||
851 | 62 | */ | 52 | */ |
852 | 63 | var $cached_page_content = ''; | 53 | var $cached_page_content = ''; |
853 | 64 | /** | 54 | /** |
854 | 65 | * Are we currently recording cache contents for this page? | 55 | * Are we currently recording cache contents for this page? |
855 | 56 | * @var foo | ||
856 | 66 | */ | 57 | */ |
857 | 67 | var $is_collecting = false; | 58 | var $is_collecting = false; |
858 | 68 | 59 | ||
859 | 69 | |||
860 | 70 | /** | 60 | /** |
861 | 71 | * Constructor | 61 | * Constructor |
862 | 72 | * | 62 | * |
863 | @@ -74,17 +64,18 @@ | |||
864 | 74 | */ | 64 | */ |
865 | 75 | function PageCache( $Blog = NULL ) | 65 | function PageCache( $Blog = NULL ) |
866 | 76 | { | 66 | { |
868 | 77 | global $Debuglog; | 67 | global $cache_path; |
869 | 78 | global $Settings; | 68 | global $Settings; |
870 | 79 | global $cache_path; | ||
871 | 80 | 69 | ||
874 | 81 | if( is_null($Blog) ) | 70 | if( is_null( $Blog ) ) |
875 | 82 | { // Cache for "other" "genereic" "special" pages: | 71 | { |
876 | 72 | // Cache for "other" "genereic" "special" pages | ||
877 | 83 | $this->ads_collcache_path = $cache_path.'general/'; | 73 | $this->ads_collcache_path = $cache_path.'general/'; |
878 | 84 | 74 | ||
882 | 85 | if( ! $Settings->get('general_cache_enabled') ) | 75 | if( ! $Settings->get( 'general_cache_enabled' ) ) |
883 | 86 | { // We do NOT want caching for this collection | 76 | { |
884 | 87 | $Debuglog->add( 'General cache not enabled.', 'cache' ); | 77 | // We do NOT want caching for this collection |
885 | 78 | // debuglog-add removed | ||
886 | 88 | } | 79 | } |
887 | 89 | else | 80 | else |
888 | 90 | { | 81 | { |
889 | @@ -92,13 +83,15 @@ | |||
890 | 92 | } | 83 | } |
891 | 93 | } | 84 | } |
892 | 94 | else | 85 | else |
895 | 95 | { // Cache for a specific Blog/Collection: | 86 | { |
896 | 96 | // We need to set this even if cache is not enabled (yet) bc it's used for creating: | 87 | // Cache for a specific Blog/Collection |
897 | 88 | // We need to set this even if cache is not enabled (yet) bc it's used for creating | ||
898 | 97 | $this->ads_collcache_path = $cache_path.'c'.$Blog->ID.'/'; | 89 | $this->ads_collcache_path = $cache_path.'c'.$Blog->ID.'/'; |
899 | 98 | 90 | ||
903 | 99 | if( ! $Blog->get_setting('cache_enabled') ) | 91 | if( ! $Blog->get_setting( 'cache_enabled' ) ) |
904 | 100 | { // We do NOT want caching for this collection | 92 | { |
905 | 101 | $Debuglog->add( 'Cache not enabled for this blog.', 'cache' ); | 93 | // We do NOT want caching for this collection |
906 | 94 | // debuglog-add removed | ||
907 | 102 | } | 95 | } |
908 | 103 | else | 96 | else |
909 | 104 | { | 97 | { |
910 | @@ -111,37 +104,35 @@ | |||
911 | 111 | /** | 104 | /** |
912 | 112 | * Get path to file for current URL | 105 | * Get path to file for current URL |
913 | 113 | * | 106 | * |
915 | 114 | * @todo fp> We may need to add some keys like the locale or the charset, I'm not sure. | 107 | * @todo (0000) fp> We may need to add some keys like the locale or the charset, I'm not sure. |
916 | 115 | */ | 108 | */ |
917 | 116 | function get_af_filecache_path() | 109 | function get_af_filecache_path() |
918 | 117 | { | 110 | { |
921 | 118 | global $Debuglog; | 111 | global $ReqURI; |
922 | 119 | global $ReqHost, $ReqURI; | 112 | global $ReqHost; |
923 | 120 | 113 | ||
924 | 121 | // We want the cache for the current URL | 114 | // We want the cache for the current URL |
925 | 122 | if( empty( $this->cache_filepath ) ) | 115 | if( empty( $this->cache_filepath ) ) |
926 | 123 | { | 116 | { |
927 | 124 | $ReqAbsUrl = $ReqHost.$ReqURI; | 117 | $ReqAbsUrl = $ReqHost.$ReqURI; |
933 | 125 | $Debuglog->add( 'URL being cached: '.$ReqAbsUrl, 'cache' ); | 118 | |
934 | 126 | 119 | $this->cache_filepath = $this->gen_filecache_path( $ReqAbsUrl ); | |
930 | 127 | $this->cache_filepath = $this->gen_filecache_path( $ReqAbsUrl ); | ||
931 | 128 | |||
932 | 129 | $Debuglog->add( 'Cache file: '.$this->cache_filepath, 'cache' ); | ||
935 | 130 | } | 120 | } |
936 | 131 | 121 | ||
938 | 132 | return $this->cache_filepath; | 122 | return $this->cache_filepath; |
939 | 133 | } | 123 | } |
940 | 134 | 124 | ||
941 | 135 | 125 | ||
942 | 136 | /** | 126 | /** |
944 | 137 | * Generate path for caching $url. | 127 | * Generate path for caching $url |
945 | 128 | * | ||
946 | 138 | * @param string URL | 129 | * @param string URL |
947 | 139 | * @return string | 130 | * @return string |
948 | 140 | */ | 131 | */ |
949 | 141 | function gen_filecache_path( $url ) | 132 | function gen_filecache_path( $url ) |
950 | 142 | { | 133 | { |
953 | 143 | $url_hash = md5($url); // fp> is this teh fastest way to hash this into something not too obvious to guess? | 134 | // fp> is this the fastest way to hash this into something not too obvious to guess? |
954 | 144 | 135 | $url_hash = md5( $url ); | |
955 | 145 | return $this->ads_collcache_path.$url_hash.'.page'; | 136 | return $this->ads_collcache_path.$url_hash.'.page'; |
956 | 146 | } | 137 | } |
957 | 147 | 138 | ||
958 | @@ -153,29 +144,27 @@ | |||
959 | 153 | */ | 144 | */ |
960 | 154 | function invalidate( $url ) | 145 | function invalidate( $url ) |
961 | 155 | { | 146 | { |
962 | 156 | global $Debuglog; | ||
963 | 157 | |||
964 | 158 | $Debuglog->add( 'Invalidating:'.$url, 'cache' ); | ||
965 | 159 | |||
966 | 160 | // What would be the cache file for the current URL? | 147 | // What would be the cache file for the current URL? |
967 | 161 | $af_cache_file = $this->gen_filecache_path( $url ); | 148 | $af_cache_file = $this->gen_filecache_path( $url ); |
968 | 162 | |||
969 | 163 | @unlink( $af_cache_file ); | 149 | @unlink( $af_cache_file ); |
970 | 164 | } | 150 | } |
971 | 165 | 151 | ||
972 | 166 | 152 | ||
973 | 167 | /** | 153 | /** |
974 | 154 | * create cache | ||
975 | 155 | * | ||
976 | 168 | * @return boolean true if cache has been successfully created | 156 | * @return boolean true if cache has been successfully created |
977 | 169 | */ | 157 | */ |
978 | 170 | function cache_create() | 158 | function cache_create() |
979 | 171 | { | 159 | { |
981 | 172 | // Create by using the filemanager's default chmod. TODO> we may not want to make these publicly readable | 160 | // Create by using the filemanager's default chmod. |
982 | 161 | // @todo (0000) we may not want to make these publicly readable | ||
983 | 173 | if( ! mkdir_r( $this->ads_collcache_path, NULL ) ) | 162 | if( ! mkdir_r( $this->ads_collcache_path, NULL ) ) |
984 | 174 | { | 163 | { |
985 | 175 | return false; | 164 | return false; |
986 | 176 | } | 165 | } |
987 | 177 | 166 | ||
989 | 178 | // Clear contents of folder, if any: | 167 | // Clear contents of folder, if any |
990 | 179 | cleardir_r( $this->ads_collcache_path ); | 168 | cleardir_r( $this->ads_collcache_path ); |
991 | 180 | 169 | ||
992 | 181 | return true; | 170 | return true; |
993 | @@ -198,66 +187,57 @@ | |||
994 | 198 | */ | 187 | */ |
995 | 199 | function check() | 188 | function check() |
996 | 200 | { | 189 | { |
997 | 201 | global $Debuglog; | ||
998 | 202 | global $disp; | 190 | global $disp; |
999 | 203 | |||
1000 | 204 | global $Messages; | 191 | global $Messages; |
1001 | 205 | 192 | ||
1002 | 206 | if( ! $this->is_enabled ) | 193 | if( ! $this->is_enabled ) |
1005 | 207 | { // We do NOT want caching for this page | 194 | { |
1006 | 208 | $Debuglog->add( 'Cache not enabled. No lookup nor caching performed.', 'cache' ); | 195 | // We do NOT want caching for this page |
1007 | 209 | return false; | 196 | return false; |
1008 | 210 | } | 197 | } |
1009 | 211 | 198 | ||
1010 | 212 | if( $disp == '404' ) | 199 | if( $disp == '404' ) |
1013 | 213 | { // We do NOT want caching for 404 pages (illimited possibilities!) | 200 | { |
1014 | 214 | $Debuglog->add( 'Never cache 404s!', 'cache' ); | 201 | // We do NOT want caching for 404 pages (illimited possibilities!) |
1015 | 215 | return false; | 202 | return false; |
1016 | 216 | } | 203 | } |
1017 | 217 | 204 | ||
1018 | 218 | if( is_logged_in() ) | 205 | if( is_logged_in() ) |
1021 | 219 | { // We do NOT want caching when a user is logged in (private data) | 206 | { |
1022 | 220 | $Debuglog->add( 'Never cache pages for/from logged in members!', 'cache' ); | 207 | // We do NOT want caching when a user is logged in (private data) |
1023 | 221 | return false; | 208 | return false; |
1024 | 222 | } | 209 | } |
1025 | 223 | 210 | ||
1026 | 224 | if( $Messages->count('all') ) | 211 | if( $Messages->count('all') ) |
1028 | 225 | { // There are some messages do be displayed. That means the user has done some action. | 212 | { |
1029 | 213 | // There are some messages do be displayed. That means the user has done some action. | ||
1030 | 226 | // We do want to display those messages. | 214 | // We do want to display those messages. |
1031 | 227 | // There may also be more... like a "comment pending review" etc... | 215 | // There may also be more... like a "comment pending review" etc... |
1032 | 228 | // DO NOT CACHE and do not present a cached page. | 216 | // DO NOT CACHE and do not present a cached page. |
1033 | 229 | $Debuglog->add( 'Not caching because we have messages!', 'cache' ); | ||
1034 | 230 | return false; | 217 | return false; |
1035 | 231 | } | 218 | } |
1036 | 232 | 219 | ||
1037 | 233 | // TODO: fp> If the user has submitted a comment, we might actually want to invalidate the cache... | ||
1038 | 234 | |||
1039 | 235 | |||
1040 | 236 | if( $this->retrieve() ) | 220 | if( $this->retrieve() ) |
1042 | 237 | { // We could retrieve: | 221 | { |
1043 | 222 | // We could retrieve | ||
1044 | 238 | return true; | 223 | return true; |
1045 | 239 | } | 224 | } |
1046 | 240 | 225 | ||
1047 | 241 | |||
1048 | 242 | $this->is_collecting = true; | 226 | $this->is_collecting = true; |
1049 | 243 | |||
1050 | 244 | $Debuglog->add( 'Collecting started', 'cache' ); | ||
1051 | 245 | |||
1052 | 246 | ob_start( array( & $this, 'output_handler'), $this->output_chunk_size ); | 227 | ob_start( array( & $this, 'output_handler'), $this->output_chunk_size ); |
1053 | 247 | |||
1054 | 248 | return false; | 228 | return false; |
1055 | 249 | } | 229 | } |
1056 | 250 | 230 | ||
1057 | 251 | 231 | ||
1058 | 252 | /** | 232 | /** |
1060 | 253 | * Retrieve and output cache for current URL. | 233 | * Retrieve and output cache for current URL |
1061 | 254 | * | 234 | * |
1062 | 255 | * @return boolean true if we could retrieve | 235 | * @return boolean true if we could retrieve |
1063 | 256 | */ | 236 | */ |
1064 | 257 | function retrieve() | 237 | function retrieve() |
1065 | 258 | { | 238 | { |
1068 | 259 | global $Debuglog; | 239 | global $ReqHost; |
1069 | 260 | global $ReqHost, $ReqURI; | 240 | global $ReqURI; |
1070 | 261 | global $servertimenow; | 241 | global $servertimenow; |
1071 | 262 | 242 | ||
1072 | 263 | // What would be the cache file for the current URL? | 243 | // What would be the cache file for the current URL? |
1073 | @@ -275,48 +255,46 @@ | |||
1074 | 275 | */ | 255 | */ |
1075 | 276 | 256 | ||
1076 | 277 | $lines = @file( $af_cache_file, false ); | 257 | $lines = @file( $af_cache_file, false ); |
1086 | 278 | // fp> note we are using empty() so that we detect both the case where there is no file and the case wher ethe file | 258 | // fp> note we are using empty() so that we detect both the case where there |
1087 | 279 | // might have ended up empty because PHP crashed while writing to it or sth like that... | 259 | // is no file and the case wher ethe file might have ended up empty because |
1088 | 280 | if( ! empty($lines) ) | 260 | // PHP crashed while writing to it or sth like that... |
1089 | 281 | { // We have data in the cache! | 261 | if( ! empty( $lines ) ) |
1090 | 282 | $Debuglog->add( 'Retrieving from cache!', 'cache' ); | 262 | { |
1091 | 283 | 263 | // We have data in the cache! | |
1092 | 284 | // Check that the format of the file if OK. | 264 | // Check that the format of the file if OK |
1093 | 285 | $sep = trim($lines[2]); | 265 | $sep = trim( $lines[2] ); |
1094 | 286 | unset($lines[2]); | 266 | unset( $lines[2] ); |
1095 | 287 | if( $sep != '' ) | 267 | if( $sep != '' ) |
1096 | 288 | { | 268 | { |
1097 | 289 | $Debuglog->add( 'Cached file format not recognized, aborting retrieve.', 'cache' ); | ||
1098 | 290 | return false; | 269 | return false; |
1099 | 291 | } | 270 | } |
1100 | 292 | 271 | ||
1104 | 293 | // Retrieved cached URL: | 272 | // Retrieved cached URL |
1105 | 294 | $retrieved_url = trim($lines[0]); | 273 | $retrieved_url = trim( $lines[0] ); |
1106 | 295 | unset($lines[0]); | 274 | unset( $lines[0] ); |
1107 | 296 | if( $retrieved_url != $ReqHost.$ReqURI ) | 275 | if( $retrieved_url != $ReqHost.$ReqURI ) |
1108 | 297 | { | 276 | { |
1109 | 298 | $Debuglog->add( 'Cached file URL ['.$retrieved_url.'] does not match current URL, aborting retrieve.', 'cache' ); | ||
1110 | 299 | return false; | 277 | return false; |
1111 | 300 | } | 278 | } |
1112 | 301 | 279 | ||
1116 | 302 | // timestamp of cache generation: | 280 | // timestamp of cache generation |
1117 | 303 | $retrieved_ts = trim($lines[1]); | 281 | $retrieved_ts = trim( $lines[1] ); |
1118 | 304 | unset($lines[1]); | 282 | unset( $lines[1] ); |
1119 | 305 | $cache_age = $servertimenow-$retrieved_ts; | 283 | $cache_age = $servertimenow-$retrieved_ts; |
1120 | 306 | $Debuglog->add( 'Cache age: '.floor($cache_age/60).' min '.($cache_age % 60).' sec', 'cache' ); | ||
1121 | 307 | if( $cache_age > $this->max_age_seconds ) | 284 | if( $cache_age > $this->max_age_seconds ) |
1123 | 308 | { // Cache has expired | 285 | { |
1124 | 286 | // Cache has expired | ||
1125 | 309 | return false; | 287 | return false; |
1126 | 310 | } | 288 | } |
1127 | 311 | 289 | ||
1128 | 312 | // Go through headers | 290 | // Go through headers |
1129 | 313 | $i = 2; | 291 | $i = 2; |
1131 | 314 | while( $headerline = trim($lines[++$i]) ) | 292 | while( $headerline = trim( $lines[++$i] ) ) |
1132 | 315 | { | 293 | { |
1133 | 316 | header( $headerline ); | 294 | header( $headerline ); |
1135 | 317 | unset($lines[$i]); | 295 | unset( $lines[$i] ); |
1136 | 318 | } | 296 | } |
1138 | 319 | unset($lines[$i]); | 297 | unset( $lines[$i] ); |
1139 | 320 | 298 | ||
1140 | 321 | // SEND CONTENT! | 299 | // SEND CONTENT! |
1141 | 322 | echo implode('',$lines); | 300 | echo implode('',$lines); |
1142 | @@ -326,7 +304,7 @@ | |||
1143 | 326 | } | 304 | } |
1144 | 327 | 305 | ||
1145 | 328 | 306 | ||
1147 | 329 | /** | 307 | /** |
1148 | 330 | * This is called every x bytes to provide real time output | 308 | * This is called every x bytes to provide real time output |
1149 | 331 | */ | 309 | */ |
1150 | 332 | function output_handler( $buffer ) | 310 | function output_handler( $buffer ) |
1151 | @@ -337,21 +315,17 @@ | |||
1152 | 337 | 315 | ||
1153 | 338 | 316 | ||
1154 | 339 | /** | 317 | /** |
1156 | 340 | * We are going to output personal data and we want to abort collecting the data for the cache. | 318 | * We are going to output personal data and we want to abort collecting the data for the cache |
1157 | 341 | */ | 319 | */ |
1158 | 342 | function abort_collect() | 320 | function abort_collect() |
1159 | 343 | { | 321 | { |
1160 | 344 | global $Debuglog; | ||
1161 | 345 | |||
1162 | 346 | if( ! $this->is_collecting ) | 322 | if( ! $this->is_collecting ) |
1164 | 347 | { // We are not collecting anyway | 323 | { |
1165 | 324 | // We are not collecting anyway | ||
1166 | 348 | return; | 325 | return; |
1167 | 349 | } | 326 | } |
1168 | 350 | 327 | ||
1169 | 351 | $Debuglog->add( 'Aborting cache data collection...', 'cache' ); | ||
1170 | 352 | |||
1171 | 353 | ob_end_flush(); | 328 | ob_end_flush(); |
1172 | 354 | |||
1173 | 355 | // We are no longer collecting... | 329 | // We are no longer collecting... |
1174 | 356 | $this->is_collecting = false; | 330 | $this->is_collecting = false; |
1175 | 357 | } | 331 | } |
1176 | @@ -362,41 +336,42 @@ | |||
1177 | 362 | */ | 336 | */ |
1178 | 363 | function end_collect() | 337 | function end_collect() |
1179 | 364 | { | 338 | { |
1180 | 365 | global $Debuglog; | ||
1181 | 366 | |||
1182 | 367 | if( ! $this->is_collecting ) | 339 | if( ! $this->is_collecting ) |
1184 | 368 | { // We are not collecting | 340 | { |
1185 | 341 | // We are not collecting | ||
1186 | 369 | return; | 342 | return; |
1187 | 370 | } | 343 | } |
1188 | 371 | 344 | ||
1189 | 372 | ob_end_flush(); | 345 | ob_end_flush(); |
1190 | 373 | |||
1191 | 374 | // What would be the cache file for the current URL? | 346 | // What would be the cache file for the current URL? |
1192 | 375 | $af_cache_file = $this->get_af_filecache_path(); | 347 | $af_cache_file = $this->get_af_filecache_path(); |
1193 | 376 | 348 | ||
1194 | 377 | // fp> 'x' mode should either give an exclusive write lock or fail | 349 | // fp> 'x' mode should either give an exclusive write lock or fail |
1196 | 378 | // fp> TODO: this here should be ok, but it would be even better with locking the file when we start collecting cache | 350 | // @todo (0000) fp> this here should be ok, but it would be even better with |
1197 | 351 | // locking the file when we start collecting cache | ||
1198 | 379 | if( ! $fh = @fopen( $af_cache_file.'.tmp', 'x', false ) ) | 352 | if( ! $fh = @fopen( $af_cache_file.'.tmp', 'x', false ) ) |
1199 | 380 | { | 353 | { |
1201 | 381 | $Debuglog->add( 'Could not open cache file!', 'cache' ); | 354 | // debuglog-add removed |
1202 | 382 | } | 355 | } |
1203 | 383 | else | 356 | else |
1204 | 384 | { | 357 | { |
1209 | 385 | // Put the URL of the page we are caching into the cache. You can never be to paranoid! | 358 | global $content_type_header; |
1210 | 386 | // People can change their domain names, folder structures, etc... AND you cannot trust the hash to give a | 359 | global $ReqHost; |
1211 | 387 | // different file name in 100.00% of the cases! Serving a page for a different URL would be REEEEEALLLY BAAAAAAD! | 360 | global $ReqURI; |
1212 | 388 | global $ReqHost, $ReqURI; | 361 | global $servertimenow; |
1213 | 362 | |||
1214 | 363 | // Put the URL of the page we are caching into the cache. You can never be | ||
1215 | 364 | // to paranoid! People can change their domain names, folder structures, etc... | ||
1216 | 365 | // AND you cannot trust the hash to give a different file name in 100.00% of | ||
1217 | 366 | // the cases! Serving a page for a different URL would be REEEEEALLLY BAAAAAAD! | ||
1218 | 389 | $file_head = $ReqHost.$ReqURI."\n"; | 367 | $file_head = $ReqHost.$ReqURI."\n"; |
1219 | 390 | 368 | ||
1220 | 391 | // Put the time of the page generation into the file (btw this is the time of when we started this script) | 369 | // Put the time of the page generation into the file (btw this is the time of when we started this script) |
1221 | 392 | global $servertimenow; | ||
1222 | 393 | $file_head .= $servertimenow."\n"; | 370 | $file_head .= $servertimenow."\n"; |
1225 | 394 | 371 | $file_head .= "\n"; | |
1224 | 395 | $file_head .= "\n"; | ||
1226 | 396 | 372 | ||
1227 | 397 | // We need to write the content type! | 373 | // We need to write the content type! |
1230 | 398 | global $content_type_header; | 374 | if( ! empty( $content_type_header ) ) |
1229 | 399 | if( !empty($content_type_header) ) | ||
1231 | 400 | { | 375 | { |
1232 | 401 | $file_head .= $content_type_header."\n"; | 376 | $file_head .= $content_type_header."\n"; |
1233 | 402 | } | 377 | } |
1234 | @@ -408,29 +383,23 @@ | |||
1235 | 408 | 383 | ||
1236 | 409 | // Now atomically replace old cache with new cache (at least on Linux) | 384 | // Now atomically replace old cache with new cache (at least on Linux) |
1237 | 410 | if( ! @rename( $af_cache_file.'.tmp', $af_cache_file ) ) | 385 | if( ! @rename( $af_cache_file.'.tmp', $af_cache_file ) ) |
1239 | 411 | { // Rename failed, we are probably on windows PHP <= 5.2.5... http://bugs.php.net/bug.php?id=44805 | 386 | { |
1240 | 387 | // Rename failed, we are probably on windows PHP <= 5.2.5... http://bugs.php.net/bug.php?id=44805 | ||
1241 | 412 | // we have to split this: | 388 | // we have to split this: |
1244 | 413 | $Debuglog->add( 'Renaming of cache file failed. (Windows?)', 'cache' ); | 389 | // Kill cache |
1243 | 414 | // Kill cache: | ||
1245 | 415 | unlink( $af_cache_file ); | 390 | unlink( $af_cache_file ); |
1247 | 416 | // Now, some other process might start to try caching (and will likely give up since the .tmp file already exists) | 391 | // Now, some other process might start to try caching (and will likely give |
1248 | 392 | // up since the .tmp file already exists) | ||
1249 | 417 | if( ! @rename( $af_cache_file.'.tmp', $af_cache_file ) ) | 393 | if( ! @rename( $af_cache_file.'.tmp', $af_cache_file ) ) |
1252 | 418 | { // Hide errors bc another PHP process could have beaten us to writing a new file there | 394 | { |
1253 | 419 | // Anyways, we still could not rename, let's drop the .tmp file: | 395 | // Hide errors bc another PHP process could have beaten us to writing a new file there |
1254 | 396 | // Anyways, we still could not rename, let's drop the .tmp file | ||
1255 | 420 | unlink( $af_cache_file.'.tmp' ); | 397 | unlink( $af_cache_file.'.tmp' ); |
1256 | 421 | } | 398 | } |
1257 | 422 | else | ||
1258 | 423 | { | ||
1259 | 424 | $Debuglog->add( 'Cache updated... after unlink+rename!', 'cache' ); | ||
1260 | 425 | } | ||
1261 | 426 | } | ||
1262 | 427 | else | ||
1263 | 428 | { | ||
1264 | 429 | $Debuglog->add( 'Cache updated!', 'cache' ); | ||
1265 | 430 | } | 399 | } |
1266 | 431 | } | 400 | } |
1267 | 432 | } | 401 | } |
1268 | 433 | 402 | ||
1269 | 434 | } | 403 | } |
1270 | 435 | 404 | ||
1271 | 436 | ?> | ||
1272 | 437 | \ No newline at end of file | 405 | \ No newline at end of file |
1273 | 406 | ?> | ||
1274 | 438 | 407 | ||
1275 | === modified file 'qp_inc/_core/model/_timer.class.php' | |||
1276 | --- qp_inc/_core/model/_timer.class.php 2010-12-31 12:12:03 +0000 | |||
1277 | +++ qp_inc/_core/model/_timer.class.php 2013-03-20 18:13:29 +0000 | |||
1278 | @@ -1,62 +1,43 @@ | |||
1279 | 1 | <?php | 1 | <?php |
1280 | 2 | /** | 2 | /** |
1314 | 3 | * This file implements the Timer class. | 3 | * This file implements the Timer base class |
1315 | 4 | * | 4 | * |
1283 | 5 | * This file is part of Quam Plures - {@link http://quamplures.net/} | ||
1284 | 6 | * See also {@link https://launchpad.net/quam-plures}. | ||
1285 | 7 | * | ||
1286 | 8 | * @copyright (c) 2009 - 2011 by the Quam Plures developers - {@link http://quamplures.net/} | ||
1287 | 9 | * @copyright (c)2003-2009 by Francois PLANQUE - {@link http://fplanque.net/} | ||
1288 | 10 | * Parts of this file are copyright (c)2004-2006 by Daniel HAHLER - {@link http://thequod.de/contact}. | ||
1289 | 11 | * | ||
1290 | 12 | * {@internal License choice | ||
1291 | 13 | * - If you have received this file as part of a package, please find the license.txt file in | ||
1292 | 14 | * the same folder or the closest folder above for complete license terms. | ||
1293 | 15 | * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/) | ||
1294 | 16 | * then you must choose one of the following licenses before using the file: | ||
1295 | 17 | * - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php | ||
1296 | 18 | * - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php | ||
1297 | 19 | * }} | ||
1298 | 20 | * | ||
1299 | 21 | * {@internal Open Source relicensing agreement: | ||
1300 | 22 | * Daniel HAHLER grants Francois PLANQUE the right to license | ||
1301 | 23 | * Daniel HAHLER's contributions to this file and the b2evolution project | ||
1302 | 24 | * under any OSI approved OSS license (http://www.opensource.org/licenses/). | ||
1303 | 25 | * }} | ||
1304 | 26 | * | ||
1305 | 27 | * {@internal Below is a list of authors who have contributed to design/coding of this file: }} | ||
1306 | 28 | * @author fplanque: Francois PLANQUE. | ||
1307 | 29 | * @author blueyed: Daniel HAHLER. | ||
1308 | 30 | * | ||
1309 | 31 | * @package pond | ||
1310 | 32 | */ | ||
1311 | 33 | if( !defined('QP_MAIN_INIT') ) die( 'Please, do not access this page directly.' ); | ||
1312 | 34 | |||
1313 | 35 | /** | ||
1316 | 36 | * This is a simple class to allow timing/profiling of code portions. | 5 | * This is a simple class to allow timing/profiling of code portions. |
1317 | 37 | * | 6 | * |
1319 | 38 | * @package pond | 7 | * @todo (1111) vars type 'foo' need useful/valid descriptions |
1320 | 8 | * @author {@link http://wonderwinds.com/ Ed Bennett} | ||
1321 | 9 | * @author {@link http://fplanque.net/ Francois PLANQUE} | ||
1322 | 10 | * @author {@link http://daniel.hahler.de/ Daniel HAHLER} | ||
1323 | 11 | * @copyright (c) 2009 by {@link http://quamplures.net/ the Quam Plures project} | ||
1324 | 12 | * @license http://www.gnu.org/licenses/gpl.txt GNU General Public License v3 | ||
1325 | 13 | * @package core | ||
1326 | 14 | */ | ||
1327 | 15 | if(!defined('QP_MAIN_INIT')) die('fail'); | ||
1328 | 16 | |||
1329 | 17 | /** | ||
1330 | 18 | * Timer base class | ||
1331 | 19 | * | ||
1332 | 20 | * @package core | ||
1333 | 39 | */ | 21 | */ |
1334 | 40 | class Timer | 22 | class Timer |
1335 | 41 | { | 23 | { |
1336 | 42 | /** | 24 | /** |
1338 | 43 | * Remember times. | 25 | * Remember times |
1339 | 44 | * | 26 | * |
1340 | 45 | * We store for each category (primary key) the state, start/resume time and the total passed time. | 27 | * We store for each category (primary key) the state, start/resume time and the total passed time. |
1341 | 46 | * | 28 | * |
1343 | 47 | * @access protected | 29 | * @var foo |
1344 | 48 | */ | 30 | */ |
1345 | 49 | var $_times = array(); | 31 | var $_times = array(); |
1346 | 50 | 32 | ||
1347 | 51 | |||
1348 | 52 | /** | 33 | /** |
1350 | 53 | * Constructor. | 34 | * Constructor |
1351 | 54 | * | 35 | * |
1352 | 55 | * @param string|NULL If a category is given the timer starts right away. | 36 | * @param string|NULL If a category is given the timer starts right away. |
1353 | 56 | */ | 37 | */ |
1354 | 57 | function Timer( $category = NULL ) | 38 | function Timer( $category = NULL ) |
1355 | 58 | { | 39 | { |
1357 | 59 | if( is_string($category) ) | 40 | if( is_string( $category ) ) |
1358 | 60 | { | 41 | { |
1359 | 61 | $this->start( $category ); | 42 | $this->start( $category ); |
1360 | 62 | } | 43 | } |
1361 | @@ -64,7 +45,7 @@ | |||
1362 | 64 | 45 | ||
1363 | 65 | 46 | ||
1364 | 66 | /** | 47 | /** |
1366 | 67 | * Reset a timer category. | 48 | * Reset a timer category |
1367 | 68 | */ | 49 | */ |
1368 | 69 | function reset( $category ) | 50 | function reset( $category ) |
1369 | 70 | { | 51 | { |
1370 | @@ -73,49 +54,44 @@ | |||
1371 | 73 | 54 | ||
1372 | 74 | 55 | ||
1373 | 75 | /** | 56 | /** |
1375 | 76 | * Start a timer. | 57 | * Start a timer |
1376 | 77 | */ | 58 | */ |
1377 | 78 | function start( $category, $log = true ) | 59 | function start( $category, $log = true ) |
1378 | 79 | { | 60 | { |
1379 | 80 | global $Debuglog; | ||
1380 | 81 | if( $log && is_object( $Debuglog ) ) $Debuglog->add( 'Starting timer '.$category, 'timer' ); | ||
1381 | 82 | $this->reset( $category ); | 61 | $this->reset( $category ); |
1382 | 83 | $this->resume( $category ); | 62 | $this->resume( $category ); |
1383 | 84 | } | 63 | } |
1384 | 85 | 64 | ||
1385 | 86 | 65 | ||
1386 | 87 | /** | 66 | /** |
1388 | 88 | * Stops a timer category. It may me resumed later on, see {@link resume()}. This is an alias for {@link pause()}. | 67 | * Stops a timer category |
1389 | 68 | * | ||
1390 | 69 | * The timer may me resumed later on, see {@link resume()}. This is an alias for {@link pause()}. | ||
1391 | 89 | * | 70 | * |
1392 | 90 | * @return boolean false, if the timer had not been started. | 71 | * @return boolean false, if the timer had not been started. |
1393 | 91 | */ | 72 | */ |
1394 | 92 | function stop( $category ) | 73 | function stop( $category ) |
1395 | 93 | { | 74 | { |
1396 | 94 | global $Debuglog; | ||
1397 | 95 | |||
1398 | 96 | if( ! $this->pause( $category ) ) | 75 | if( ! $this->pause( $category ) ) |
1399 | 97 | return false; | 76 | return false; |
1400 | 98 | 77 | ||
1401 | 99 | if( is_object( $Debuglog ) ) | ||
1402 | 100 | { | ||
1403 | 101 | $Debuglog->add( 'Stopped timer '.$category.' at '.$this->get_duration( $category, 3 ), 'timer' ); | ||
1404 | 102 | } | ||
1405 | 103 | |||
1406 | 104 | return true; | 78 | return true; |
1407 | 105 | } | 79 | } |
1408 | 106 | 80 | ||
1409 | 107 | 81 | ||
1410 | 108 | /** | 82 | /** |
1412 | 109 | * Pauses a timer category. It may me resumed later on, see {@link resume()}. | 83 | * Pause a timer category |
1413 | 110 | * | 84 | * |
1415 | 111 | * NOTE: The timer needs to be started, either through the {@link Timer() Constructor} or the {@link start()} method. | 85 | * It may me resumed later on, see {@link resume()}. NOTE: The timer needs to be started, |
1416 | 86 | * either through the {@link Timer() Constructor} or the {@link start()} method. | ||
1417 | 112 | * | 87 | * |
1418 | 113 | * @return boolean false, if the timer had not been started. | 88 | * @return boolean false, if the timer had not been started. |
1419 | 114 | */ | 89 | */ |
1420 | 115 | function pause( $category ) | 90 | function pause( $category ) |
1421 | 116 | { | 91 | { |
1424 | 117 | if( !isset($this->_times[$category]['resumed']) ) | 92 | if( ! isset( $this->_times[$category]['resumed'] ) ) |
1425 | 118 | { // Timer has not been started! | 93 | { |
1426 | 94 | // Timer has not been started! | ||
1427 | 119 | return false; | 95 | return false; |
1428 | 120 | } | 96 | } |
1429 | 121 | $since_resume = $this->get_current_microtime() - $this->_times[$category]['resumed']; | 97 | $since_resume = $this->get_current_microtime() - $this->_times[$category]['resumed']; |
1430 | @@ -127,26 +103,25 @@ | |||
1431 | 127 | 103 | ||
1432 | 128 | 104 | ||
1433 | 129 | /** | 105 | /** |
1435 | 130 | * Resumes the timer on a category. | 106 | * Resume the timer on a category |
1436 | 131 | */ | 107 | */ |
1437 | 132 | function resume( $category ) | 108 | function resume( $category ) |
1438 | 133 | { | 109 | { |
1440 | 134 | if( !isset($this->_times[$category]['total']) ) | 110 | if( ! isset( $this->_times[$category]['total'] ) ) |
1441 | 135 | { | 111 | { |
1443 | 136 | $this->start($category); | 112 | $this->start( $category ); |
1444 | 137 | } | 113 | } |
1445 | 138 | else | 114 | else |
1446 | 139 | { | 115 | { |
1447 | 140 | $this->_times[$category]['resumed'] = $this->get_current_microtime(); | 116 | $this->_times[$category]['resumed'] = $this->get_current_microtime(); |
1448 | 141 | $this->_times[$category]['count']++; | 117 | $this->_times[$category]['count']++; |
1449 | 142 | |||
1450 | 143 | $this->_times[$category]['state'] = 'running'; | 118 | $this->_times[$category]['state'] = 'running'; |
1451 | 144 | } | 119 | } |
1452 | 145 | } | 120 | } |
1453 | 146 | 121 | ||
1454 | 147 | 122 | ||
1455 | 148 | /** | 123 | /** |
1457 | 149 | * Get the duration for a given category. | 124 | * Get the duration for a given category |
1458 | 150 | * | 125 | * |
1459 | 151 | * @param string Category name | 126 | * @param string Category name |
1460 | 152 | * @param integer Number of decimals after dot. | 127 | * @param integer Number of decimals after dot. |
1461 | @@ -154,12 +129,13 @@ | |||
1462 | 154 | */ | 129 | */ |
1463 | 155 | function get_duration( $category, $decimals = 3 ) | 130 | function get_duration( $category, $decimals = 3 ) |
1464 | 156 | { | 131 | { |
1466 | 157 | return number_format( $this->get_microtime($category), $decimals ); // TODO: decimals/seperator by locale! | 132 | // @todo (0000) decimals/seperator by locale! |
1467 | 133 | return number_format( $this->get_microtime( $category ), $decimals ); | ||
1468 | 158 | } | 134 | } |
1469 | 159 | 135 | ||
1470 | 160 | 136 | ||
1471 | 161 | /** | 137 | /** |
1473 | 162 | * Get number of timer resumes (includes start). | 138 | * Get number of timer resumes (includes start) |
1474 | 163 | * | 139 | * |
1475 | 164 | * @return integer | 140 | * @return integer |
1476 | 165 | */ | 141 | */ |
1477 | @@ -175,41 +151,40 @@ | |||
1478 | 175 | 151 | ||
1479 | 176 | 152 | ||
1480 | 177 | /** | 153 | /** |
1482 | 178 | * Get the time in microseconds that was spent in the given category. | 154 | * Get the time in microseconds that was spent in the given category |
1483 | 179 | * | 155 | * |
1484 | 180 | * @return float | 156 | * @return float |
1485 | 181 | */ | 157 | */ |
1486 | 182 | function get_microtime( $category ) | 158 | function get_microtime( $category ) |
1487 | 183 | { | 159 | { |
1489 | 184 | switch( $this->get_state($category) ) | 160 | switch( $this->get_state( $category ) ) |
1490 | 185 | { | 161 | { |
1491 | 186 | case 'running': | 162 | case 'running': |
1495 | 187 | // The timer is running, we need to return the additional time since the last resume. | 163 | // The timer is running, we need to return the additional time since the last resume |
1496 | 188 | return $this->_times[$category]['total'] | 164 | return $this->_times[$category]['total'] + $this->get_current_microtime() - $this->_times[$category]['resumed']; |
1494 | 189 | + $this->get_current_microtime() - $this->_times[$category]['resumed']; | ||
1497 | 190 | 165 | ||
1498 | 191 | case 'paused': | 166 | case 'paused': |
1500 | 192 | return $this->_times[$category]['total']; | 167 | return $this->_times[$category]['total']; |
1501 | 193 | 168 | ||
1502 | 194 | default: | 169 | default: |
1504 | 195 | return (float)0; | 170 | return (float)0; |
1505 | 196 | } | 171 | } |
1506 | 197 | } | 172 | } |
1507 | 198 | 173 | ||
1508 | 199 | 174 | ||
1509 | 200 | /** | 175 | /** |
1511 | 201 | * Get the state a category timer is in. | 176 | * Get the state a category timer is in |
1512 | 202 | * | 177 | * |
1513 | 203 | * @return string 'unknown', 'not initialised', 'running', 'paused' | 178 | * @return string 'unknown', 'not initialised', 'running', 'paused' |
1514 | 204 | */ | 179 | */ |
1515 | 205 | function get_state( $category ) | 180 | function get_state( $category ) |
1516 | 206 | { | 181 | { |
1518 | 207 | if( !isset($this->_times[$category]) ) | 182 | if( ! isset( $this->_times[$category] ) ) |
1519 | 208 | { | 183 | { |
1520 | 209 | return 'unknown'; | 184 | return 'unknown'; |
1521 | 210 | } | 185 | } |
1522 | 211 | 186 | ||
1524 | 212 | if( !isset($this->_times[$category]['state']) ) | 187 | if( ! isset( $this->_times[$category]['state'] ) ) |
1525 | 213 | { | 188 | { |
1526 | 214 | return 'not initialised'; | 189 | return 'not initialised'; |
1527 | 215 | } | 190 | } |
1528 | @@ -219,7 +194,7 @@ | |||
1529 | 219 | 194 | ||
1530 | 220 | 195 | ||
1531 | 221 | /** | 196 | /** |
1533 | 222 | * Get a list of used categories. | 197 | * Get a list of used categories |
1534 | 223 | * | 198 | * |
1535 | 224 | * @return array | 199 | * @return array |
1536 | 225 | */ | 200 | */ |
1537 | @@ -236,9 +211,10 @@ | |||
1538 | 236 | */ | 211 | */ |
1539 | 237 | function get_current_microtime() | 212 | function get_current_microtime() |
1540 | 238 | { | 213 | { |
1543 | 239 | list($usec, $sec) = explode(' ', microtime()); | 214 | list( $usec, $sec ) = explode( ' ', microtime() ); |
1544 | 240 | return ((float)$usec + (float)$sec); | 215 | return ( (float)$usec + (float)$sec ); |
1545 | 241 | } | 216 | } |
1546 | 217 | |||
1547 | 242 | } | 218 | } |
1548 | 243 | 219 | ||
1549 | 244 | ?> | ||
1550 | 245 | \ No newline at end of file | 220 | \ No newline at end of file |
1551 | 221 | ?> | ||
1552 | 246 | 222 | ||
1553 | === modified file 'qp_inc/_core/model/dataobjects/_dataobject.class.php' | |||
1554 | --- qp_inc/_core/model/dataobjects/_dataobject.class.php 2010-12-31 12:12:03 +0000 | |||
1555 | +++ qp_inc/_core/model/dataobjects/_dataobject.class.php 2013-03-20 18:13:29 +0000 | |||
1556 | @@ -1,89 +1,86 @@ | |||
1557 | 1 | <?php | 1 | <?php |
1558 | 2 | /** | 2 | /** |
1599 | 3 | * This file implements the abstract DataObject base class. | 3 | * This file implements the abstract DataObject base class |
1560 | 4 | * | ||
1561 | 5 | * This file is part of Quam Plures - {@link http://quamplures.net/} | ||
1562 | 6 | * See also {@link https://launchpad.net/quam-plures}. | ||
1563 | 7 | * | ||
1564 | 8 | * @copyright (c) 2009 - 2011 by the Quam Plures developers - {@link http://quamplures.net/} | ||
1565 | 9 | * @copyright (c)2003-2009 by Francois PLANQUE - {@link http://fplanque.net/} | ||
1566 | 10 | * Parts of this file are copyright (c)2004-2006 by Daniel HAHLER - {@link http://thequod.de/contact}. | ||
1567 | 11 | * Parts of this file are copyright (c)2005-2006 by PROGIDISTRI - {@link http://progidistri.com/}. | ||
1568 | 12 | * | ||
1569 | 13 | * {@internal License choice | ||
1570 | 14 | * - If you have received this file as part of a package, please find the license.txt file in | ||
1571 | 15 | * the same folder or the closest folder above for complete license terms. | ||
1572 | 16 | * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/) | ||
1573 | 17 | * then you must choose one of the following licenses before using the file: | ||
1574 | 18 | * - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php | ||
1575 | 19 | * - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php | ||
1576 | 20 | * }} | ||
1577 | 21 | * | ||
1578 | 22 | * {@internal Open Source relicensing agreement: | ||
1579 | 23 | * Daniel HAHLER grants Francois PLANQUE the right to license | ||
1580 | 24 | * Daniel HAHLER's contributions to this file and the b2evolution project | ||
1581 | 25 | * under any OSI approved OSS license (http://www.opensource.org/licenses/). | ||
1582 | 26 | * | ||
1583 | 27 | * PROGIDISTRI S.A.S. grants Francois PLANQUE the right to license | ||
1584 | 28 | * PROGIDISTRI S.A.S.'s contributions to this file and the b2evolution project | ||
1585 | 29 | * under any OSI approved OSS license (http://www.opensource.org/licenses/). | ||
1586 | 30 | * }} | ||
1587 | 31 | * | ||
1588 | 32 | * {@internal Below is a list of authors who have contributed to design/coding of this file: }} | ||
1589 | 33 | * @author fplanque: Francois PLANQUE | ||
1590 | 34 | * @author blueyed: Daniel HAHLER | ||
1591 | 35 | * @author mbruneau: Marc BRUNEAU / PROGIDISTRI | ||
1592 | 36 | * | ||
1593 | 37 | * @package pond | ||
1594 | 38 | */ | ||
1595 | 39 | if( !defined('QP_MAIN_INIT') ) die( 'Please, do not access this page directly.' ); | ||
1596 | 40 | |||
1597 | 41 | /** | ||
1598 | 42 | * Data Object Base Class | ||
1600 | 43 | * | 4 | * |
1601 | 44 | * This is typically an abstract class, useful only when derived. | 5 | * This is typically an abstract class, useful only when derived. |
1602 | 45 | * | 6 | * |
1605 | 46 | * @version beta | 7 | * @todo (1111) vars type 'foo' need useful/valid descriptions |
1606 | 47 | * @abstract | 8 | * @author {@link http://wonderwinds.com/ Ed Bennett} |
1607 | 9 | * @author {@link http://progidistri.com/ PROGIDISTRI} | ||
1608 | 10 | * @author {@link http://daniel.hahler.de/ Daniel HAHLER} | ||
1609 | 11 | * @author {@link http://fplanque.net/ Francois PLANQUE} | ||
1610 | 12 | * @copyright (c) 2009 by {@link http://quamplures.net/ the Quam Plures project} | ||
1611 | 13 | * @license http://www.gnu.org/licenses/gpl.txt GNU General Public License v3 | ||
1612 | 14 | * @package core | ||
1613 | 15 | */ | ||
1614 | 16 | if(!defined('QP_MAIN_INIT')) die('fail'); | ||
1615 | 17 | |||
1616 | 18 | /** | ||
1617 | 19 | * DataObject base class | ||
1618 | 48 | * | 20 | * |
1620 | 49 | * @package pond | 21 | * @package core |
1621 | 50 | */ | 22 | */ |
1622 | 51 | class DataObject | 23 | class DataObject |
1623 | 52 | { | 24 | { |
1624 | 53 | /** | 25 | /** |
1625 | 54 | * Unique ID of object in database | 26 | * Unique ID of object in database |
1626 | 55 | * | 27 | * |
1628 | 56 | * Please use get/set functions to read or write this param | 28 | * This will be the ID in the DB. Please use get/set functions to read or write this param |
1629 | 57 | * | 29 | * |
1632 | 58 | * @var int | 30 | * @var integer |
1631 | 59 | * @access protected | ||
1633 | 60 | */ | 31 | */ |
1638 | 61 | var $ID = 0; // This will be the ID in the DB | 32 | var $ID = 0; |
1639 | 62 | 33 | /** | |
1640 | 63 | /**#@+ | 34 | * FIX THIS |
1641 | 64 | * @access private | 35 | * @var foo |
1642 | 65 | */ | 36 | */ |
1643 | 66 | var $dbtablename; | 37 | var $dbtablename; |
1644 | 38 | /** | ||
1645 | 39 | * FIX THIS | ||
1646 | 40 | * @var foo | ||
1647 | 41 | */ | ||
1648 | 67 | var $dbprefix; | 42 | var $dbprefix; |
1649 | 43 | /** | ||
1650 | 44 | * FIX THIS | ||
1651 | 45 | * @var foo | ||
1652 | 46 | */ | ||
1653 | 68 | var $dbIDname; | 47 | var $dbIDname; |
1654 | 48 | /** | ||
1655 | 49 | * FIX THIS | ||
1656 | 50 | * @var foo | ||
1657 | 51 | */ | ||
1658 | 69 | var $datecreated_field; | 52 | var $datecreated_field; |
1659 | 53 | /** | ||
1660 | 54 | * FIX THIS | ||
1661 | 55 | * @var foo | ||
1662 | 56 | */ | ||
1663 | 70 | var $datemodified_field; | 57 | var $datemodified_field; |
1664 | 58 | /** | ||
1665 | 59 | * FIX THIS | ||
1666 | 60 | * @var foo | ||
1667 | 61 | */ | ||
1668 | 71 | var $creator_field; | 62 | var $creator_field; |
1669 | 63 | /** | ||
1670 | 64 | * FIX THIS | ||
1671 | 65 | * @var foo | ||
1672 | 66 | */ | ||
1673 | 72 | var $lasteditor_field; | 67 | var $lasteditor_field; |
1674 | 68 | /** | ||
1675 | 69 | * FIX THIS | ||
1676 | 70 | * @var foo | ||
1677 | 71 | */ | ||
1678 | 73 | var $dbchanges = array(); | 72 | var $dbchanges = array(); |
1679 | 74 | /**#@-*/ | ||
1680 | 75 | |||
1681 | 76 | /** | 73 | /** |
1682 | 77 | * Relations that may restrict deletion. | 74 | * Relations that may restrict deletion. |
1683 | 75 | * @var foo | ||
1684 | 78 | */ | 76 | */ |
1685 | 79 | var $delete_restrictions = array(); | 77 | var $delete_restrictions = array(); |
1686 | 80 | |||
1687 | 81 | /** | 78 | /** |
1688 | 82 | * Relations that will cascade deletion. | 79 | * Relations that will cascade deletion. |
1689 | 80 | * @var foo | ||
1690 | 83 | */ | 81 | */ |
1691 | 84 | var $delete_cascades = array(); | 82 | var $delete_cascades = array(); |
1692 | 85 | 83 | ||
1693 | 86 | |||
1694 | 87 | /** | 84 | /** |
1695 | 88 | * Constructor | 85 | * Constructor |
1696 | 89 | * | 86 | * |
1697 | @@ -97,28 +94,29 @@ | |||
1698 | 97 | */ | 94 | */ |
1699 | 98 | function DataObject( $tablename, $prefix = '', $dbIDname = 'ID', $datecreated_field = '', $datemodified_field = '', $creator_field = '', $lasteditor_field = '' ) | 95 | function DataObject( $tablename, $prefix = '', $dbIDname = 'ID', $datecreated_field = '', $datemodified_field = '', $creator_field = '', $lasteditor_field = '' ) |
1700 | 99 | { | 96 | { |
1705 | 100 | $this->dbtablename = $tablename; | 97 | $this->dbtablename = $tablename; |
1706 | 101 | $this->dbprefix = $prefix; | 98 | $this->dbprefix = $prefix; |
1707 | 102 | $this->dbIDname = $dbIDname; | 99 | $this->dbIDname = $dbIDname; |
1708 | 103 | $this->datecreated_field = $datecreated_field; | 100 | $this->datecreated_field = $datecreated_field; |
1709 | 104 | $this->datemodified_field = $datemodified_field; | 101 | $this->datemodified_field = $datemodified_field; |
1712 | 105 | $this->creator_field = $creator_field; | 102 | $this->creator_field = $creator_field; |
1713 | 106 | $this->lasteditor_field = $lasteditor_field; | 103 | $this->lasteditor_field = $lasteditor_field; |
1714 | 107 | } | 104 | } |
1715 | 108 | 105 | ||
1716 | 109 | 106 | ||
1717 | 110 | /** | 107 | /** |
1718 | 111 | * Records a change that will need to be updated in the db | 108 | * Records a change that will need to be updated in the db |
1719 | 112 | * | 109 | * |
1720 | 113 | * @access protected | ||
1721 | 114 | * @param string Name of parameter | 110 | * @param string Name of parameter |
1722 | 115 | * @param string DB field type ('string', 'number', 'date' ) | 111 | * @param string DB field type ('string', 'number', 'date' ) |
1724 | 116 | * @param mixed Pointer to value of parameter - dh> pointer? So it should be a reference? Would make sense IMHO anyway.. fp> I just wonder why it's not already a reference... :@ | 112 | * @param mixed Pointer to value of parameter - dh> pointer? So it should be a |
1725 | 113 | * reference? Would make sense IMHO anyway.. fp> I just wonder why it's not already | ||
1726 | 114 | * a reference... :@ | ||
1727 | 117 | */ | 115 | */ |
1729 | 118 | function dbchange( $dbfieldname, $dbfieldtype, $valuepointer ) // TODO: dh> value by reference? see above.. | 116 | function dbchange( $dbfieldname, $dbfieldtype, $valuepointer ) // @todo (0000) dh> value by reference? see above.. |
1730 | 119 | { | 117 | { |
1731 | 120 | $this->dbchanges[$dbfieldname]['type'] = $dbfieldtype; | 118 | $this->dbchanges[$dbfieldname]['type'] = $dbfieldtype; |
1733 | 121 | $this->dbchanges[$dbfieldname]['value'] = $valuepointer ; | 119 | $this->dbchanges[$dbfieldname]['value'] = $valuepointer; |
1734 | 122 | } | 120 | } |
1735 | 123 | 121 | ||
1736 | 124 | 122 | ||
1737 | @@ -130,24 +128,30 @@ | |||
1738 | 130 | */ | 128 | */ |
1739 | 131 | function dbupdate( $auto_track_modification = true ) | 129 | function dbupdate( $auto_track_modification = true ) |
1740 | 132 | { | 130 | { |
1742 | 133 | global $DB, $localtimenow, $current_User; | 131 | global $current_User; |
1743 | 132 | global $DB; | ||
1744 | 133 | global $localtimenow; | ||
1745 | 134 | 134 | ||
1746 | 135 | if( $this->ID == 0 ) { debug_die( 'New object cannot be updated!' ); } | 135 | if( $this->ID == 0 ) { debug_die( 'New object cannot be updated!' ); } |
1747 | 136 | 136 | ||
1748 | 137 | if( count( $this->dbchanges ) == 0 ) | 137 | if( count( $this->dbchanges ) == 0 ) |
1749 | 138 | { | 138 | { |
1751 | 139 | return NULL; // No changes! | 139 | return NULL; // No changes! |
1752 | 140 | } | 140 | } |
1753 | 141 | 141 | ||
1754 | 142 | if( $auto_track_modification ) | 142 | if( $auto_track_modification ) |
1759 | 143 | { // We wnat to track modification date and author automatically: | 143 | { |
1760 | 144 | if( !empty($this->datemodified_field) ) | 144 | // We want to track modification date and author automatically |
1761 | 145 | { // We want to track modification date: | 145 | if( ! empty( $this->datemodified_field ) ) |
1762 | 146 | $this->set_param( $this->datemodified_field, 'date', date('Y-m-d H:i:s',$localtimenow) ); | 146 | { |
1763 | 147 | // We want to track modification date | ||
1764 | 148 | $this->set_param( $this->datemodified_field, 'date', date( 'Y-m-d H:i:s', $localtimenow ) ); | ||
1765 | 147 | } | 149 | } |
1769 | 148 | if( !empty($this->lasteditor_field) && is_object($current_User) ) | 150 | if( ! empty( $this->lasteditor_field ) && is_object( $current_User ) ) |
1770 | 149 | { // We want to track last editor: | 151 | { |
1771 | 150 | // TODO: the current_User is not necessarily the last editor. Item::dbupdate() gets called after incrementing the view for example! | 152 | // We want to track last editor |
1772 | 153 | // @todo (0000) the current_User is not necessarily the last editor. | ||
1773 | 154 | // Item::dbupdate() gets called after incrementing the view for example! | ||
1774 | 151 | // fplanque: this should be handled by set() deciding wether the setting changes the last editor or not | 155 | // fplanque: this should be handled by set() deciding wether the setting changes the last editor or not |
1775 | 152 | $this->set_param( $this->lasteditor_field, 'number', $current_User->ID ); | 156 | $this->set_param( $this->lasteditor_field, 'number', $current_User->ID ); |
1776 | 153 | } | 157 | } |
1777 | @@ -156,10 +160,11 @@ | |||
1778 | 156 | $sql_changes = array(); | 160 | $sql_changes = array(); |
1779 | 157 | foreach( $this->dbchanges as $loop_dbfieldname => $loop_dbchange ) | 161 | foreach( $this->dbchanges as $loop_dbfieldname => $loop_dbchange ) |
1780 | 158 | { | 162 | { |
1782 | 159 | // Get changed value (we use eval() to allow constructs like $loop_dbchange['value'] = 'Group->get(\'ID\')'): | 163 | // Get changed value |
1783 | 164 | // (we use eval() to allow constructs like $loop_dbchange['value'] = 'Group->get(\'ID\')'): | ||
1784 | 160 | eval( '$loop_value = $this->'.$loop_dbchange['value'].';' ); | 165 | eval( '$loop_value = $this->'.$loop_dbchange['value'].';' ); |
1787 | 161 | // Prepare matching statement: | 166 | // Prepare matching statement |
1788 | 162 | if( is_null($loop_value) ) | 167 | if( is_null( $loop_value ) ) |
1789 | 163 | { | 168 | { |
1790 | 164 | $sql_changes[] = $loop_dbfieldname.' = NULL '; | 169 | $sql_changes[] = $loop_dbfieldname.' = NULL '; |
1791 | 165 | } | 170 | } |
1792 | @@ -169,25 +174,24 @@ | |||
1793 | 169 | { | 174 | { |
1794 | 170 | case 'date': | 175 | case 'date': |
1795 | 171 | case 'string': | 176 | case 'string': |
1798 | 172 | $sql_changes[] = $loop_dbfieldname." = '".$DB->escape( $loop_value )."' "; | 177 | $sql_changes[] = $loop_dbfieldname." = '".$DB->escape( $loop_value )."' "; |
1799 | 173 | break; | 178 | break; |
1800 | 174 | 179 | ||
1801 | 175 | default: | 180 | default: |
1803 | 176 | $sql_changes[] = $loop_dbfieldname." = ".$DB->null($loop_value).' '; | 181 | $sql_changes[] = $loop_dbfieldname." = ".$DB->null( $loop_value ).' '; |
1804 | 177 | } | 182 | } |
1805 | 178 | } | 183 | } |
1806 | 179 | } | 184 | } |
1807 | 180 | 185 | ||
1811 | 181 | // Prepare full statement: | 186 | // Prepare full statement |
1812 | 182 | $sql = "UPDATE $this->dbtablename SET ". implode( ', ', $sql_changes ). " | 187 | $sql = "UPDATE $this->dbtablename SET ". implode( ', ', $sql_changes ). " WHERE $this->dbIDname = $this->ID"; |
1810 | 183 | WHERE $this->dbIDname = $this->ID"; | ||
1813 | 184 | 188 | ||
1814 | 185 | if( ! $DB->query( $sql, 'DataObject::dbupdate()' ) ) | 189 | if( ! $DB->query( $sql, 'DataObject::dbupdate()' ) ) |
1815 | 186 | { | 190 | { |
1816 | 187 | return false; | 191 | return false; |
1817 | 188 | } | 192 | } |
1818 | 189 | 193 | ||
1820 | 190 | // Reset changes in object: | 194 | // Reset changes in object |
1821 | 191 | $this->dbchanges = array(); | 195 | $this->dbchanges = array(); |
1822 | 192 | 196 | ||
1823 | 193 | return true; | 197 | return true; |
1824 | @@ -195,35 +199,43 @@ | |||
1825 | 195 | 199 | ||
1826 | 196 | 200 | ||
1827 | 197 | /** | 201 | /** |
1829 | 198 | * Insert object into DB based on previously recorded changes. | 202 | * Insert object into DB based on previously recorded changes |
1830 | 199 | * | 203 | * |
1831 | 200 | * @return boolean true on success | 204 | * @return boolean true on success |
1832 | 201 | */ | 205 | */ |
1833 | 202 | function dbinsert() | 206 | function dbinsert() |
1834 | 203 | { | 207 | { |
1836 | 204 | global $DB, $localtimenow, $current_User; | 208 | global $current_User; |
1837 | 209 | global $DB; | ||
1838 | 210 | global $localtimenow; | ||
1839 | 205 | 211 | ||
1840 | 206 | if( $this->ID != 0 ) debug_die( 'Existing object cannot be inserted!' ); | 212 | if( $this->ID != 0 ) debug_die( 'Existing object cannot be inserted!' ); |
1841 | 207 | 213 | ||
1854 | 208 | if( !empty($this->datecreated_field) ) | 214 | if( ! empty( $this->datecreated_field ) ) |
1855 | 209 | { // We want to track creation date: | 215 | { |
1856 | 210 | $this->set_param( $this->datecreated_field, 'date', date('Y-m-d H:i:s',$localtimenow) ); | 216 | // We want to track creation date |
1857 | 211 | } | 217 | $this->set_param( $this->datecreated_field, 'date', date( 'Y-m-d H:i:s', $localtimenow ) ); |
1858 | 212 | if( !empty($this->datemodified_field) ) | 218 | } |
1859 | 213 | { // We want to track modification date: | 219 | if( ! empty( $this->datemodified_field ) ) |
1860 | 214 | $this->set_param( $this->datemodified_field, 'date', date('Y-m-d H:i:s',$localtimenow) ); | 220 | { |
1861 | 215 | } | 221 | // We want to track modification date |
1862 | 216 | if( !empty($this->creator_field) ) | 222 | $this->set_param( $this->datemodified_field, 'date', date( 'Y-m-d H:i:s', $localtimenow ) ); |
1863 | 217 | { // We want to track creator: | 223 | } |
1864 | 218 | if( empty($this->creator_user_ID) ) | 224 | if( ! empty( $this->creator_field ) ) |
1865 | 219 | { // No creator assigned yet, use current user: | 225 | { |
1866 | 226 | // We want to track creator | ||
1867 | 227 | if( empty( $this->creator_user_ID ) ) | ||
1868 | 228 | { | ||
1869 | 229 | // No creator assigned yet, use current user | ||
1870 | 220 | $this->set_param( $this->creator_field, 'number', $current_User->ID ); | 230 | $this->set_param( $this->creator_field, 'number', $current_User->ID ); |
1871 | 221 | } | 231 | } |
1872 | 222 | } | 232 | } |
1877 | 223 | if( !empty($this->lasteditor_field) ) | 233 | if( ! empty( $this->lasteditor_field ) ) |
1878 | 224 | { // We want to track last editor: | 234 | { |
1879 | 225 | if( empty($this->lastedit_user_ID) ) | 235 | // We want to track last editor |
1880 | 226 | { // No editor assigned yet, use current user: | 236 | if( empty( $this->lastedit_user_ID ) ) |
1881 | 237 | { | ||
1882 | 238 | // No editor assigned yet, use current user | ||
1883 | 227 | $this->set_param( $this->lasteditor_field, 'number', $current_User->ID ); | 239 | $this->set_param( $this->lasteditor_field, 'number', $current_User->ID ); |
1884 | 228 | } | 240 | } |
1885 | 229 | } | 241 | } |
1886 | @@ -232,11 +244,12 @@ | |||
1887 | 232 | $sql_values = array(); | 244 | $sql_values = array(); |
1888 | 233 | foreach( $this->dbchanges as $loop_dbfieldname => $loop_dbchange ) | 245 | foreach( $this->dbchanges as $loop_dbfieldname => $loop_dbchange ) |
1889 | 234 | { | 246 | { |
1891 | 235 | // Get changed value (we use eval() to allow constructs like $loop_dbchange['value'] = 'Group->get(\'ID\')'): | 247 | // Get changed value |
1892 | 248 | // (we use eval() to allow constructs like $loop_dbchange['value'] = 'Group->get(\'ID\')'): | ||
1893 | 236 | eval( '$loop_value = $this->'. $loop_dbchange['value'].';' ); | 249 | eval( '$loop_value = $this->'. $loop_dbchange['value'].';' ); |
1895 | 237 | // Prepare matching statement: | 250 | // Prepare matching statement |
1896 | 238 | $sql_fields[] = $loop_dbfieldname; | 251 | $sql_fields[] = $loop_dbfieldname; |
1898 | 239 | if( is_null($loop_value) ) | 252 | if( is_null( $loop_value ) ) |
1899 | 240 | { | 253 | { |
1900 | 241 | $sql_values[] = 'NULL'; | 254 | $sql_values[] = 'NULL'; |
1901 | 242 | } | 255 | } |
1902 | @@ -246,16 +259,16 @@ | |||
1903 | 246 | { | 259 | { |
1904 | 247 | case 'date': | 260 | case 'date': |
1905 | 248 | case 'string': | 261 | case 'string': |
1908 | 249 | $sql_values[] = $DB->quote( $loop_value ); | 262 | $sql_values[] = $DB->quote( $loop_value ); |
1909 | 250 | break; | 263 | break; |
1910 | 251 | 264 | ||
1911 | 252 | default: | 265 | default: |
1913 | 253 | $sql_values[] = $DB->null( $loop_value ); | 266 | $sql_values[] = $DB->null( $loop_value ); |
1914 | 254 | } | 267 | } |
1915 | 255 | } | 268 | } |
1916 | 256 | } | 269 | } |
1917 | 257 | 270 | ||
1919 | 258 | // Prepare full statement: | 271 | // Prepare full statement |
1920 | 259 | $sql = "INSERT INTO {$this->dbtablename} (". implode( ', ', $sql_fields ). ") VALUES (". implode( ', ', $sql_values ). ")"; | 272 | $sql = "INSERT INTO {$this->dbtablename} (". implode( ', ', $sql_fields ). ") VALUES (". implode( ', ', $sql_values ). ")"; |
1921 | 260 | 273 | ||
1922 | 261 | if( ! $DB->query( $sql, 'DataObject::dbinsert()' ) ) | 274 | if( ! $DB->query( $sql, 'DataObject::dbinsert()' ) ) |
1923 | @@ -266,7 +279,7 @@ | |||
1924 | 266 | // store ID for newly created db record | 279 | // store ID for newly created db record |
1925 | 267 | $this->ID = $DB->insert_id; | 280 | $this->ID = $DB->insert_id; |
1926 | 268 | 281 | ||
1928 | 269 | // Reset changes in object: | 282 | // Reset changes in object |
1929 | 270 | $this->dbchanges = array(); | 283 | $this->dbchanges = array(); |
1930 | 271 | 284 | ||
1931 | 272 | return true; | 285 | return true; |
1932 | @@ -274,7 +287,7 @@ | |||
1933 | 274 | 287 | ||
1934 | 275 | 288 | ||
1935 | 276 | /** | 289 | /** |
1937 | 277 | * Inserts or Updates depending on object state. | 290 | * Inserts or Updates depending on object state |
1938 | 278 | * | 291 | * |
1939 | 279 | * @uses dbinsert() | 292 | * @uses dbinsert() |
1940 | 280 | * @uses dbupdate() | 293 | * @uses dbupdate() |
1941 | @@ -283,55 +296,57 @@ | |||
1942 | 283 | function dbsave() | 296 | function dbsave() |
1943 | 284 | { | 297 | { |
1944 | 285 | if( $this->ID == 0 ) | 298 | if( $this->ID == 0 ) |
1946 | 286 | { // Object not serialized yet, let's insert! | 299 | { |
1947 | 300 | // Object not serialized yet, let's insert! | ||
1948 | 287 | return $this->dbinsert(); | 301 | return $this->dbinsert(); |
1949 | 288 | } | 302 | } |
1950 | 289 | else | 303 | else |
1952 | 290 | { // Object already serialized, let's update! | 304 | { |
1953 | 305 | // Object already serialized, let's update! | ||
1954 | 291 | return $this->dbupdate(); | 306 | return $this->dbupdate(); |
1955 | 292 | } | 307 | } |
1956 | 293 | } | 308 | } |
1957 | 294 | 309 | ||
1958 | 295 | 310 | ||
1959 | 296 | /** | 311 | /** |
1961 | 297 | * Delete object from DB. | 312 | * Delete object from DB |
1962 | 298 | * | 313 | * |
1963 | 299 | * @return boolean true on success | 314 | * @return boolean true on success |
1964 | 300 | */ | 315 | */ |
1965 | 301 | function dbdelete() | 316 | function dbdelete() |
1966 | 302 | { | 317 | { |
1968 | 303 | global $DB, $Messages, $app_db_config; | 318 | global $app_db_config; |
1969 | 319 | global $DB; | ||
1970 | 320 | global $Messages; | ||
1971 | 304 | 321 | ||
1972 | 305 | if( $this->ID == 0 ) { debug_die( 'Non persistant object cannot be deleted!' ); } | 322 | if( $this->ID == 0 ) { debug_die( 'Non persistant object cannot be deleted!' ); } |
1973 | 306 | 323 | ||
1978 | 307 | if( count($this->delete_cascades) ) | 324 | if( count( $this->delete_cascades ) ) |
1979 | 308 | { // The are cascading deletes to be performed | 325 | { |
1980 | 309 | 326 | // The are cascading deletes to be performed; start transaction | |
1977 | 310 | // Start transaction: | ||
1981 | 311 | $DB->begin(); | 327 | $DB->begin(); |
1982 | 312 | 328 | ||
1983 | 313 | foreach( $this->delete_cascades as $restriction ) | 329 | foreach( $this->delete_cascades as $restriction ) |
1984 | 314 | { | 330 | { |
1987 | 315 | if( !isset( $app_db_config['aliases'][$restriction['table']] ) ) | 331 | if( ! isset( $app_db_config['aliases'][$restriction['table']] ) ) |
1988 | 316 | { // We have no declaration for this table, we consider we don't deal with this table in this app: | 332 | { |
1989 | 333 | // We have no declaration for this table, we consider we don't deal with this table in this app | ||
1990 | 317 | continue; | 334 | continue; |
1991 | 318 | } | 335 | } |
1992 | 319 | 336 | ||
1997 | 320 | $DB->query( ' | 337 | $DB->query( 'DELETE FROM '.$restriction['table'].' WHERE '.$restriction['fk'].' = '.$this->ID, 'Cascaded delete' ); |
1994 | 321 | DELETE FROM '.$restriction['table'].' | ||
1995 | 322 | WHERE '.$restriction['fk'].' = '.$this->ID, | ||
1996 | 323 | 'Cascaded delete' ); | ||
1998 | 324 | } | 338 | } |
1999 | 325 | } | 339 | } |
2000 | 326 | 340 | ||
2002 | 327 | // Delete this (main/parent) object: | 341 | // Delete this (main/parent) object |
2003 | 328 | $DB->query( " | 342 | $DB->query( " |
2004 | 329 | DELETE FROM $this->dbtablename | 343 | DELETE FROM $this->dbtablename |
2005 | 330 | WHERE $this->dbIDname = $this->ID", | 344 | WHERE $this->dbIDname = $this->ID", |
2006 | 331 | 'Main delete' ); | 345 | 'Main delete' ); |
2007 | 332 | 346 | ||
2010 | 333 | if( count($this->delete_cascades) ) | 347 | if( count( $this->delete_cascades ) ) |
2011 | 334 | { // There were cascading deletes | 348 | { |
2012 | 349 | // There were cascading deletes | ||
2013 | 335 | 350 | ||
2014 | 336 | // End transaction: | 351 | // End transaction: |
2015 | 337 | $DB->commit(); | 352 | $DB->commit(); |
2016 | @@ -347,36 +362,42 @@ | |||
2017 | 347 | /** | 362 | /** |
2018 | 348 | * Check relations for restrictions or cascades | 363 | * Check relations for restrictions or cascades |
2019 | 349 | * | 364 | * |
2020 | 365 | * The $verbose_callbacks array is as follows: | ||
2021 | 366 | * <ul> <li>Array keys (string): Foreign key this callback should apply to.</li> | ||
2022 | 367 | * <li>Array values: Arrays with the following keys: | ||
2023 | 368 | * <ul><li>'cb' (callback): Callback to call. Should take one array argument, which | ||
2024 | 369 | * will contain the following keys:</li> | ||
2025 | 370 | * <li>'fk': The foreign key.</li> | ||
2026 | 371 | * <li>'table': The SQL table for this relation.</li> | ||
2027 | 372 | * <li>'msg': A format string -- a base message to be displayed.It normally shows | ||
2028 | 373 | * the number of results.</li> | ||
2029 | 374 | * <li>'id': The ID of this object.</li> | ||
2030 | 375 | * </li></ul></ul> | ||
2031 | 376 | * | ||
2032 | 350 | * @param string Which relation should be checked ('delete_restrictions' or 'delete_cascades')? | 377 | * @param string Which relation should be checked ('delete_restrictions' or 'delete_cascades')? |
2033 | 351 | * @param string An array of foreign key checks to skip. | 378 | * @param string An array of foreign key checks to skip. |
2044 | 352 | * @param array An array of callbacks used to display more information about a relation. | 379 | * @param array An array of callbacks used to display more information about a relation. |
2035 | 353 | * - Array keys (string): Foreign key this callback should apply to. | ||
2036 | 354 | * - Array values: Arrays with the following keys: | ||
2037 | 355 | * - 'cb' (callback): Callback to call. Should take one array argument, which | ||
2038 | 356 | * will contain the following keys: | ||
2039 | 357 | * - 'fk': The foreign key. | ||
2040 | 358 | * - 'table': The SQL table for this relation. | ||
2041 | 359 | * - 'msg': A format string -- a base message to be displayed. | ||
2042 | 360 | * It normally shows the number of results. | ||
2043 | 361 | * - 'id': The ID of this object. | ||
2045 | 362 | */ | 380 | */ |
2046 | 363 | function check_relations( $what, $ignore = array(), $verbose_callbacks = array() ) | 381 | function check_relations( $what, $ignore = array(), $verbose_callbacks = array() ) |
2047 | 364 | { | 382 | { |
2049 | 365 | global $DB, $Messages; | 383 | global $DB; |
2050 | 384 | global $Messages; | ||
2051 | 366 | 385 | ||
2052 | 367 | foreach( $this->$what as $restriction ) | 386 | foreach( $this->$what as $restriction ) |
2053 | 368 | { | 387 | { |
2054 | 369 | if( in_array( $restriction['fk'], $ignore ) ) | 388 | if( in_array( $restriction['fk'], $ignore ) ) |
2056 | 370 | { // Skip this relation check. | 389 | { |
2057 | 390 | // Skip this relation check | ||
2058 | 371 | continue; | 391 | continue; |
2059 | 372 | } | 392 | } |
2060 | 373 | 393 | ||
2061 | 374 | if( ! isset( $verbose_callbacks[$restriction['fk']] ) ) | 394 | if( ! isset( $verbose_callbacks[$restriction['fk']] ) ) |
2063 | 375 | { // We do not want to display detailed info, just the result count: | 395 | { |
2064 | 396 | // We do not want to display detailed info, just the result count | ||
2065 | 376 | $count = $DB->get_var( | 397 | $count = $DB->get_var( |
2066 | 377 | 'SELECT COUNT(*) | 398 | 'SELECT COUNT(*) |
2069 | 378 | FROM '.$restriction['table'].' | 399 | FROM '.$restriction['table'].' |
2070 | 379 | WHERE '.$restriction['fk'].' = '.$this->ID, | 400 | WHERE '.$restriction['fk'].' = '.$this->ID, |
2071 | 380 | 0, 0, 'restriction/cascade check' ); | 401 | 0, 0, 'restriction/cascade check' ); |
2072 | 381 | if( $count ) | 402 | if( $count ) |
2073 | 382 | { | 403 | { |
2074 | @@ -384,7 +405,8 @@ | |||
2075 | 384 | } | 405 | } |
2076 | 385 | } | 406 | } |
2077 | 386 | else | 407 | else |
2079 | 387 | { // We want verbose information. | 408 | { |
2080 | 409 | // We want verbose information. | ||
2081 | 388 | // We just will call the callback, providing some | 410 | // We just will call the callback, providing some |
2082 | 389 | // information about this object: | 411 | // information about this object: |
2083 | 390 | call_user_func( $verbose_callbacks[$restriction['fk']]['cb'], | 412 | call_user_func( $verbose_callbacks[$restriction['fk']]['cb'], |
2084 | @@ -411,16 +433,17 @@ | |||
2085 | 411 | $this->check_relations( 'delete_restrictions', $ignore ); | 433 | $this->check_relations( 'delete_restrictions', $ignore ); |
2086 | 412 | 434 | ||
2087 | 413 | if( $Messages->count('restrict') ) | 435 | if( $Messages->count('restrict') ) |
2089 | 414 | { // There are restrictions: | 436 | { |
2090 | 437 | // There are restrictions: | ||
2091 | 415 | $Messages->head = array( | 438 | $Messages->head = array( |
2092 | 416 | 'container' => $restrict_title, | 439 | 'container' => $restrict_title, |
2093 | 417 | 'restrict' => T_('The following relations prevent deletion:') | 440 | 'restrict' => T_('The following relations prevent deletion:') |
2094 | 418 | ); | 441 | ); |
2097 | 419 | $Messages->foot = T_('Please delete related objects before you proceed.'); | 442 | $Messages->foot = T_('Please delete related objects before you proceed.'); |
2098 | 420 | return false; // Can't delete | 443 | return false; // Can't delete |
2099 | 421 | } | 444 | } |
2100 | 422 | 445 | ||
2102 | 423 | return true; // can delete | 446 | return true; // can delete |
2103 | 424 | } | 447 | } |
2104 | 425 | 448 | ||
2105 | 426 | 449 | ||
2106 | @@ -444,7 +467,8 @@ | |||
2107 | 444 | $this->check_relations( 'delete_cascades' ); | 467 | $this->check_relations( 'delete_cascades' ); |
2108 | 445 | 468 | ||
2109 | 446 | if( $Messages->count('restrict') ) | 469 | if( $Messages->count('restrict') ) |
2111 | 447 | { // The will be cascading deletes, issue WARNING: | 470 | { |
2112 | 471 | // The will be cascading deletes, issue WARNING | ||
2113 | 448 | echo '<h3>'.T_('WARNING: Deleting this object will also delete:').'</h3>'; | 472 | echo '<h3>'.T_('WARNING: Deleting this object will also delete:').'</h3>'; |
2114 | 449 | $Messages->display( '', '', true, 'restrict', NULL, NULL, NULL ); | 473 | $Messages->display( '', '', true, 'restrict', NULL, NULL, NULL ); |
2115 | 450 | } | 474 | } |
2116 | @@ -465,7 +489,7 @@ | |||
2117 | 465 | 489 | ||
2118 | 466 | $Form->begin_form( 'inline' ); | 490 | $Form->begin_form( 'inline' ); |
2119 | 467 | $Form->hiddens_by_key( $hiddens ); | 491 | $Form->hiddens_by_key( $hiddens ); |
2121 | 468 | if( !empty( $cancel_action ) ) | 492 | if( ! empty( $cancel_action ) ) |
2122 | 469 | { | 493 | { |
2123 | 470 | $Form->hidden( 'action', $cancel_action ); | 494 | $Form->hidden( 'action', $cancel_action ); |
2124 | 471 | } | 495 | } |
2125 | @@ -500,7 +524,7 @@ | |||
2126 | 500 | function dget( $parname, $format = 'htmlbody' ) | 524 | function dget( $parname, $format = 'htmlbody' ) |
2127 | 501 | { | 525 | { |
2128 | 502 | // Note: we call get again because of derived objects specific handlers ! | 526 | // Note: we call get again because of derived objects specific handlers ! |
2130 | 503 | return format_to_output( $this->get($parname), $format ); | 527 | return format_to_output( $this->get( $parname ), $format ); |
2131 | 504 | } | 528 | } |
2132 | 505 | 529 | ||
2133 | 506 | 530 | ||
2134 | @@ -513,7 +537,7 @@ | |||
2135 | 513 | function disp( $parname, $format = 'htmlbody' ) | 537 | function disp( $parname, $format = 'htmlbody' ) |
2136 | 514 | { | 538 | { |
2137 | 515 | // Note: we call get again because of derived objects specific handlers ! | 539 | // Note: we call get again because of derived objects specific handlers ! |
2139 | 516 | echo format_to_output( $this->get($parname), $format ); | 540 | echo format_to_output( $this->get( $parname ), $format ); |
2140 | 517 | } | 541 | } |
2141 | 518 | 542 | ||
2142 | 519 | 543 | ||
2143 | @@ -534,90 +558,74 @@ | |||
2144 | 534 | 558 | ||
2145 | 535 | 559 | ||
2146 | 536 | /** | 560 | /** |
2148 | 537 | * Set param value. | 561 | * Set param value |
2149 | 538 | * | 562 | * |
2150 | 539 | * @param string Name of parameter | 563 | * @param string Name of parameter |
2152 | 540 | * @param string DB field type ('string', 'number', 'date' ) | 564 | * @param string DB field type ('string', 'number', 'date') |
2153 | 541 | * @param mixed Value of parameter | 565 | * @param mixed Value of parameter |
2154 | 542 | * @param boolean true to set to NULL if empty string value | 566 | * @param boolean true to set to NULL if empty string value |
2155 | 543 | * @return boolean true, if value has been set/changed, false if not. | 567 | * @return boolean true, if value has been set/changed, false if not. |
2156 | 544 | */ | 568 | */ |
2157 | 545 | function set_param( $parname, $fieldtype, $parvalue, $make_null = false ) | 569 | function set_param( $parname, $fieldtype, $parvalue, $make_null = false ) |
2158 | 546 | { | 570 | { |
2159 | 547 | global $Debuglog; | ||
2160 | 548 | |||
2161 | 549 | $dbfield = $this->dbprefix.$parname; | 571 | $dbfield = $this->dbprefix.$parname; |
2162 | 550 | 572 | ||
2168 | 551 | // Set value: | 573 | // Set value. fplanque: Note: I am changing the "make NULL" test to differentiate |
2169 | 552 | // fplanque: Note: I am changing the "make NULL" test to differentiate between 0 and NULL . | 574 | // between 0 and NULL. There might be side effects. In this case it would be |
2170 | 553 | // There might be side effects. In this case it would be better to fix them before coming here. | 575 | // better to fix them before coming here. i-e: transform 0 to '' |
2171 | 554 | // i-e: transform 0 to '' | 576 | $new_value = ( $make_null && ( $parvalue === '' ) ) ? NULL : $parvalue; |
2167 | 555 | $new_value = ($make_null && ($parvalue === '')) ? NULL : $parvalue; | ||
2172 | 556 | 577 | ||
2196 | 557 | /* Tblue> Problem: All class member variables originating from the | 578 | // Tblue> Problem: All class member variables originating from the DB are strings |
2197 | 558 | * DB are strings (unless they were NULL in the DB, | 579 | // (unless they were NULL in the DB, then they are set to NULL by the PHP MySQL |
2198 | 559 | * then they are set to NULL by the PHP MySQL | 580 | // extension). If we pass an integer or a double to this function, the corresponding |
2199 | 560 | * extension). | 581 | // member variable gets changed on every call, because its type is 'string' and |
2200 | 561 | * If we pass an integer or a double to this function, | 582 | // we compare using the === operator. Using the == operator would be a bad idea, |
2201 | 562 | * the corresponding member variable gets changed | 583 | // though, because somebody could pass a NULL value to this function. If the member |
2202 | 563 | * on every call, because its type is 'string' and | 584 | // variable then is set to 0, then 0 equals NULL and the member variable does not |
2203 | 564 | * we compare using the === operator. Using the | 585 | // get updated at all! Thus, using the === operator is correct. |
2204 | 565 | * == operator would be a bad idea, though, because | 586 | // Solution: If $fieldtype is 'number' and the type of the passed value is either |
2205 | 566 | * somebody could pass a NULL value to this function. | 587 | // integer or double, we convert it to a string (no data loss). The member variable and |
2206 | 567 | * If the member variable then is set to 0, then | 588 | // the passed value can then be correctly compared using the === operator. |
2207 | 568 | * 0 equals NULL and the member variable does not | 589 | // fp> It would be nicer to convert numeric values to ints & floats at load time in |
2208 | 569 | * get updated at all! | 590 | // class constructor x=(int)$y->value or sth. |
2209 | 570 | * Thus, using the === operator is correct. | 591 | // THIS IS EXPERIMENTAL! Feel free to revert if something does not |
2210 | 571 | * Solution: If $fieldtype is 'number' and the type of the | 592 | // work as expected. |
2188 | 572 | * passed value is either integer or double, we | ||
2189 | 573 | * convert it to a string (no data loss). The | ||
2190 | 574 | * member variable and the passed value can then | ||
2191 | 575 | * be correctly compared using the === operator. | ||
2192 | 576 | * fp> It would be nicer to convert numeric values to ints & floats at load time in class constructor x=(int)$y->value or sth. | ||
2193 | 577 | * THIS IS EXPERIMENTAL! Feel free to revert if something does not | ||
2194 | 578 | * work as expected. | ||
2195 | 579 | */ | ||
2211 | 580 | if( $fieldtype == 'number' && ( is_int( $new_value ) || is_float( $new_value ) ) ) | 593 | if( $fieldtype == 'number' && ( is_int( $new_value ) || is_float( $new_value ) ) ) |
2212 | 581 | { | 594 | { |
2213 | 582 | settype( $new_value, 'string' ); | 595 | settype( $new_value, 'string' ); |
2214 | 583 | } | 596 | } |
2215 | 584 | 597 | ||
2219 | 585 | /* >old | 598 | /* |
2220 | 586 | if( !isset($this->$parname) ) | 599 | old way |
2221 | 587 | { // This property has never been set before, set it to NULL now in order for tests to work: | 600 | if( ! isset( $this->$parname ) ) |
2222 | 601 | { | ||
2223 | 602 | // This property has never been set before, set it to NULL now in order for tests to work: | ||
2224 | 588 | $this->$parname = NULL; | 603 | $this->$parname = NULL; |
2225 | 589 | } | 604 | } |
2226 | 590 | 605 | ||
2245 | 591 | 606 | @todo (0000) blueyed> there's a bug here: you cannot use set_param('foo', | |
2246 | 592 | /* blueyed> | 607 | 'number', 0), if the $parname member has not been set before or is null!! What |
2247 | 593 | TODO: there's a bug here: you cannot use set_param('foo', 'number', 0), if the $parname member | 608 | about just:( isset( $this->$parname ) && $this->$parname === $new_value ) |
2248 | 594 | has not been set before or is null!! | 609 | This would also eliminate the isset() check from above. IIRC you've once said |
2249 | 595 | What about just: | 610 | here that '===' would be too expensive and I would misuse the DataObjects, but |
2250 | 596 | ( isset($this->$parname) && $this->$parname === $new_value ) | 611 | IMHO what we have now is not much faster and buggy anyway. fp> okay let's give |
2251 | 597 | This would also eliminate the isset() check from above. | 612 | it a try... |
2252 | 598 | IIRC you've once said here that '===' would be too expensive and I would misuse the DataObjects, | 613 | if( ( ! is_null( $new_value ) && $this->$parname == $new_value ) |
2253 | 599 | but IMHO what we have now is not much faster and buggy anyway.. | 614 | || ( is_null( $this->$parname ) && is_null( $new_value ) ) ) |
2254 | 600 | fp> okay let's give it a try... | 615 | */ |
2255 | 601 | if( (!is_null($new_value) && $this->$parname == $new_value) | 616 | |
2256 | 602 | || (is_null($this->$parname) && is_null($new_value)) ) | 617 | if( ( isset( $this->$parname ) && $this->$parname === $new_value ) |
2257 | 603 | <old */ | 618 | || ( ! isset( $this->$parname ) && ! isset( $new_value ) ) ) |
2258 | 604 | if( (isset($this->$parname) && $this->$parname === $new_value) | 619 | { |
2259 | 605 | || ( ! isset($this->$parname) && ! isset($new_value) ) ) | 620 | // Value has not changed (we need 2 tests, for NULL and for NOT NULL value pairs) |
2242 | 606 | { // Value has not changed (we need 2 tests, for NULL and for NOT NULL value pairs) | ||
2243 | 607 | $Debuglog->add( $this->dbtablename.' object, already set to same value: '.$parname.'/'.$dbfield.' = '.var_export( @$this->$parname, true ), 'dataobjects' ); | ||
2244 | 608 | |||
2260 | 609 | return false; | 621 | return false; |
2261 | 610 | } | 622 | } |
2262 | 611 | else | 623 | else |
2263 | 612 | { | 624 | { |
2269 | 613 | // Set the value in the object: | 625 | // Set the value in the object |
2265 | 614 | $Debuglog->add( $this->dbtablename.' object, setting param ' | ||
2266 | 615 | .$parname.'/'.$dbfield.' to '.var_export( $new_value, true ) | ||
2267 | 616 | .' (old: '.( isset( $this->$parname ) ? var_export( $this->$parname, true ) : 'NULL' ) | ||
2268 | 617 | .')', 'dataobjects' ); | ||
2270 | 618 | $this->$parname = $new_value; | 626 | $this->$parname = $new_value; |
2271 | 619 | 627 | ||
2273 | 620 | // Remember change for later db update: | 628 | // Remember change for later db update |
2274 | 621 | $this->dbchange( $dbfield, $fieldtype, $parname ); | 629 | $this->dbchange( $dbfield, $fieldtype, $parname ); |
2275 | 622 | 630 | ||
2276 | 623 | return true; | 631 | return true; |
2277 | @@ -626,7 +634,7 @@ | |||
2278 | 626 | 634 | ||
2279 | 627 | 635 | ||
2280 | 628 | /** | 636 | /** |
2282 | 629 | * Set a parameter from a Request form value. | 637 | * Set a parameter from a Request form value |
2283 | 630 | * | 638 | * |
2284 | 631 | * @param string Dataobject parameter name | 639 | * @param string Dataobject parameter name |
2285 | 632 | * @param string Request parameter name (NULL means to use Dataobject param name with its prefix) | 640 | * @param string Request parameter name (NULL means to use Dataobject param name with its prefix) |
2286 | @@ -635,17 +643,17 @@ | |||
2287 | 635 | */ | 643 | */ |
2288 | 636 | function set_from_Request( $parname, $var = NULL, $make_null = false ) | 644 | function set_from_Request( $parname, $var = NULL, $make_null = false ) |
2289 | 637 | { | 645 | { |
2291 | 638 | if( empty($var) ) | 646 | if( empty( $var ) ) |
2292 | 639 | { | 647 | { |
2293 | 640 | $var = $this->dbprefix.$parname; | 648 | $var = $this->dbprefix.$parname; |
2294 | 641 | } | 649 | } |
2295 | 642 | 650 | ||
2297 | 643 | return $this->set( $parname, get_param($var), $make_null ); | 651 | return $this->set( $parname, get_param( $var ), $make_null ); |
2298 | 644 | } | 652 | } |
2299 | 645 | 653 | ||
2300 | 646 | 654 | ||
2301 | 647 | /** | 655 | /** |
2303 | 648 | * Template function: Displays object ID. | 656 | * Template function: Displays object ID |
2304 | 649 | */ | 657 | */ |
2305 | 650 | function ID() | 658 | function ID() |
2306 | 651 | { | 659 | { |
2307 | @@ -662,47 +670,56 @@ | |||
2308 | 662 | $UserCache = & get_Cache( 'UserCache' ); | 670 | $UserCache = & get_Cache( 'UserCache' ); |
2309 | 663 | 671 | ||
2310 | 664 | // HANDLE CREATOR STUFF | 672 | // HANDLE CREATOR STUFF |
2313 | 665 | if( !empty($this->creator_field) && !empty($this->{$this->creator_field}) ) | 673 | if( ! empty( $this->creator_field ) && ! empty( $this->{$this->creator_field} ) ) |
2314 | 666 | { // We have a creator: | 674 | { |
2315 | 675 | // We have a creator | ||
2316 | 667 | $creator_User = & $UserCache->get_by_ID( $this->{$this->creator_field} ); | 676 | $creator_User = & $UserCache->get_by_ID( $this->{$this->creator_field} ); |
2317 | 668 | 677 | ||
2320 | 669 | if( !empty($this->datecreated_field) && !empty($this->{$this->datecreated_field}) ) | 678 | if( ! empty( $this->datecreated_field ) && ! empty( $this->{$this->datecreated_field} ) ) |
2321 | 670 | { // We also have a create date: | 679 | { |
2322 | 680 | // We also have a create date | ||
2323 | 671 | $history[0] = sprintf( T_('Created on %s by %s'), mysql2localedate( $this->{$this->datecreated_field} ), | 681 | $history[0] = sprintf( T_('Created on %s by %s'), mysql2localedate( $this->{$this->datecreated_field} ), |
2325 | 672 | $creator_User->dget('preferredname') ); | 682 | $creator_User->dget( 'preferredname' ) ); |
2326 | 673 | } | 683 | } |
2327 | 674 | else | 684 | else |
2330 | 675 | { // We only have a cretaor: | 685 | { |
2331 | 676 | $history[0] = sprintf( T_('Created by %s'), $creator_User->dget('preferredname') ); | 686 | // We only have a creator |
2332 | 687 | $history[0] = sprintf( T_('Created by %s'), $creator_User->dget( 'preferredname' ) ); | ||
2333 | 677 | } | 688 | } |
2334 | 678 | } | 689 | } |
2337 | 679 | elseif( !empty($this->datecreated_field) && !empty($this->{$this->datecreated_field}) ) | 690 | elseif( ! empty( $this->datecreated_field ) && ! empty( $this->{$this->datecreated_field} ) ) |
2338 | 680 | { // We only have a create date: | 691 | { |
2339 | 692 | // We only have a create date | ||
2340 | 681 | $history[0] = sprintf( T_('Created on %s'), mysql2localedate( $this->{$this->datecreated_field} ) ); | 693 | $history[0] = sprintf( T_('Created on %s'), mysql2localedate( $this->{$this->datecreated_field} ) ); |
2341 | 682 | } | 694 | } |
2342 | 683 | 695 | ||
2343 | 684 | // HANDLE LAST UPDATE STUFF | 696 | // HANDLE LAST UPDATE STUFF |
2346 | 685 | if( !empty($this->lasteditor_field) && !empty($this->{$this->lasteditor_field}) ) | 697 | if( ! empty( $this->lasteditor_field ) && ! empty( $this->{$this->lasteditor_field} ) ) |
2347 | 686 | { // We have a creator: | 698 | { |
2348 | 699 | // We have a creator | ||
2349 | 687 | $creator_User = & $UserCache->get_by_ID( $this->{$this->lasteditor_field} ); | 700 | $creator_User = & $UserCache->get_by_ID( $this->{$this->lasteditor_field} ); |
2350 | 688 | 701 | ||
2353 | 689 | if( !empty($this->datemodified_field) && !empty($this->{$this->datemodified_field}) ) | 702 | if( ! empty( $this->datemodified_field ) && ! empty( $this->{$this->datemodified_field} ) ) |
2354 | 690 | { // We also have a create date: | 703 | { |
2355 | 704 | // We also have a create date | ||
2356 | 691 | $history[1] = sprintf( T_('Last mod on %s by %s'), mysql2localedate( $this->{$this->datemodified_field} ), | 705 | $history[1] = sprintf( T_('Last mod on %s by %s'), mysql2localedate( $this->{$this->datemodified_field} ), |
2358 | 692 | $creator_User->dget('preferredname') ); | 706 | $creator_User->dget( 'preferredname' ) ); |
2359 | 693 | } | 707 | } |
2360 | 694 | else | 708 | else |
2363 | 695 | { // We only have a cretaor: | 709 | { |
2364 | 696 | $history[1] = sprintf( T_('Last mod by %s'), $creator_User->dget('preferredname') ); | 710 | // We only have a creator |
2365 | 711 | $history[1] = sprintf( T_('Last mod by %s'), $creator_User->dget( 'preferredname' ) ); | ||
2366 | 697 | } | 712 | } |
2367 | 698 | } | 713 | } |
2370 | 699 | elseif( !empty($this->datemodified_field) && !empty($this->{$this->datemodified_field}) ) | 714 | elseif( ! empty( $this->datemodified_field ) && ! empty( $this->{$this->datemodified_field} ) ) |
2371 | 700 | { // We only have a create date: | 715 | { |
2372 | 716 | // We only have a create date | ||
2373 | 701 | $history[1] = sprintf( T_('Last mod on %s'), mysql2localedate( $this->{$this->datemodified_field} ) ); | 717 | $history[1] = sprintf( T_('Last mod on %s'), mysql2localedate( $this->{$this->datemodified_field} ) ); |
2374 | 702 | } | 718 | } |
2375 | 703 | 719 | ||
2377 | 704 | return get_icon( 'history', $what = 'imgtag', array( 'title'=>implode( ' - ', $history ) ), true ); | 720 | return get_icon( 'history', $what = 'imgtag', array( 'title' => implode( ' - ', $history ) ), true ); |
2378 | 705 | } | 721 | } |
2379 | 722 | |||
2380 | 706 | } | 723 | } |
2381 | 707 | 724 | ||
2382 | 708 | ?> | 725 | ?> |
2383 | 709 | 726 | ||
2384 | === modified file 'qp_inc/_core/model/dataobjects/_dataobjectcache.class.php' | |||
2385 | --- qp_inc/_core/model/dataobjects/_dataobjectcache.class.php 2010-12-31 12:12:03 +0000 | |||
2386 | +++ qp_inc/_core/model/dataobjects/_dataobjectcache.class.php 2013-03-20 18:13:29 +0000 | |||
2387 | @@ -1,104 +1,95 @@ | |||
2388 | 1 | <?php | 1 | <?php |
2389 | 2 | /** | 2 | /** |
2424 | 3 | * This file implements the DataObjectCache class. | 3 | * This file implements the DataObjectCache base class |
2425 | 4 | * | 4 | * |
2426 | 5 | * This file is part of Quam Plures - {@link http://quamplures.net/} | 5 | * @todo (1111) vars type 'foo' need useful/valid descriptions |
2427 | 6 | * See also {@link https://launchpad.net/quam-plures}. | 6 | * @author {@link http://wonderwinds.com/ Ed Bennett} |
2428 | 7 | * | 7 | * @author {@link http://progidistri.com/ PROGIDISTRI} |
2429 | 8 | * @copyright (c) 2009 - 2011 by the Quam Plures developers - {@link http://quamplures.net/} | 8 | * @author {@link http://daniel.hahler.de/ Daniel HAHLER} |
2430 | 9 | * @copyright (c)2003-2009 by Francois PLANQUE - {@link http://fplanque.net/} | 9 | * @author {@link http://fplanque.net/ Francois PLANQUE} |
2431 | 10 | * Parts of this file are copyright (c)2004-2006 by Daniel HAHLER - {@link http://thequod.de/contact}. | 10 | * @copyright (c) 2009 by {@link http://quamplures.net/ the Quam Plures project} |
2432 | 11 | * Parts of this file are copyright (c)2005-2006 by PROGIDISTRI - {@link http://progidistri.com/}. | 11 | * @license http://www.gnu.org/licenses/gpl.txt GNU General Public License v3 |
2433 | 12 | * | 12 | * @package core |
2400 | 13 | * {@internal License choice | ||
2401 | 14 | * - If you have received this file as part of a package, please find the license.txt file in | ||
2402 | 15 | * the same folder or the closest folder above for complete license terms. | ||
2403 | 16 | * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/) | ||
2404 | 17 | * then you must choose one of the following licenses before using the file: | ||
2405 | 18 | * - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php | ||
2406 | 19 | * - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php | ||
2407 | 20 | * }} | ||
2408 | 21 | * | ||
2409 | 22 | * {@internal Open Source relicensing agreement: | ||
2410 | 23 | * Daniel HAHLER grants Francois PLANQUE the right to license | ||
2411 | 24 | * Daniel HAHLER's contributions to this file and the b2evolution project | ||
2412 | 25 | * under any OSI approved OSS license (http://www.opensource.org/licenses/). | ||
2413 | 26 | * | ||
2414 | 27 | * PROGIDISTRI S.A.S. grants Francois PLANQUE the right to license | ||
2415 | 28 | * PROGIDISTRI S.A.S.'s contributions to this file and the b2evolution project | ||
2416 | 29 | * under any OSI approved OSS license (http://www.opensource.org/licenses/). | ||
2417 | 30 | * }} | ||
2418 | 31 | * | ||
2419 | 32 | * {@internal Below is a list of authors who have contributed to design/coding of this file: }} | ||
2420 | 33 | * @author blueyed: Daniel HAHLER. | ||
2421 | 34 | * @author fplanque: Francois PLANQUE | ||
2422 | 35 | * | ||
2423 | 36 | * @package pond | ||
2434 | 37 | */ | 13 | */ |
2436 | 38 | if( !defined('QP_MAIN_INIT') ) die( 'Please, do not access this page directly.' ); | 14 | if(!defined('QP_MAIN_INIT')) die('fail'); |
2437 | 39 | 15 | ||
2438 | 40 | /** | 16 | /** |
2446 | 41 | * Data Object Cache Class | 17 | * DataObjectCache base class |
2447 | 42 | * | 18 | * |
2448 | 43 | * @todo dh> Provide iteration "interface"! | 19 | * @package core |
2442 | 44 | * | ||
2443 | 45 | * @version beta | ||
2444 | 46 | * | ||
2445 | 47 | * @package pond | ||
2449 | 48 | */ | 20 | */ |
2450 | 49 | class DataObjectCache | 21 | class DataObjectCache |
2451 | 50 | { | 22 | { |
2452 | 23 | /** | ||
2453 | 24 | * FIX THIS | ||
2454 | 25 | * @var foo | ||
2455 | 26 | */ | ||
2456 | 51 | var $dbtablename; | 27 | var $dbtablename; |
2457 | 28 | /** | ||
2458 | 29 | * FIX THIS | ||
2459 | 30 | * @var foo | ||
2460 | 31 | */ | ||
2461 | 52 | var $dbprefix; | 32 | var $dbprefix; |
2462 | 33 | /** | ||
2463 | 34 | * FIX THIS | ||
2464 | 35 | * @var foo | ||
2465 | 36 | */ | ||
2466 | 53 | var $dbIDname; | 37 | var $dbIDname; |
2467 | 54 | |||
2468 | 55 | /** | 38 | /** |
2469 | 56 | * Class name of objects in this cache: | 39 | * Class name of objects in this cache: |
2470 | 40 | * @var foo | ||
2471 | 57 | */ | 41 | */ |
2472 | 58 | var $objtype; | 42 | var $objtype; |
2473 | 59 | |||
2474 | 60 | /** | 43 | /** |
2475 | 61 | * Object array by ID | 44 | * Object array by ID |
2476 | 45 | * @var foo | ||
2477 | 62 | */ | 46 | */ |
2478 | 63 | var $cache = array(); | 47 | var $cache = array(); |
2479 | 64 | |||
2480 | 65 | /** | 48 | /** |
2481 | 66 | * Copy of previous object array | 49 | * Copy of previous object array |
2482 | 67 | * @see DataObjectCache::clear() | 50 | * @see DataObjectCache::clear() |
2483 | 68 | */ | 51 | */ |
2484 | 69 | var $shadow_cache = NULL; | 52 | var $shadow_cache = NULL; |
2485 | 70 | |||
2486 | 71 | /** | 53 | /** |
2487 | 72 | * NON indexed object array | 54 | * NON indexed object array |
2488 | 73 | * @var array of DataObjects | 55 | * @var array of DataObjects |
2489 | 74 | */ | 56 | */ |
2490 | 75 | var $DataObject_array = array(); | 57 | var $DataObject_array = array(); |
2493 | 76 | 58 | /** | |
2492 | 77 | /** | ||
2494 | 78 | * Index of current iteration | 59 | * Index of current iteration |
2495 | 79 | * @see DataObjectCache::get_next() | 60 | * @see DataObjectCache::get_next() |
2496 | 80 | */ | 61 | */ |
2497 | 81 | var $current_idx = NULL; | 62 | var $current_idx = NULL; |
2499 | 82 | 63 | /** | |
2500 | 64 | * FIX THIS | ||
2501 | 65 | * @var foo | ||
2502 | 66 | */ | ||
2503 | 83 | var $load_all = false; | 67 | var $load_all = false; |
2504 | 68 | /** | ||
2505 | 69 | * FIX THIS | ||
2506 | 70 | * @var foo | ||
2507 | 71 | */ | ||
2508 | 84 | var $all_loaded = false; | 72 | var $all_loaded = false; |
2511 | 85 | 73 | /** | |
2512 | 86 | 74 | * FIX THIS | |
2513 | 75 | * @var foo | ||
2514 | 76 | */ | ||
2515 | 87 | var $name_field; | 77 | var $name_field; |
2516 | 78 | /** | ||
2517 | 79 | * FIX THIS | ||
2518 | 80 | * @var foo | ||
2519 | 81 | */ | ||
2520 | 88 | var $order_by; | 82 | var $order_by; |
2521 | 89 | |||
2522 | 90 | /** | 83 | /** |
2524 | 91 | * The text that gets used for the "None" option in the objects options list. | 84 | * The text that gets used for the "None" option in the objects options list |
2525 | 92 | * | 85 | * |
2526 | 93 | * This is especially useful for i18n, because there are several "None"s! | 86 | * This is especially useful for i18n, because there are several "None"s! |
2527 | 94 | * | 87 | * |
2528 | 95 | * @var string | 88 | * @var string |
2529 | 96 | */ | 89 | */ |
2530 | 97 | var $none_option_text; | 90 | var $none_option_text; |
2531 | 98 | |||
2532 | 99 | /** | 91 | /** |
2535 | 100 | * The value that gets used for the "None" option in the objects options list. | 92 | * The value that gets used for the "None" option in the objects options list |
2534 | 101 | * | ||
2536 | 102 | * @var mixed | 93 | * @var mixed |
2537 | 103 | */ | 94 | */ |
2538 | 104 | var $none_option_value; | 95 | var $none_option_value; |
2539 | @@ -115,9 +106,18 @@ | |||
2540 | 115 | * @param string Name of the name field (including prefix) | 106 | * @param string Name of the name field (including prefix) |
2541 | 116 | * @param string field names or NULL to use name field | 107 | * @param string field names or NULL to use name field |
2542 | 117 | * @param string The text that gets used for the "None" option in the objects options list (Default: T_('None')). | 108 | * @param string The text that gets used for the "None" option in the objects options list (Default: T_('None')). |
2544 | 118 | * @param mixed The value that gets used for the "None" option in the objects options list. | 109 | * @param mixed The value that gets used for the "None" option in the objects options list. |
2545 | 119 | */ | 110 | */ |
2547 | 120 | function DataObjectCache( $objtype, $load_all, $tablename, $prefix = '', $dbIDname, $name_field = NULL, $order_by = '', $allow_none_text = NULL, $allow_none_value = '' ) | 111 | function DataObjectCache( |
2548 | 112 | $objtype, | ||
2549 | 113 | $load_all, | ||
2550 | 114 | $tablename, | ||
2551 | 115 | $prefix = '', | ||
2552 | 116 | $dbIDname, | ||
2553 | 117 | $name_field = NULL, | ||
2554 | 118 | $order_by = '', | ||
2555 | 119 | $allow_none_text = NULL, | ||
2556 | 120 | $allow_none_value = '' ) | ||
2557 | 121 | { | 121 | { |
2558 | 122 | $this->objtype = $objtype; | 122 | $this->objtype = $objtype; |
2559 | 123 | $this->load_all = $load_all; | 123 | $this->load_all = $load_all; |
2560 | @@ -143,7 +143,7 @@ | |||
2561 | 143 | $this->order_by = $order_by; | 143 | $this->order_by = $order_by; |
2562 | 144 | } | 144 | } |
2563 | 145 | 145 | ||
2565 | 146 | if( isset($allow_none_text) ) | 146 | if( isset( $allow_none_text ) ) |
2566 | 147 | { | 147 | { |
2567 | 148 | $this->none_option_text = $allow_none_text; | 148 | $this->none_option_text = $allow_none_text; |
2568 | 149 | } | 149 | } |
2569 | @@ -160,7 +160,6 @@ | |||
2570 | 160 | function & new_obj( $row = NULL ) | 160 | function & new_obj( $row = NULL ) |
2571 | 161 | { | 161 | { |
2572 | 162 | $objtype = $this->objtype; | 162 | $objtype = $this->objtype; |
2573 | 163 | |||
2574 | 164 | // Instantiate a custom object | 163 | // Instantiate a custom object |
2575 | 165 | $obj = new $objtype( $row ); // COPY !! | 164 | $obj = new $objtype( $row ); // COPY !! |
2576 | 166 | 165 | ||
2577 | @@ -173,24 +172,16 @@ | |||
2578 | 173 | */ | 172 | */ |
2579 | 174 | function load_all() | 173 | function load_all() |
2580 | 175 | { | 174 | { |
2581 | 176 | /** | ||
2582 | 177 | * @var DB | ||
2583 | 178 | */ | ||
2584 | 179 | global $DB; | 175 | global $DB; |
2585 | 180 | global $Debuglog; | ||
2586 | 181 | 176 | ||
2587 | 182 | if( $this->all_loaded ) | 177 | if( $this->all_loaded ) |
2589 | 183 | { // Already loaded | 178 | { |
2590 | 179 | // Already loaded | ||
2591 | 184 | return false; | 180 | return false; |
2592 | 185 | } | 181 | } |
2593 | 186 | 182 | ||
2594 | 187 | $this->clear( true ); | 183 | $this->clear( true ); |
2601 | 188 | 184 | $sql = 'SELECT * FROM '.$this->dbtablename.' ORDER BY '.$this->order_by; | |
2596 | 189 | $Debuglog->add( get_class($this).' - Loading <strong>'.$this->objtype.'(ALL)</strong> into cache', 'dataobjects' ); | ||
2597 | 190 | $sql = 'SELECT * | ||
2598 | 191 | FROM '.$this->dbtablename.' | ||
2599 | 192 | ORDER BY '.$this->order_by; | ||
2600 | 193 | |||
2602 | 194 | foreach( $DB->get_results( $sql, OBJECT, 'Loading '.$this->objtype.'(ALL) into cache' ) as $row ) | 185 | foreach( $DB->get_results( $sql, OBJECT, 'Loading '.$this->objtype.'(ALL) into cache' ) as $row ) |
2603 | 195 | { | 186 | { |
2604 | 196 | // Instantiate a custom object | 187 | // Instantiate a custom object |
2605 | @@ -211,19 +202,14 @@ | |||
2606 | 211 | */ | 202 | */ |
2607 | 212 | function load_list( $req_list, $invert = false ) | 203 | function load_list( $req_list, $invert = false ) |
2608 | 213 | { | 204 | { |
2612 | 214 | global $DB, $Debuglog; | 205 | global $DB; |
2610 | 215 | |||
2611 | 216 | $Debuglog->add( 'Loading <strong>'.$this->objtype.'('.( $invert ? 'ALL except ' : '' ).$req_list.')</strong> into cache', 'dataobjects' ); | ||
2613 | 217 | 206 | ||
2614 | 218 | if( empty( $req_list ) ) | 207 | if( empty( $req_list ) ) |
2615 | 219 | { | 208 | { |
2616 | 220 | return false; | 209 | return false; |
2617 | 221 | } | 210 | } |
2618 | 222 | 211 | ||
2623 | 223 | $sql = "SELECT * | 212 | $sql = "SELECT * FROM $this->dbtablename WHERE $this->dbIDname ".( $invert ? 'NOT ' : '' )."IN ( $req_list )"; |
2620 | 224 | FROM $this->dbtablename | ||
2621 | 225 | WHERE $this->dbIDname ".( $invert ? 'NOT ' : '' )."IN ($req_list)"; | ||
2622 | 226 | |||
2624 | 227 | foreach( $DB->get_results( $sql ) as $row ) | 213 | foreach( $DB->get_results( $sql ) as $row ) |
2625 | 228 | { | 214 | { |
2626 | 229 | // Instantiate a custom object | 215 | // Instantiate a custom object |
2627 | @@ -233,19 +219,17 @@ | |||
2628 | 233 | 219 | ||
2629 | 234 | 220 | ||
2630 | 235 | /** | 221 | /** |
2632 | 236 | * Get an array of all (loaded) IDs. | 222 | * Get an array of all (loaded) IDs |
2633 | 237 | * | 223 | * |
2634 | 238 | * @return array | 224 | * @return array |
2635 | 239 | */ | 225 | */ |
2636 | 240 | function get_ID_array() | 226 | function get_ID_array() |
2637 | 241 | { | 227 | { |
2638 | 242 | $IDs = array(); | 228 | $IDs = array(); |
2639 | 243 | |||
2640 | 244 | foreach( $this->cache as $obj ) | 229 | foreach( $this->cache as $obj ) |
2641 | 245 | { | 230 | { |
2642 | 246 | $IDs[] = $obj->ID; | 231 | $IDs[] = $obj->ID; |
2643 | 247 | } | 232 | } |
2644 | 248 | |||
2645 | 249 | return $IDs; | 233 | return $IDs; |
2646 | 250 | } | 234 | } |
2647 | 251 | 235 | ||
2648 | @@ -255,26 +239,21 @@ | |||
2649 | 255 | */ | 239 | */ |
2650 | 256 | function add( & $Obj ) | 240 | function add( & $Obj ) |
2651 | 257 | { | 241 | { |
2655 | 258 | global $Debuglog; | 242 | if( is_null( $Obj->ID ) ) // value 0 is used by item preview |
2653 | 259 | |||
2654 | 260 | if( is_null($Obj->ID) ) // value 0 is used by item preview | ||
2656 | 261 | { | 243 | { |
2657 | 262 | $Debuglog->add( 'No object to add!', 'dataobjects' ); | ||
2658 | 263 | return false; | 244 | return false; |
2659 | 264 | } | 245 | } |
2660 | 265 | 246 | ||
2661 | 266 | // fplanque: I don't want an extra (and expensive) comparison here. $this->cache[$Obj->ID] === $Obj. | 247 | // fplanque: I don't want an extra (and expensive) comparison here. $this->cache[$Obj->ID] === $Obj. |
2662 | 267 | // If you need this you're probably misusing the cache. | 248 | // If you need this you're probably misusing the cache. |
2664 | 268 | if( isset($this->cache[$Obj->ID]) ) | 249 | if( isset( $this->cache[$Obj->ID] ) ) |
2665 | 269 | { | 250 | { |
2666 | 270 | $Debuglog->add( $this->objtype.': Object with ID '.$Obj->ID.' is already cached', 'dataobjects' ); | ||
2667 | 271 | return false; | 251 | return false; |
2668 | 272 | } | 252 | } |
2669 | 273 | 253 | ||
2672 | 274 | // If the object is valid and not already cached: | 254 | // If the object is valid and not already cached, Add object to cache |
2671 | 275 | // Add object to cache: | ||
2673 | 276 | $this->cache[$Obj->ID] = & $Obj; | 255 | $this->cache[$Obj->ID] = & $Obj; |
2675 | 277 | // Add a reference in the object list: | 256 | // Add a reference in the object list |
2676 | 278 | $this->DataObject_array[] = & $Obj; | 257 | $this->DataObject_array[] = & $Obj; |
2677 | 279 | 258 | ||
2678 | 280 | return true; | 259 | return true; |
2679 | @@ -282,36 +261,40 @@ | |||
2680 | 282 | 261 | ||
2681 | 283 | 262 | ||
2682 | 284 | /** | 263 | /** |
2684 | 285 | * Instantiate a DataObject from a table row and then cache it. | 264 | * Instantiate a DataObject from a table row and then cache it |
2685 | 286 | * | 265 | * |
2686 | 287 | * @param Object Database row | 266 | * @param Object Database row |
2687 | 288 | * @return Object | 267 | * @return Object |
2688 | 289 | */ | 268 | */ |
2689 | 290 | function & instantiate( & $db_row ) | 269 | function & instantiate( & $db_row ) |
2690 | 291 | { | 270 | { |
2693 | 292 | if( is_null($db_row) ) | 271 | if( is_null( $db_row ) ) |
2694 | 293 | { // we can't access NULL as an object | 272 | { |
2695 | 273 | // we can't access NULL as an object | ||
2696 | 294 | return $db_row; | 274 | return $db_row; |
2697 | 295 | } | 275 | } |
2698 | 296 | 276 | ||
2699 | 297 | // Get ID of the object we'ere preparing to instantiate... | 277 | // Get ID of the object we'ere preparing to instantiate... |
2700 | 298 | $obj_ID = $db_row->{$this->dbIDname}; | 278 | $obj_ID = $db_row->{$this->dbIDname}; |
2701 | 299 | 279 | ||
2703 | 300 | if( is_null($obj_ID) ) // value 0 is used for item preview | 280 | if( is_null( $obj_ID ) ) // value 0 is used for item preview |
2704 | 301 | { | 281 | { |
2705 | 302 | $Obj = NULL; | 282 | $Obj = NULL; |
2706 | 303 | return $Obj; | 283 | return $Obj; |
2707 | 304 | } | 284 | } |
2708 | 305 | 285 | ||
2709 | 306 | if( isset( $this->cache[$obj_ID] ) ) | 286 | if( isset( $this->cache[$obj_ID] ) ) |
2711 | 307 | { // Already in cache, do nothing! | 287 | { |
2712 | 288 | // Already in cache, do nothing! | ||
2713 | 308 | } | 289 | } |
2714 | 309 | elseif( isset( $this->shadow_cache[$obj_ID] ) ) | 290 | elseif( isset( $this->shadow_cache[$obj_ID] ) ) |
2716 | 310 | { // Already in shadow, recycle object: | 291 | { |
2717 | 292 | // Already in shadow, recycle object | ||
2718 | 311 | $this->add( $this->shadow_cache[$obj_ID] ); | 293 | $this->add( $this->shadow_cache[$obj_ID] ); |
2719 | 312 | } | 294 | } |
2720 | 313 | else | 295 | else |
2722 | 314 | { // Not already cached, add new object: | 296 | { |
2723 | 297 | // Not already cached, add new object | ||
2724 | 315 | $this->add( $this->new_obj( $db_row ) ); | 298 | $this->add( $this->new_obj( $db_row ) ); |
2725 | 316 | } | 299 | } |
2726 | 317 | 300 | ||
2727 | @@ -321,12 +304,12 @@ | |||
2728 | 321 | 304 | ||
2729 | 322 | /** | 305 | /** |
2730 | 323 | * Clear the cache **extensively** | 306 | * Clear the cache **extensively** |
2731 | 324 | * | ||
2732 | 325 | */ | 307 | */ |
2733 | 326 | function clear( $keep_shadow = false ) | 308 | function clear( $keep_shadow = false ) |
2734 | 327 | { | 309 | { |
2735 | 328 | if( $keep_shadow ) | 310 | if( $keep_shadow ) |
2737 | 329 | { // Keep copy of cache in case we try to re instantiate previous object: | 311 | { |
2738 | 312 | // Keep copy of cache in case we try to re instantiate previous object | ||
2739 | 330 | $this->shadow_cache = $this->cache; | 313 | $this->shadow_cache = $this->cache; |
2740 | 331 | } | 314 | } |
2741 | 332 | else | 315 | else |
2742 | @@ -341,33 +324,30 @@ | |||
2743 | 341 | } | 324 | } |
2744 | 342 | 325 | ||
2745 | 343 | 326 | ||
2748 | 344 | /** | 327 | /** |
2749 | 345 | * This provides a simple interface for looping over the contents of the Cache. | 328 | * This provides a simple interface for looping over the contents of the Cache |
2750 | 346 | * | 329 | * |
2753 | 347 | * This should only be used for basic enumeration. | 330 | * This should only be used for basic enumeration. If you need complex filtering |
2754 | 348 | * If you need complex filtering of the cache contents, you should probablt use a DataObjectList instead. | 331 | * of the cache contents, you should probablt use a DataObjectList instead. |
2755 | 349 | * | 332 | * |
2756 | 350 | * @see DataObject::get_next() | 333 | * @see DataObject::get_next() |
2757 | 351 | * | ||
2758 | 352 | * @return DataObject | 334 | * @return DataObject |
2759 | 353 | */ | 335 | */ |
2760 | 354 | function & get_first() | 336 | function & get_first() |
2761 | 355 | { | 337 | { |
2762 | 356 | $this->load_all(); | 338 | $this->load_all(); |
2763 | 357 | |||
2764 | 358 | $this->current_idx = -1; | 339 | $this->current_idx = -1; |
2765 | 359 | return $this->get_next(); | 340 | return $this->get_next(); |
2766 | 360 | } | 341 | } |
2767 | 361 | 342 | ||
2768 | 362 | 343 | ||
2771 | 363 | /** | 344 | /** |
2772 | 364 | * This provides a simple interface for looping over the contents of the Cache. | 345 | * This provides a simple interface for looping over the contents of the Cache |
2773 | 365 | * | 346 | * |
2776 | 366 | * This should only be used for basic enumeration. | 347 | * This should only be used for basic enumeration. If you need complex filtering |
2777 | 367 | * If you need complex filtering of the cache contents, you should probablt use a DataObjectList instead. | 348 | * of the cache contents, you should probably use a DataObjectList instead. |
2778 | 368 | * | 349 | * |
2779 | 369 | * @see DataObject::get_first() | 350 | * @see DataObject::get_first() |
2780 | 370 | * | ||
2781 | 371 | * @return DataObject | 351 | * @return DataObject |
2782 | 372 | */ | 352 | */ |
2783 | 373 | function & get_next() | 353 | function & get_next() |
2784 | @@ -397,11 +377,11 @@ | |||
2785 | 397 | */ | 377 | */ |
2786 | 398 | function & get_by_ID( $req_ID, $halt_on_error = true, $halt_on_empty = true ) | 378 | function & get_by_ID( $req_ID, $halt_on_error = true, $halt_on_empty = true ) |
2787 | 399 | { | 379 | { |
2789 | 400 | global $DB, $Debuglog; | 380 | global $DB; |
2790 | 401 | 381 | ||
2792 | 402 | if( empty($req_ID) ) | 382 | if( empty( $req_ID ) ) |
2793 | 403 | { | 383 | { |
2795 | 404 | if($halt_on_empty) | 384 | if( $halt_on_empty ) |
2796 | 405 | { | 385 | { |
2797 | 406 | debug_die( "Requested $this->objtype from $this->dbtablename without ID!" ); | 386 | debug_die( "Requested $this->objtype from $this->dbtablename without ID!" ); |
2798 | 407 | } | 387 | } |
2799 | @@ -409,41 +389,37 @@ | |||
2800 | 409 | return $r; | 389 | return $r; |
2801 | 410 | } | 390 | } |
2802 | 411 | 391 | ||
2807 | 412 | if( !empty( $this->cache[ $req_ID ] ) ) | 392 | if( ! empty( $this->cache[$req_ID] ) ) |
2808 | 413 | { // Already in cache | 393 | { |
2809 | 414 | // $Debuglog->add( "Accessing $this->objtype($req_ID) from cache", 'dataobjects' ); | 394 | // Already in cache |
2810 | 415 | return $this->cache[ $req_ID ]; | 395 | return $this->cache[$req_ID]; |
2811 | 416 | } | 396 | } |
2814 | 417 | elseif( !$this->all_loaded ) | 397 | elseif( ! $this->all_loaded ) |
2815 | 418 | { // Not in cache, but not everything is loaded yet | 398 | { |
2816 | 399 | // Not in cache, but not everything is loaded yet | ||
2817 | 419 | if( $this->load_all ) | 400 | if( $this->load_all ) |
2819 | 420 | { // It's ok to just load everything: | 401 | { |
2820 | 402 | // It's ok to just load everything | ||
2821 | 421 | $this->load_all(); | 403 | $this->load_all(); |
2822 | 422 | } | 404 | } |
2823 | 423 | else | 405 | else |
2826 | 424 | { // Load just the requested object: | 406 | { |
2827 | 425 | $Debuglog->add( "Loading <strong>$this->objtype($req_ID)</strong> into cache", 'dataobjects' ); | 407 | // Load just the requested object |
2828 | 426 | // Note: $req_ID MUST be an unsigned integer. This is how DataObject works. | 408 | // Note: $req_ID MUST be an unsigned integer. This is how DataObject works. |
2832 | 427 | $sql = "SELECT * | 409 | $sql = "SELECT * FROM $this->dbtablename WHERE $this->dbIDname = $req_ID"; |
2830 | 428 | FROM $this->dbtablename | ||
2831 | 429 | WHERE $this->dbIDname = $req_ID"; | ||
2833 | 430 | if( $row = $DB->get_row( $sql, OBJECT, 0, 'DataObjectCache::get_by_ID()' ) ) | 410 | if( $row = $DB->get_row( $sql, OBJECT, 0, 'DataObjectCache::get_by_ID()' ) ) |
2834 | 431 | { | 411 | { |
2835 | 432 | if( ! $this->instantiate( $row ) ) | 412 | if( ! $this->instantiate( $row ) ) |
2836 | 433 | { | 413 | { |
2838 | 434 | $Debuglog->add( 'Could not add() object to cache!', 'dataobjects' ); | 414 | // debuglog-add removed |
2839 | 435 | } | 415 | } |
2840 | 436 | } | 416 | } |
2841 | 437 | else | ||
2842 | 438 | { | ||
2843 | 439 | $Debuglog->add( 'Could not get DataObject by ID. Query: '.$sql, 'dataobjects' ); | ||
2844 | 440 | } | ||
2845 | 441 | } | 417 | } |
2846 | 442 | } | 418 | } |
2847 | 443 | 419 | ||
2851 | 444 | if( empty( $this->cache[ $req_ID ] ) ) | 420 | if( empty( $this->cache[$req_ID] ) ) |
2852 | 445 | { // Requested object does not exist | 421 | { |
2853 | 446 | // $Debuglog->add( 'failure', 'dataobjects' ); | 422 | // Requested object does not exist |
2854 | 447 | if( $halt_on_error ) | 423 | if( $halt_on_error ) |
2855 | 448 | { | 424 | { |
2856 | 449 | debug_die( "Requested $this->objtype does not exist!" ); | 425 | debug_die( "Requested $this->objtype does not exist!" ); |
2857 | @@ -452,7 +428,7 @@ | |||
2858 | 452 | return $r; | 428 | return $r; |
2859 | 453 | } | 429 | } |
2860 | 454 | 430 | ||
2862 | 455 | return $this->cache[ $req_ID ]; | 431 | return $this->cache[$req_ID]; |
2863 | 456 | } | 432 | } |
2864 | 457 | 433 | ||
2865 | 458 | 434 | ||
2866 | @@ -468,45 +444,30 @@ | |||
2867 | 468 | */ | 444 | */ |
2868 | 469 | function & get_by_name( $req_name, $halt_on_error = true, $halt_on_empty = true ) | 445 | function & get_by_name( $req_name, $halt_on_error = true, $halt_on_empty = true ) |
2869 | 470 | { | 446 | { |
2871 | 471 | global $DB, $Debuglog; | 447 | global $DB; |
2872 | 472 | 448 | ||
2873 | 473 | if( empty( $this->name_field ) ) | 449 | if( empty( $this->name_field ) ) |
2874 | 474 | { | 450 | { |
2875 | 475 | debug_die( 'DataObjectCache::get_by_name() : No name field to query on' ); | 451 | debug_die( 'DataObjectCache::get_by_name() : No name field to query on' ); |
2876 | 476 | } | 452 | } |
2877 | 477 | 453 | ||
2879 | 478 | if( empty($req_name) ) | 454 | if( empty( $req_name ) ) |
2880 | 479 | { | 455 | { |
2882 | 480 | if($halt_on_empty) { debug_die( "Requested $this->objtype from $this->dbtablename without name!" ); } | 456 | if( $halt_on_empty ) { debug_die( "Requested $this->objtype from $this->dbtablename without name!" ); } |
2883 | 481 | $r = NULL; | 457 | $r = NULL; |
2884 | 482 | return $r; | 458 | return $r; |
2885 | 483 | } | 459 | } |
2886 | 484 | 460 | ||
2892 | 485 | // Load just the requested object: | 461 | // Load just the requested object |
2893 | 486 | $Debuglog->add( "Loading <strong>$this->objtype($req_name)</strong>", 'dataobjects' ); | 462 | $sql = "SELECT * FROM $this->dbtablename WHERE $this->name_field = ".$DB->quote( $req_name ); |
2889 | 487 | $sql = "SELECT * | ||
2890 | 488 | FROM $this->dbtablename | ||
2891 | 489 | WHERE $this->name_field = ".$DB->quote($req_name); | ||
2894 | 490 | 463 | ||
2895 | 491 | if( $db_row = $DB->get_row( $sql, OBJECT, 0, 'DataObjectCache::get_by_name()' ) ) | 464 | if( $db_row = $DB->get_row( $sql, OBJECT, 0, 'DataObjectCache::get_by_name()' ) ) |
2896 | 492 | { | 465 | { |
2897 | 493 | $resolved_ID = $db_row->{$this->dbIDname}; | 466 | $resolved_ID = $db_row->{$this->dbIDname}; |
2898 | 494 | $Debuglog->add( 'success; ID = '.$resolved_ID, 'dataobjects' ); | ||
2899 | 495 | if( ! isset( $this->cache[$resolved_ID] ) ) | ||
2900 | 496 | { // Object is not already in cache: | ||
2901 | 497 | $Debuglog->add( 'Adding to cache...', 'dataobjects' ); | ||
2902 | 498 | //$Obj = new $this->objtype( $row ); // COPY !! | ||
2903 | 499 | //if( ! $this->add( $this->new_obj( $db_row ) ) ) | ||
2904 | 500 | if( ! $this->add( $this->new_obj( $db_row ) ) ) | ||
2905 | 501 | { // could not add | ||
2906 | 502 | $Debuglog->add( 'Could not add() object to cache!', 'dataobjects' ); | ||
2907 | 503 | } | ||
2908 | 504 | } | ||
2909 | 505 | return $this->cache[$resolved_ID]; | 467 | return $this->cache[$resolved_ID]; |
2910 | 506 | } | 468 | } |
2911 | 507 | else | 469 | else |
2912 | 508 | { | 470 | { |
2913 | 509 | $Debuglog->add( 'Could not get DataObject by name.', 'dataobjects' ); | ||
2914 | 510 | if( $halt_on_error ) | 471 | if( $halt_on_error ) |
2915 | 511 | { | 472 | { |
2916 | 512 | debug_die( "Requested $this->objtype does not exist!" ); | 473 | debug_die( "Requested $this->objtype does not exist!" ); |
2917 | @@ -529,7 +490,7 @@ | |||
2918 | 529 | 490 | ||
2919 | 530 | 491 | ||
2920 | 531 | /** | 492 | /** |
2922 | 532 | * Delete an object from DB by ID. | 493 | * Delete an object from DB by ID |
2923 | 533 | * | 494 | * |
2924 | 534 | * @param integer ID of object to delete | 495 | * @param integer ID of object to delete |
2925 | 535 | * @return boolean | 496 | * @return boolean |
2926 | @@ -540,10 +501,8 @@ | |||
2927 | 540 | { | 501 | { |
2928 | 541 | // Delete from db | 502 | // Delete from db |
2929 | 542 | $this->cache[$req_ID]->dbdelete(); | 503 | $this->cache[$req_ID]->dbdelete(); |
2930 | 543 | |||
2931 | 544 | // Remove from cache | 504 | // Remove from cache |
2932 | 545 | $this->remove_by_ID( $req_ID ); | 505 | $this->remove_by_ID( $req_ID ); |
2933 | 546 | |||
2934 | 547 | return true; | 506 | return true; |
2935 | 548 | } | 507 | } |
2936 | 549 | else | 508 | else |
2937 | @@ -572,13 +531,16 @@ | |||
2938 | 572 | } | 531 | } |
2939 | 573 | 532 | ||
2940 | 574 | if( ! $this->all_loaded && $this->load_all ) | 533 | if( ! $this->all_loaded && $this->load_all ) |
2944 | 575 | { // We have not loaded all items so far, but we're allowed to. | 534 | { |
2945 | 576 | if ( empty( $ignore_IDs ) ) | 535 | // We have not loaded all items so far, but we're allowed to |
2946 | 577 | { // just load all items | 536 | if( empty( $ignore_IDs ) ) |
2947 | 537 | { | ||
2948 | 538 | // just load all items | ||
2949 | 578 | $this->load_all(); | 539 | $this->load_all(); |
2950 | 579 | } | 540 | } |
2951 | 580 | else | 541 | else |
2953 | 581 | { // only load those items not listed in $ignore_IDs | 542 | { |
2954 | 543 | // only load those items not listed in $ignore_IDs | ||
2955 | 582 | $this->load_list( implode( ',', $ignore_IDs ), true ); | 544 | $this->load_list( implode( ',', $ignore_IDs ), true ); |
2956 | 583 | } | 545 | } |
2957 | 584 | } | 546 | } |
2958 | @@ -588,22 +550,23 @@ | |||
2959 | 588 | if( $allow_none ) | 550 | if( $allow_none ) |
2960 | 589 | { | 551 | { |
2961 | 590 | $r .= '<option value="'.$this->none_option_value.'"'; | 552 | $r .= '<option value="'.$this->none_option_value.'"'; |
2964 | 591 | if( empty($default) ) $r .= ' selected="selected"'; | 553 | if( empty( $default ) ) $r .= ' selected="selected"'; |
2965 | 592 | $r .= '>'.format_to_output($this->none_option_text).'</option>'."\n"; | 554 | $r .= '>'.format_to_output( $this->none_option_text ).'</option>'."\n"; |
2966 | 593 | } | 555 | } |
2967 | 594 | 556 | ||
2968 | 595 | foreach( $this->cache as $loop_Obj ) | 557 | foreach( $this->cache as $loop_Obj ) |
2969 | 596 | { | 558 | { |
2972 | 597 | if ( in_array( $loop_Obj->ID, $ignore_IDs ) ) | 559 | if( in_array( $loop_Obj->ID, $ignore_IDs ) ) |
2973 | 598 | { // Ignore this ID | 560 | { |
2974 | 561 | // Ignore this ID | ||
2975 | 599 | continue; | 562 | continue; |
2976 | 600 | } | 563 | } |
2977 | 601 | 564 | ||
2979 | 602 | $r .= '<option value="'.$loop_Obj->ID.'"'; | 565 | $r .= '<option value="'.$loop_Obj->ID.'"'; |
2980 | 603 | if( in_array( $loop_Obj->ID, $default ) ) $r .= ' selected="selected"'; | 566 | if( in_array( $loop_Obj->ID, $default ) ) $r .= ' selected="selected"'; |
2981 | 604 | $r .= '>'; | 567 | $r .= '>'; |
2982 | 605 | $r .= format_to_output( $loop_Obj->$method(), 'htmlbody' ); | 568 | $r .= format_to_output( $loop_Obj->$method(), 'htmlbody' ); |
2984 | 606 | $r .= '</option>'."\n"; | 569 | $r .= '</option>'."\n"; |
2985 | 607 | } | 570 | } |
2986 | 608 | 571 | ||
2987 | 609 | return $r; | 572 | return $r; |
2988 | @@ -622,13 +585,16 @@ | |||
2989 | 622 | function get_option_array( $method = 'get_name', $ignore_IDs = array() ) | 585 | function get_option_array( $method = 'get_name', $ignore_IDs = array() ) |
2990 | 623 | { | 586 | { |
2991 | 624 | if( ! $this->all_loaded && $this->load_all ) | 587 | if( ! $this->all_loaded && $this->load_all ) |
2995 | 625 | { // We have not loaded all items so far, but we're allowed to. | 588 | { |
2996 | 626 | if ( empty( $ignore_IDs ) ) | 589 | // We have not loaded all items so far, but we're allowed to |
2997 | 627 | { // just load all items | 590 | if( empty( $ignore_IDs ) ) |
2998 | 591 | { | ||
2999 | 592 | // just load all items | ||
3000 | 628 | $this->load_all(); | 593 | $this->load_all(); |
3001 | 629 | } | 594 | } |
3002 | 630 | else | 595 | else |
3004 | 631 | { // only load those items not listed in $ignore_IDs | 596 | { |
3005 | 597 | // only load those items not listed in $ignore_IDs | ||
3006 | 632 | $this->load_list( implode( ',', $ignore_IDs ), true ); | 598 | $this->load_list( implode( ',', $ignore_IDs ), true ); |
3007 | 633 | } | 599 | } |
3008 | 634 | } | 600 | } |
3009 | @@ -638,7 +604,8 @@ | |||
3010 | 638 | foreach( $this->cache as $loop_Obj ) | 604 | foreach( $this->cache as $loop_Obj ) |
3011 | 639 | { | 605 | { |
3012 | 640 | if( in_array( $loop_Obj->ID, $ignore_IDs ) ) | 606 | if( in_array( $loop_Obj->ID, $ignore_IDs ) ) |
3014 | 641 | { // Ignore this ID | 607 | { |
3015 | 608 | // Ignore this ID | ||
3016 | 642 | continue; | 609 | continue; |
3017 | 643 | } | 610 | } |
3018 | 644 | 611 | ||
3019 | @@ -650,5 +617,4 @@ | |||
3020 | 650 | 617 | ||
3021 | 651 | } | 618 | } |
3022 | 652 | 619 | ||
3023 | 653 | |||
3024 | 654 | ?> | ||
3025 | 655 | \ No newline at end of file | 620 | \ No newline at end of file |
3026 | 621 | ?> | ||
3027 | 656 | 622 | ||
3028 | === modified file 'qp_inc/_core/model/dataobjects/_dataobjectlist.class.php' | |||
3029 | --- qp_inc/_core/model/dataobjects/_dataobjectlist.class.php 2010-12-31 12:12:03 +0000 | |||
3030 | +++ qp_inc/_core/model/dataobjects/_dataobjectlist.class.php 2013-03-20 18:13:29 +0000 | |||
3031 | @@ -1,66 +1,52 @@ | |||
3032 | 1 | <?php | 1 | <?php |
3033 | 2 | /** | 2 | /** |
3058 | 3 | * This file implements the abstract DataObjectList base class. | 3 | * This file implements the DataObjectList class |
3059 | 4 | * | 4 | * |
3060 | 5 | * This file is part of Quam Plures - {@link http://quamplures.net/} | 5 | * This is typically an abstract class, useful only when derived. Holds DataObjects |
3061 | 6 | * See also {@link https://launchpad.net/quam-plures}. | 6 | * in an array and allows walking through... |
3062 | 7 | * | 7 | * |
3063 | 8 | * @copyright (c) 2009 - 2011 by the Quam Plures developers - {@link http://quamplures.net/} | 8 | * @todo (1111) vars type 'foo' need useful/valid descriptions |
3064 | 9 | * @copyright (c)2003-2009 by Francois PLANQUE - {@link http://fplanque.net/} | 9 | * @author {@link http://wonderwinds.com/ Ed Bennett} |
3065 | 10 | * | 10 | * @author {@link http://fplanque.net/ Francois PLANQUE} |
3066 | 11 | * {@internal License choice | 11 | * @copyright (c) 2009 by {@link http://quamplures.net/ the Quam Plures project} |
3067 | 12 | * - If you have received this file as part of a package, please find the license.txt file in | 12 | * @license http://www.gnu.org/licenses/gpl.txt GNU General Public License v3 |
3068 | 13 | * the same folder or the closest folder above for complete license terms. | 13 | * @package core |
3045 | 14 | * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/) | ||
3046 | 15 | * then you must choose one of the following licenses before using the file: | ||
3047 | 16 | * - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php | ||
3048 | 17 | * - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php | ||
3049 | 18 | * }} | ||
3050 | 19 | * | ||
3051 | 20 | * {@internal Open Source relicensing agreement: | ||
3052 | 21 | * }} | ||
3053 | 22 | * | ||
3054 | 23 | * {@internal Below is a list of authors who have contributed to design/coding of this file: }} | ||
3055 | 24 | * @author fplanque: Francois PLANQUE | ||
3056 | 25 | * | ||
3057 | 26 | * @package pond | ||
3069 | 27 | */ | 14 | */ |
3073 | 28 | if( !defined('QP_MAIN_INIT') ) die( 'Please, do not access this page directly.' ); | 15 | if(!defined('QP_MAIN_INIT')) die('fail'); |
3071 | 29 | |||
3072 | 30 | load_class('_core/ui/results/_results.class.php'); | ||
3074 | 31 | 16 | ||
3075 | 32 | /** | 17 | /** |
3085 | 33 | * Data Object List Base Class | 18 | * DataObjectList class |
3086 | 34 | * | 19 | * |
3087 | 35 | * This is typically an abstract class, useful only when derived. | 20 | * @package core |
3079 | 36 | * Holds DataObjects in an array and allows walking through... | ||
3080 | 37 | * | ||
3081 | 38 | * @version beta | ||
3082 | 39 | * @abstract | ||
3083 | 40 | * | ||
3084 | 41 | * @package pond | ||
3088 | 42 | */ | 21 | */ |
3089 | 43 | class DataObjectList extends Results | 22 | class DataObjectList extends Results |
3090 | 44 | { | 23 | { |
3091 | 45 | |||
3092 | 46 | /** | 24 | /** |
3093 | 47 | * The following should probably be obsoleted by Results::Cache | 25 | * The following should probably be obsoleted by Results::Cache |
3096 | 48 | */ | 26 | * @var foo |
3097 | 49 | var $dbtablename; | 27 | */ |
3098 | 28 | var $dbtablename; | ||
3099 | 29 | /** | ||
3100 | 30 | * FIX THIS | ||
3101 | 31 | * @var foo | ||
3102 | 32 | */ | ||
3103 | 50 | var $dbprefix; | 33 | var $dbprefix; |
3104 | 34 | /** | ||
3105 | 35 | * FIX THIS | ||
3106 | 36 | * @var foo | ||
3107 | 37 | */ | ||
3108 | 51 | var $dbIDname; | 38 | var $dbIDname; |
3109 | 52 | |||
3110 | 53 | /** | 39 | /** |
3111 | 54 | * Class name of objects handled in this list | 40 | * Class name of objects handled in this list |
3112 | 41 | * @var foo | ||
3113 | 55 | */ | 42 | */ |
3114 | 56 | var $objType; | 43 | var $objType; |
3115 | 57 | |||
3116 | 58 | /** | 44 | /** |
3117 | 59 | * Object array | 45 | * Object array |
3118 | 46 | * @var foo | ||
3119 | 60 | */ | 47 | */ |
3120 | 61 | var $Obj = array(); | 48 | var $Obj = array(); |
3121 | 62 | 49 | ||
3122 | 63 | |||
3123 | 64 | /** | 50 | /** |
3124 | 65 | * Constructor | 51 | * Constructor |
3125 | 66 | * | 52 | * |
3126 | @@ -75,8 +61,14 @@ | |||
3127 | 75 | * @param string prefix to differentiate page/order params when multiple Results appear one same page | 61 | * @param string prefix to differentiate page/order params when multiple Results appear one same page |
3128 | 76 | * @param string default ordering of columns (special syntax) | 62 | * @param string default ordering of columns (special syntax) |
3129 | 77 | */ | 63 | */ |
3132 | 78 | function DataObjectList( $tablename, $prefix = '', $dbIDname = 'ID', $objType = 'Item', $sql = NULL, | 64 | function DataObjectList( |
3133 | 79 | $limit = 20, $param_prefix = '', $default_order = NULL ) | 65 | $tablename, $prefix = '', |
3134 | 66 | $dbIDname = 'ID', | ||
3135 | 67 | $objType = 'Item', | ||
3136 | 68 | $sql = NULL, | ||
3137 | 69 | $limit = 20, | ||
3138 | 70 | $param_prefix = '', | ||
3139 | 71 | $default_order = NULL ) | ||
3140 | 80 | { | 72 | { |
3141 | 81 | $this->dbtablename = $tablename; | 73 | $this->dbtablename = $tablename; |
3142 | 82 | $this->dbprefix = $prefix; | 74 | $this->dbprefix = $prefix; |
3143 | @@ -84,12 +76,14 @@ | |||
3144 | 84 | $this->objType = $objType; | 76 | $this->objType = $objType; |
3145 | 85 | 77 | ||
3146 | 86 | if( !is_null( $sql ) ) | 78 | if( !is_null( $sql ) ) |
3148 | 87 | { // We have an SQL query to execute: | 79 | { |
3149 | 80 | // We have an SQL query to execute | ||
3150 | 88 | parent::Results( $sql, $param_prefix, $default_order, $limit ); | 81 | parent::Results( $sql, $param_prefix, $default_order, $limit ); |
3151 | 89 | } | 82 | } |
3152 | 90 | else | 83 | else |
3154 | 91 | { // TODO: do we want to autogenerate a query here??? | 84 | { |
3155 | 92 | // Temporary... | 85 | // Temporary... |
3156 | 86 | // @todo (0000) do we want to autogenerate a query here??? | ||
3157 | 93 | parent::Results( $sql, $param_prefix, $default_order, $limit ); | 87 | parent::Results( $sql, $param_prefix, $default_order, $limit ); |
3158 | 94 | } | 88 | } |
3159 | 95 | } | 89 | } |
3160 | @@ -103,7 +97,8 @@ | |||
3161 | 103 | function & get_next() | 97 | function & get_next() |
3162 | 104 | { | 98 | { |
3163 | 105 | if( $this->current_idx >= $this->result_num_rows ) | 99 | if( $this->current_idx >= $this->result_num_rows ) |
3165 | 106 | { // No more comment in list | 100 | { |
3166 | 101 | // No more comment in list | ||
3167 | 107 | $r = false; | 102 | $r = false; |
3168 | 108 | return $r; | 103 | return $r; |
3169 | 109 | } | 104 | } |
3170 | @@ -112,4 +107,4 @@ | |||
3171 | 112 | 107 | ||
3172 | 113 | } | 108 | } |
3173 | 114 | 109 | ||
3174 | 115 | ?> | ||
3175 | 116 | \ No newline at end of file | 110 | \ No newline at end of file |
3176 | 111 | ?> | ||
3177 | 117 | 112 | ||
3178 | === modified file 'qp_inc/_core/model/dataobjects/_dataobjectlist2.class.php' | |||
3179 | --- qp_inc/_core/model/dataobjects/_dataobjectlist2.class.php 2010-12-31 12:12:03 +0000 | |||
3180 | +++ qp_inc/_core/model/dataobjects/_dataobjectlist2.class.php 2013-03-20 18:13:29 +0000 | |||
3181 | @@ -1,53 +1,34 @@ | |||
3182 | 1 | <?php | 1 | <?php |
3183 | 2 | /** | 2 | /** |
3208 | 3 | * This file implements the abstract DataObjectList2 base class. | 3 | * This file implements the abstract FilteredResults class |
3209 | 4 | * | 4 | * |
3210 | 5 | * This file is part of Quam Plures - {@link http://quamplures.net/} | 5 | * @todo (1111) vars type 'foo' need useful/valid descriptions |
3211 | 6 | * See also {@link https://launchpad.net/quam-plures}. | 6 | * @author {@link http://wonderwinds.com/ Ed Bennett} |
3212 | 7 | * | 7 | * @author {@link http://fplanque.net/ Francois PLANQUE} |
3213 | 8 | * @copyright (c) 2009 - 2011 by the Quam Plures developers - {@link http://quamplures.net/} | 8 | * @copyright (c) 2009 by {@link http://quamplures.net/ the Quam Plures project} |
3214 | 9 | * @copyright (c)2003-2009 by Francois PLANQUE - {@link http://fplanque.net/} | 9 | * @license http://www.gnu.org/licenses/gpl.txt GNU General Public License v3 |
3215 | 10 | * | 10 | * @package core |
3192 | 11 | * {@internal License choice | ||
3193 | 12 | * - If you have received this file as part of a package, please find the license.txt file in | ||
3194 | 13 | * the same folder or the closest folder above for complete license terms. | ||
3195 | 14 | * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/) | ||
3196 | 15 | * then you must choose one of the following licenses before using the file: | ||
3197 | 16 | * - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php | ||
3198 | 17 | * - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php | ||
3199 | 18 | * }} | ||
3200 | 19 | * | ||
3201 | 20 | * {@internal Open Source relicensing agreement: | ||
3202 | 21 | * }} | ||
3203 | 22 | * | ||
3204 | 23 | * {@internal Below is a list of authors who have contributed to design/coding of this file: }} | ||
3205 | 24 | * @author fplanque: Francois PLANQUE | ||
3206 | 25 | * | ||
3207 | 26 | * @package pond | ||
3216 | 27 | */ | 11 | */ |
3221 | 28 | if( !defined('QP_MAIN_INIT') ) die( 'Please, do not access this page directly.' ); | 12 | if(!defined('QP_MAIN_INIT')) die('fail'); |
3218 | 29 | |||
3219 | 30 | load_class('_core/ui/results/_results.class.php'); | ||
3220 | 31 | |||
3222 | 32 | 13 | ||
3223 | 33 | /** | 14 | /** |
3225 | 34 | * FilteredResults > Results | 15 | * FilteredResults class |
3226 | 35 | * | 16 | * |
3228 | 36 | * @package pond | 17 | * @package core |
3229 | 37 | */ | 18 | */ |
3230 | 38 | class FilteredResults extends Results | 19 | class FilteredResults extends Results |
3231 | 39 | { | 20 | { |
3232 | 40 | /** | 21 | /** |
3233 | 41 | * Default filter set (used if no specific params are passed) | 22 | * Default filter set (used if no specific params are passed) |
3234 | 23 | * @var foo | ||
3235 | 42 | */ | 24 | */ |
3236 | 43 | var $default_filters = array(); | 25 | var $default_filters = array(); |
3237 | 44 | |||
3238 | 45 | /** | 26 | /** |
3239 | 46 | * Current filter set (depending on user input) | 27 | * Current filter set (depending on user input) |
3240 | 28 | * @var foo | ||
3241 | 47 | */ | 29 | */ |
3242 | 48 | var $filters = array(); | 30 | var $filters = array(); |
3243 | 49 | 31 | ||
3244 | 50 | |||
3245 | 51 | /** | 32 | /** |
3246 | 52 | * Check if the Result set is filtered or not | 33 | * Check if the Result set is filtered or not |
3247 | 53 | */ | 34 | */ |
3248 | @@ -57,7 +38,6 @@ | |||
3249 | 57 | { | 38 | { |
3250 | 58 | return false; | 39 | return false; |
3251 | 59 | } | 40 | } |
3252 | 60 | |||
3253 | 61 | return ( $this->filters != $this->default_filters ); | 41 | return ( $this->filters != $this->default_filters ); |
3254 | 62 | } | 42 | } |
3255 | 63 | 43 | ||
3256 | @@ -67,7 +47,7 @@ | |||
3257 | 67 | */ | 47 | */ |
3258 | 68 | function get_active_filter( $key ) | 48 | function get_active_filter( $key ) |
3259 | 69 | { | 49 | { |
3261 | 70 | if( isset($this->filters[$key]) ) | 50 | if( isset( $this->filters[$key] ) ) |
3262 | 71 | { | 51 | { |
3263 | 72 | return $this->filters[$key]; | 52 | return $this->filters[$key]; |
3264 | 73 | } | 53 | } |
3265 | @@ -76,7 +56,7 @@ | |||
3266 | 76 | } | 56 | } |
3267 | 77 | 57 | ||
3268 | 78 | 58 | ||
3270 | 79 | /** | 59 | /** |
3271 | 80 | * Get every active filter that is not the same as the defaults | 60 | * Get every active filter that is not the same as the defaults |
3272 | 81 | */ | 61 | */ |
3273 | 82 | function get_active_filters() | 62 | function get_active_filters() |
3274 | @@ -85,10 +65,12 @@ | |||
3275 | 85 | 65 | ||
3276 | 86 | foreach( $this->default_filters as $key => $value ) | 66 | foreach( $this->default_filters as $key => $value ) |
3277 | 87 | { | 67 | { |
3282 | 88 | if( !isset( $this->filters[$key] ) ) | 68 | if( ! isset( $this->filters[$key] ) ) |
3283 | 89 | { // Some value has not been copied over from defaults to active or specifically set: | 69 | { |
3284 | 90 | if( !is_null($value)) // Note: NULL value are not copied over. that's normal. | 70 | // Some value has not been copied over from defaults to active or specifically set: |
3285 | 91 | { // A NON NULL value is missing | 71 | if( ! is_null( $value ) ) // Note: NULL value are not copied over. that's normal. |
3286 | 72 | { | ||
3287 | 73 | // A NON NULL value is missing | ||
3288 | 92 | $r[] = $key; | 74 | $r[] = $key; |
3289 | 93 | } | 75 | } |
3290 | 94 | } | 76 | } |
3291 | @@ -101,17 +83,19 @@ | |||
3292 | 101 | } | 83 | } |
3293 | 102 | 84 | ||
3294 | 103 | 85 | ||
3296 | 104 | /** | 86 | /** |
3297 | 105 | * Show every active filter that is not the same as the defaults | 87 | * Show every active filter that is not the same as the defaults |
3298 | 106 | */ | 88 | */ |
3299 | 107 | function dump_active_filters() | 89 | function dump_active_filters() |
3300 | 108 | { | 90 | { |
3301 | 109 | foreach( $this->default_filters as $key => $value ) | 91 | foreach( $this->default_filters as $key => $value ) |
3302 | 110 | { | 92 | { |
3307 | 111 | if( !isset( $this->filters[$key] ) ) | 93 | if( ! isset( $this->filters[$key] ) ) |
3308 | 112 | { // SOme value has not been copied over from defaults to active or specifically set: | 94 | { |
3309 | 113 | if( !is_null($value)) // Note: NULL value ar enot copied over. that's normal. | 95 | // Some value has not been copied over from defaults to active or specifically set |
3310 | 114 | { // A NON NULL value is missing | 96 | if( ! is_null( $value ) ) // Note: NULL value are not copied over. that's normal. |
3311 | 97 | { | ||
3312 | 98 | // A NON NULL value is missing | ||
3313 | 115 | pre_dump( 'no active value for default '.$key ); | 99 | pre_dump( 'no active value for default '.$key ); |
3314 | 116 | } | 100 | } |
3315 | 117 | } | 101 | } |
3316 | @@ -125,60 +109,51 @@ | |||
3317 | 125 | } | 109 | } |
3318 | 126 | 110 | ||
3319 | 127 | 111 | ||
3320 | 128 | |||
3321 | 129 | /** | 112 | /** |
3322 | 130 | * Data Object List Base Class 2 | 113 | * Data Object List Base Class 2 |
3323 | 131 | * | 114 | * |
3333 | 132 | * This is typically an abstract class, useful only when derived. | 115 | * This is typically an abstract class, useful only when derived. Holds DataObjects |
3334 | 133 | * Holds DataObjects in an array and allows walking through... | 116 | * in an array and allows walking through... This SECOND implementation will deprecate |
3335 | 134 | * | 117 | * the first one when finished. |
3336 | 135 | * This SECOND implementation will deprecate the first one when finished. | 118 | * |
3337 | 136 | * | 119 | * @package core |
3329 | 137 | * @version beta | ||
3330 | 138 | * @abstract | ||
3331 | 139 | * | ||
3332 | 140 | * @package pond | ||
3338 | 141 | */ | 120 | */ |
3339 | 142 | class DataObjectList2 extends FilteredResults | 121 | class DataObjectList2 extends FilteredResults |
3340 | 143 | { | 122 | { |
3341 | 144 | |||
3342 | 145 | |||
3343 | 146 | /** | 123 | /** |
3344 | 147 | * Constructor | 124 | * Constructor |
3345 | 148 | * | 125 | * |
3346 | 149 | * If provided, executes SQL query via parent Results object | 126 | * If provided, executes SQL query via parent Results object |
3347 | 150 | * | 127 | * |
3348 | 151 | * @param DataObjectCache | 128 | * @param DataObjectCache |
3350 | 152 | * @param integer number of lines displayed on one screen (null for default [20]) | 129 | * @param integer number of lines displayed on one screen (null for default [20] ) |
3351 | 153 | * @param string prefix to differentiate page/order params when multiple Results appear one same page | 130 | * @param string prefix to differentiate page/order params when multiple Results appear one same page |
3352 | 154 | * @param string default ordering of columns (special syntax) | 131 | * @param string default ordering of columns (special syntax) |
3353 | 155 | */ | 132 | */ |
3354 | 156 | function DataObjectList2( & $Cache, $limit = null, $param_prefix = '', $default_order = NULL ) | 133 | function DataObjectList2( & $Cache, $limit = null, $param_prefix = '', $default_order = NULL ) |
3355 | 157 | { | 134 | { |
3356 | 158 | // WARNING: we are not passing any SQL query to the Results object | 135 | // WARNING: we are not passing any SQL query to the Results object |
3358 | 159 | // This will make the Results object behave a little bit differently than usual: | 136 | // This will make the Results object behave a little bit differently than usual |
3359 | 160 | parent::Results( NULL, $param_prefix, $default_order, $limit, NULL, false ); | 137 | parent::Results( NULL, $param_prefix, $default_order, $limit, NULL, false ); |
3360 | 161 | |||
3361 | 162 | // The list objects will also be cached in this cache. | 138 | // The list objects will also be cached in this cache. |
3363 | 163 | // Tje Cache object may also be useful to get table information for the Items. | 139 | // The Cache object may also be useful to get table information for the Items |
3364 | 164 | $this->Cache = & $Cache; | 140 | $this->Cache = & $Cache; |
3365 | 165 | |||
3366 | 166 | // Colum used for IDs | 141 | // Colum used for IDs |
3367 | 167 | $this->ID_col = $Cache->dbIDname; | 142 | $this->ID_col = $Cache->dbIDname; |
3368 | 168 | } | 143 | } |
3369 | 169 | 144 | ||
3370 | 170 | 145 | ||
3374 | 171 | /** | 146 | /** |
3375 | 172 | * dummy docblock makes error-free autodocs | 147 | * dummy docblock |
3376 | 173 | */ | 148 | */ |
3377 | 174 | function & get_row_by_idx( $idx ) | 149 | function & get_row_by_idx( $idx ) |
3378 | 175 | { | 150 | { |
3380 | 176 | return $this->rows[ $idx ]; | 151 | return $this->rows[$idx]; |
3381 | 177 | } | 152 | } |
3382 | 178 | 153 | ||
3383 | 179 | 154 | ||
3384 | 180 | /** | 155 | /** |
3386 | 181 | * Instantiate an object for requested row and cache it: | 156 | * Instantiate an object for requested row and cache it |
3387 | 182 | */ | 157 | */ |
3388 | 183 | function & get_by_idx( $idx ) | 158 | function & get_by_idx( $idx ) |
3389 | 184 | { | 159 | { |
3390 | @@ -192,13 +167,14 @@ | |||
3391 | 192 | function & get_next() | 167 | function & get_next() |
3392 | 193 | { | 168 | { |
3393 | 194 | if( $this->current_idx >= $this->result_num_rows ) | 169 | if( $this->current_idx >= $this->result_num_rows ) |
3395 | 195 | { // No more object in list | 170 | { |
3396 | 171 | // No more object in list | ||
3397 | 196 | $this->current_Obj = NULL; | 172 | $this->current_Obj = NULL; |
3399 | 197 | $r = false; // TODO: try with NULL | 173 | $r = false; |
3400 | 198 | return $r; | 174 | return $r; |
3401 | 199 | } | 175 | } |
3402 | 200 | 176 | ||
3404 | 201 | // We also keep a local ref in case we want to use it for display: | 177 | // We also keep a local ref in case we want to use it for display |
3405 | 202 | $this->current_Obj = & $this->get_by_idx( $this->current_idx ); | 178 | $this->current_Obj = & $this->get_by_idx( $this->current_idx ); |
3406 | 203 | $this->next_idx(); | 179 | $this->next_idx(); |
3407 | 204 | 180 | ||
3408 | @@ -210,7 +186,6 @@ | |||
3409 | 210 | * Display a global title matching filter params | 186 | * Display a global title matching filter params |
3410 | 211 | * | 187 | * |
3411 | 212 | * @todo implement $order | 188 | * @todo implement $order |
3412 | 213 | * | ||
3413 | 214 | * @param string prefix to display if a title is generated | 189 | * @param string prefix to display if a title is generated |
3414 | 215 | * @param string suffix to display if a title is generated | 190 | * @param string suffix to display if a title is generated |
3415 | 216 | * @param string glue to use if multiple title elements are generated | 191 | * @param string glue to use if multiple title elements are generated |
3416 | @@ -221,12 +196,12 @@ | |||
3417 | 221 | { | 196 | { |
3418 | 222 | $title_array = $this->get_filter_titles(); | 197 | $title_array = $this->get_filter_titles(); |
3419 | 223 | 198 | ||
3422 | 224 | if( empty( $title_array ) ) | 199 | if( empty( $title_array ) ) |
3423 | 225 | { | 200 | { |
3424 | 226 | return ''; | 201 | return ''; |
3425 | 227 | } | 202 | } |
3426 | 228 | 203 | ||
3428 | 229 | // We have something to display: | 204 | // We have something to display |
3429 | 230 | $r = implode( $glue, $title_array ); | 205 | $r = implode( $glue, $title_array ); |
3430 | 231 | $r = $prefix.format_to_output( $r, $format ).$suffix; | 206 | $r = $prefix.format_to_output( $r, $format ).$suffix; |
3431 | 232 | return $r; | 207 | return $r; |
3432 | @@ -245,7 +220,7 @@ | |||
3433 | 245 | 220 | ||
3434 | 246 | $DB->begin(); | 221 | $DB->begin(); |
3435 | 247 | 222 | ||
3437 | 248 | if( ($obj = & $this->Cache->get_by_ID( $id )) === false ) | 223 | if( ( $obj = & $this->Cache->get_by_ID( $id ) ) === false ) |
3438 | 249 | { | 224 | { |
3439 | 250 | $Messages->head = T_('Cannot edit entry!'); | 225 | $Messages->head = T_('Cannot edit entry!'); |
3440 | 251 | $Messages->add( T_('Requested entry does not exist any longer.'), 'error' ); | 226 | $Messages->add( T_('Requested entry does not exist any longer.'), 'error' ); |
3441 | @@ -256,24 +231,21 @@ | |||
3442 | 256 | 231 | ||
3443 | 257 | // Get the ID of the inferior element which his order is the nearest | 232 | // Get the ID of the inferior element which his order is the nearest |
3444 | 258 | $rows = $DB->get_results( 'SELECT '.$this->Cache->dbIDname | 233 | $rows = $DB->get_results( 'SELECT '.$this->Cache->dbIDname |
3449 | 259 | .' FROM '.$this->Cache->dbtablename | 234 | .' FROM '.$this->Cache->dbtablename |
3450 | 260 | .' WHERE '.$this->Cache->dbprefix.'order < '.$order | 235 | .' WHERE '.$this->Cache->dbprefix.'order < '.$order |
3451 | 261 | .' ORDER BY '.$this->Cache->dbprefix.'order DESC | 236 | .' ORDER BY '.$this->Cache->dbprefix.'order DESC |
3452 | 262 | LIMIT 0,1' ); | 237 | LIMIT 0, 1' ); |
3453 | 263 | 238 | ||
3454 | 264 | if( count( $rows ) ) | 239 | if( count( $rows ) ) |
3455 | 265 | { | 240 | { |
3456 | 266 | // instantiate the inferior element | 241 | // instantiate the inferior element |
3457 | 267 | $obj_inf = & $this->Cache->get_by_ID( $rows[0]->{$this->Cache->dbIDname} ); | 242 | $obj_inf = & $this->Cache->get_by_ID( $rows[0]->{$this->Cache->dbIDname} ); |
3460 | 268 | 243 | // Update element order | |
3459 | 269 | // Update element order | ||
3461 | 270 | $obj->set( 'order', $obj_inf->order ); | 244 | $obj->set( 'order', $obj_inf->order ); |
3462 | 271 | $obj->dbupdate(); | 245 | $obj->dbupdate(); |
3463 | 272 | |||
3464 | 273 | // Update inferior element order | 246 | // Update inferior element order |
3465 | 274 | $obj_inf->set( 'order', $order ); | 247 | $obj_inf->set( 'order', $order ); |
3466 | 275 | $obj_inf->dbupdate(); | 248 | $obj_inf->dbupdate(); |
3467 | 276 | |||
3468 | 277 | // EXPERIMENTAL FOR FADEOUT RESULT | 249 | // EXPERIMENTAL FOR FADEOUT RESULT |
3469 | 278 | $result_fadeout[$this->Cache->dbIDname][] = $id; | 250 | $result_fadeout[$this->Cache->dbIDname][] = $id; |
3470 | 279 | $result_fadeout[$this->Cache->dbIDname][] = $obj_inf->ID; | 251 | $result_fadeout[$this->Cache->dbIDname][] = $obj_inf->ID; |
3471 | @@ -294,11 +266,13 @@ | |||
3472 | 294 | */ | 266 | */ |
3473 | 295 | function move_down( $id ) | 267 | function move_down( $id ) |
3474 | 296 | { | 268 | { |
3476 | 297 | global $DB, $Messages, $result_fadeout; | 269 | global $DB; |
3477 | 270 | global $Messages; | ||
3478 | 271 | global $result_fadeout; | ||
3479 | 298 | 272 | ||
3480 | 299 | $DB->begin(); | 273 | $DB->begin(); |
3481 | 300 | 274 | ||
3483 | 301 | if( ($obj = & $this->Cache->get_by_ID( $id )) === false ) | 275 | if( ( $obj = & $this->Cache->get_by_ID( $id ) ) === false ) |
3484 | 302 | { | 276 | { |
3485 | 303 | $Messages->head = T_('Cannot edit entry!'); | 277 | $Messages->head = T_('Cannot edit entry!'); |
3486 | 304 | $Messages->add( T_('Requested entry does not exist any longer.'), 'error' ); | 278 | $Messages->add( T_('Requested entry does not exist any longer.'), 'error' ); |
3487 | @@ -309,24 +283,21 @@ | |||
3488 | 309 | 283 | ||
3489 | 310 | // Get the ID of the inferior element which his order is the nearest | 284 | // Get the ID of the inferior element which his order is the nearest |
3490 | 311 | $rows = $DB->get_results( 'SELECT '.$this->Cache->dbIDname | 285 | $rows = $DB->get_results( 'SELECT '.$this->Cache->dbIDname |
3495 | 312 | .' FROM '.$this->Cache->dbtablename | 286 | .' FROM '.$this->Cache->dbtablename |
3496 | 313 | .' WHERE '.$this->Cache->dbprefix.'order > '.$order | 287 | .' WHERE '.$this->Cache->dbprefix.'order > '.$order |
3497 | 314 | .' ORDER BY '.$this->Cache->dbprefix.'order ASC | 288 | .' ORDER BY '.$this->Cache->dbprefix.'order ASC |
3498 | 315 | LIMIT 0,1' ); | 289 | LIMIT 0, 1' ); |
3499 | 316 | 290 | ||
3500 | 317 | if( count( $rows ) ) | 291 | if( count( $rows ) ) |
3501 | 318 | { | 292 | { |
3502 | 319 | // instantiate the inferior element | 293 | // instantiate the inferior element |
3503 | 320 | $obj_sup = & $this->Cache->get_by_ID( $rows[0]->{$this->Cache->dbIDname} ); | 294 | $obj_sup = & $this->Cache->get_by_ID( $rows[0]->{$this->Cache->dbIDname} ); |
3506 | 321 | 295 | // Update element order | |
3505 | 322 | // Update element order | ||
3507 | 323 | $obj->set( 'order', $obj_sup->order ); | 296 | $obj->set( 'order', $obj_sup->order ); |
3508 | 324 | $obj->dbupdate(); | 297 | $obj->dbupdate(); |
3509 | 325 | |||
3510 | 326 | // Update inferior element order | 298 | // Update inferior element order |
3511 | 327 | $obj_sup->set( 'order', $order ); | 299 | $obj_sup->set( 'order', $order ); |
3512 | 328 | $obj_sup->dbupdate(); | 300 | $obj_sup->dbupdate(); |
3513 | 329 | |||
3514 | 330 | // EXPERIMENTAL FOR FADEOUT RESULT | 301 | // EXPERIMENTAL FOR FADEOUT RESULT |
3515 | 331 | $result_fadeout[$this->Cache->dbIDname][] = $id; | 302 | $result_fadeout[$this->Cache->dbIDname][] = $id; |
3516 | 332 | $result_fadeout[$this->Cache->dbIDname][] = $obj_sup->ID; | 303 | $result_fadeout[$this->Cache->dbIDname][] = $obj_sup->ID; |
3517 | @@ -339,4 +310,4 @@ | |||
3518 | 339 | } | 310 | } |
3519 | 340 | } | 311 | } |
3520 | 341 | 312 | ||
3521 | 342 | ?> | ||
3522 | 343 | \ No newline at end of file | 313 | \ No newline at end of file |
3523 | 314 | ?> | ||
3524 | 344 | 315 | ||
3525 | === modified file 'qp_inc/_core/model/db/_db.class.php' | |||
3526 | --- qp_inc/_core/model/db/_db.class.php 2010-12-31 12:12:03 +0000 | |||
3527 | +++ qp_inc/_core/model/db/_db.class.php 2013-03-20 18:13:29 +0000 | |||
3528 | @@ -1,80 +1,55 @@ | |||
3529 | 1 | <?php | 1 | <?php |
3530 | 2 | /** | 2 | /** |
3561 | 3 | * This file implements the DB class. | 3 | * This file implements the DB base class |
3562 | 4 | * | 4 | * |
3533 | 5 | * Based on ezSQL - Class to make it very easy to deal with MySQL database connections. | ||
3534 | 6 | * b2evo Additions: | ||
3535 | 7 | * - nested transactions | ||
3536 | 8 | * - symbolic table names | ||
3537 | 9 | * - query log | ||
3538 | 10 | * - get_list | ||
3539 | 11 | * - dynamic extension loading | ||
3540 | 12 | * - Debug features (EXPLAIN...) | ||
3541 | 13 | * and more... | ||
3542 | 14 | * | ||
3543 | 15 | * This file is part of the Quam Plures project - {@link http://quamplures.net/}. | ||
3544 | 16 | * See also {@link https://launchpad.net/quam-plures}. | ||
3545 | 17 | * | ||
3546 | 18 | * @copyright (c) 2009 - 2011 by the Quam Plures developers - {@link http://quamplures.net/} | ||
3547 | 19 | * @copyright (c)2003-2009 by Francois PLANQUE - {@link http://fplanque.net/}. | ||
3548 | 20 | * Parts of this file are copyright (c)2004 by Justin Vincent - {@link http://php.justinvincent.com} | ||
3549 | 21 | * Parts of this file are copyright (c)2004-2005 by Daniel HAHLER - {@link http://thequod.de/contact}. | ||
3550 | 22 | * | ||
3551 | 23 | * {@internal License choice | ||
3552 | 24 | * - If you have received this file as part of a package, please find the license.txt file in | ||
3553 | 25 | * the same folder or the closest folder above for complete license terms. | ||
3554 | 26 | * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/) | ||
3555 | 27 | * then you must choose one of the following licenses before using the file: | ||
3556 | 28 | * - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php | ||
3557 | 29 | * - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php | ||
3558 | 30 | * }} | ||
3559 | 31 | * | ||
3560 | 32 | * {@internal Origin: | ||
3563 | 33 | * This file is based on the following package (excerpt from ezSQL's readme.txt): | 5 | * This file is based on the following package (excerpt from ezSQL's readme.txt): |
3564 | 34 | * ======================================================================= | 6 | * ======================================================================= |
3569 | 35 | * Author: Justin Vincent (justin@visunet.ie) | 7 | * Author: Justin Vincent (justin@visunet.ie) |
3570 | 36 | * Web: http://php.justinvincent.com | 8 | * Web: http://php.justinvincent.com |
3571 | 37 | * Name: ezSQL | 9 | * Name: ezSQL |
3572 | 38 | * Desc: Class to make it very easy to deal with database connections. | 10 | * Desc: Class to make it very easy to deal with database connections. |
3573 | 39 | * License: FREE / Donation (LGPL - You may do what you like with ezSQL - no exceptions.) | 11 | * License: FREE / Donation (LGPL - You may do what you like with ezSQL - no exceptions.) |
3574 | 40 | * ======================================================================= | 12 | * ======================================================================= |
3575 | 41 | * A $10 donation has been made to Justin VINCENT on behalf of the b2evolution team. | 13 | * A $10 donation has been made to Justin VINCENT on behalf of the b2evolution team. |
3576 | 42 | * The package has been relicensed as GPL based on | 14 | * The package has been relicensed as GPL based on |
3577 | 43 | * "You may do what you like with ezSQL - no exceptions." | 15 | * "You may do what you like with ezSQL - no exceptions." |
3578 | 44 | * 2004-10-14 (email): Justin VINCENT grants Francois PLANQUE the right to relicense | 16 | * 2004-10-14 (email): Justin VINCENT grants Francois PLANQUE the right to relicense |
3596 | 45 | * this modified class under other licenses. "Just include a link to where you got it from." | 17 | * this modified class under other licenses. "Just include a link to where you got |
3597 | 46 | * }} | 18 | * it from." |
3598 | 47 | * | 19 | * |
3599 | 48 | * {@internal Open Source relicensing agreement: | 20 | * @todo (1111) vars type 'foo' need useful/valid descriptions |
3600 | 49 | * Daniel HAHLER grants Francois PLANQUE the right to license | 21 | * @todo (0000) transaction support |
3601 | 50 | * Daniel HAHLER's contributions to this file and the b2evolution project | 22 | * @author {@link http://wonderwinds.com/ Ed Bennett} |
3602 | 51 | * under any OSI approved OSS license (http://www.opensource.org/licenses/). | 23 | * @author {@link http://daniel.hahler.de/ Daniel HAHLER} |
3603 | 52 | * }} | 24 | * @author {@link http://fplanque.net/ Francois PLANQUE} |
3604 | 53 | * | 25 | * @author {@link http://php.justinvincent.com Justin VINCENT} |
3605 | 54 | * {@internal Below is a list of authors who have contributed to design/coding of this file: }} | 26 | * @copyright (c) 2009 by {@link http://quamplures.net/ the Quam Plures project} |
3606 | 55 | * @author blueyed: Daniel HAHLER | 27 | * @license http://www.gnu.org/licenses/gpl.txt GNU General Public License v3 |
3607 | 56 | * @author fplanque: Francois PLANQUE | 28 | * @package core |
3591 | 57 | * @author Justin VINCENT | ||
3592 | 58 | * | ||
3593 | 59 | * @todo transaction support | ||
3594 | 60 | * | ||
3595 | 61 | * @package pond | ||
3608 | 62 | */ | 29 | */ |
3610 | 63 | if( !defined('QP_MAIN_INIT') ) die( 'Please, do not access this page directly.' ); | 30 | if(!defined('QP_MAIN_INIT')) die('fail'); |
3611 | 64 | 31 | ||
3612 | 65 | /** | 32 | /** |
3613 | 66 | * ezSQL Constants | 33 | * ezSQL Constants |
3614 | 67 | */ | 34 | */ |
3615 | 68 | define( 'EZSQL_VERSION', '1.25' ); | 35 | define( 'EZSQL_VERSION', '1.25' ); |
3616 | 36 | /** | ||
3617 | 37 | * ezSQL Constants | ||
3618 | 38 | */ | ||
3619 | 69 | define( 'OBJECT', 'OBJECT', true ); | 39 | define( 'OBJECT', 'OBJECT', true ); |
3620 | 40 | /** | ||
3621 | 41 | * ezSQL Constants | ||
3622 | 42 | */ | ||
3623 | 70 | define( 'ARRAY_A', 'ARRAY_A', true); | 43 | define( 'ARRAY_A', 'ARRAY_A', true); |
3624 | 44 | /** | ||
3625 | 45 | * ezSQL Constants | ||
3626 | 46 | */ | ||
3627 | 71 | define( 'ARRAY_N', 'ARRAY_N', true); | 47 | define( 'ARRAY_N', 'ARRAY_N', true); |
3628 | 72 | 48 | ||
3629 | 73 | |||
3630 | 74 | /** | 49 | /** |
3632 | 75 | * The Main Class | 50 | * DB base class |
3633 | 76 | * | 51 | * |
3635 | 77 | * @package pond | 52 | * @package core |
3636 | 78 | */ | 53 | */ |
3637 | 79 | class DB | 54 | class DB |
3638 | 80 | { | 55 | { |
3639 | @@ -94,7 +69,7 @@ | |||
3640 | 94 | */ | 69 | */ |
3641 | 95 | var $error = false; | 70 | var $error = false; |
3642 | 96 | /** | 71 | /** |
3644 | 97 | * Number of done queries. | 72 | * Number of done queries |
3645 | 98 | * @var integer | 73 | * @var integer |
3646 | 99 | */ | 74 | */ |
3647 | 100 | var $num_queries = 0; | 75 | var $num_queries = 0; |
3648 | @@ -108,168 +83,150 @@ | |||
3649 | 108 | * @var string | 83 | * @var string |
3650 | 109 | */ | 84 | */ |
3651 | 110 | var $last_error = ''; | 85 | var $last_error = ''; |
3652 | 111 | |||
3653 | 112 | /** | 86 | /** |
3654 | 113 | * Last insert ID | 87 | * Last insert ID |
3655 | 114 | * @var integer | 88 | * @var integer |
3656 | 115 | */ | 89 | */ |
3657 | 116 | var $insert_id = 0; | 90 | var $insert_id = 0; |
3658 | 117 | |||
3659 | 118 | /** | 91 | /** |
3660 | 119 | * Last query's resource | 92 | * Last query's resource |
3661 | 120 | * @access protected | ||
3662 | 121 | * @var resource | 93 | * @var resource |
3663 | 122 | */ | 94 | */ |
3664 | 123 | var $result; | 95 | var $result; |
3665 | 124 | |||
3666 | 125 | /** | 96 | /** |
3667 | 126 | * Last result's rows | 97 | * Last result's rows |
3668 | 127 | * @var array | 98 | * @var array |
3669 | 128 | */ | 99 | */ |
3670 | 129 | var $last_result; | 100 | var $last_result; |
3671 | 130 | |||
3672 | 131 | /** | 101 | /** |
3673 | 132 | * Number of rows in result set (after a select) | 102 | * Number of rows in result set (after a select) |
3674 | 103 | * @var foo | ||
3675 | 133 | */ | 104 | */ |
3676 | 134 | var $num_rows = 0; | 105 | var $num_rows = 0; |
3677 | 135 | |||
3678 | 136 | /** | 106 | /** |
3679 | 137 | * Number of rows affected by insert, delete, update or replace | 107 | * Number of rows affected by insert, delete, update or replace |
3680 | 108 | * @var foo | ||
3681 | 138 | */ | 109 | */ |
3682 | 139 | var $rows_affected = 0; | 110 | var $rows_affected = 0; |
3683 | 140 | |||
3684 | 141 | /** | 111 | /** |
3686 | 142 | * Aliases that will be replaced in queries: | 112 | * Aliases that will be replaced in queries |
3687 | 113 | * @var foo | ||
3688 | 143 | */ | 114 | */ |
3689 | 144 | var $dbaliases = array(); | 115 | var $dbaliases = array(); |
3690 | 145 | /** | 116 | /** |
3692 | 146 | * Strings that will replace the aliases in queries: | 117 | * Strings that will replace the aliases in queries |
3693 | 118 | * @var foo | ||
3694 | 147 | */ | 119 | */ |
3695 | 148 | var $dbreplaces = array(); | 120 | var $dbreplaces = array(); |
3696 | 149 | |||
3697 | 150 | /** | 121 | /** |
3706 | 151 | * CREATE TABLE options. | 122 | * CREATE TABLE options |
3707 | 152 | * | 123 | * |
3708 | 153 | * This gets appended to every "CREATE TABLE" query. | 124 | * This gets appended to every "CREATE TABLE" query. Edit those if you have control over your MySQL |
3709 | 154 | * | 125 | * server and want a more professional database than what is commonly offered by popular hosting providers. |
3710 | 155 | * Edit those if you have control over you MySQL server and want a more professional | 126 | * |
3703 | 156 | * database than what is commonly offered by popular hosting providers. | ||
3704 | 157 | * | ||
3705 | 158 | * @todo dh> If the query itself uses already e.g. "CHARACTER SET latin1" it should not get overridden.. | ||
3711 | 159 | * @var string | 127 | * @var string |
3712 | 160 | */ | 128 | */ |
3713 | 161 | var $table_options = ''; | 129 | var $table_options = ''; |
3714 | 162 | |||
3715 | 163 | /** | 130 | /** |
3716 | 164 | * Use transactions in DB? | 131 | * Use transactions in DB? |
3717 | 165 | * | 132 | * |
3719 | 166 | * You need to use InnoDB in order to enable this. See the {@link $app_db_config "table_options" key}. | 133 | * You need to use InnoDB in order to enable this. See the {@link $app_db_config |
3720 | 134 | * "table_options" key}. | ||
3721 | 135 | * | ||
3722 | 136 | * @var foo | ||
3723 | 167 | */ | 137 | */ |
3724 | 168 | var $use_transactions = false; | 138 | var $use_transactions = false; |
3725 | 169 | |||
3726 | 170 | /** | 139 | /** |
3727 | 171 | * How many transactions are currently nested? | 140 | * How many transactions are currently nested? |
3728 | 141 | * @var foo | ||
3729 | 172 | */ | 142 | */ |
3730 | 173 | var $transaction_nesting_level = 0; | 143 | var $transaction_nesting_level = 0; |
3731 | 174 | |||
3732 | 175 | /** | 144 | /** |
3733 | 176 | * Rememeber if we have to rollback at the end of a nested transaction construct | 145 | * Rememeber if we have to rollback at the end of a nested transaction construct |
3734 | 146 | * @var foo | ||
3735 | 177 | */ | 147 | */ |
3736 | 178 | var $rollback_nested_transaction = false; | 148 | var $rollback_nested_transaction = false; |
3737 | 179 | |||
3738 | 180 | /** | 149 | /** |
3739 | 181 | * MySQL Database handle | 150 | * MySQL Database handle |
3740 | 182 | * @var object | 151 | * @var object |
3741 | 183 | */ | 152 | */ |
3742 | 184 | var $dbhandle; | 153 | var $dbhandle; |
3743 | 185 | |||
3744 | 186 | /** | 154 | /** |
3745 | 187 | * Database username | 155 | * Database username |
3746 | 188 | * @var string | 156 | * @var string |
3747 | 189 | */ | 157 | */ |
3748 | 190 | var $dbuser; | 158 | var $dbuser; |
3749 | 191 | |||
3750 | 192 | /** | 159 | /** |
3751 | 193 | * Database username's password | 160 | * Database username's password |
3752 | 194 | * @var string | 161 | * @var string |
3753 | 195 | */ | 162 | */ |
3754 | 196 | var $dbpassword; | 163 | var $dbpassword; |
3755 | 197 | |||
3756 | 198 | /** | 164 | /** |
3757 | 199 | * Database name | 165 | * Database name |
3758 | 200 | * @var string | 166 | * @var string |
3759 | 201 | * @see select() | ||
3760 | 202 | */ | 167 | */ |
3761 | 203 | var $dbname; | 168 | var $dbname; |
3762 | 204 | |||
3763 | 205 | /** | 169 | /** |
3764 | 206 | * Database hostname | 170 | * Database hostname |
3765 | 207 | * @var string | 171 | * @var string |
3766 | 208 | */ | 172 | */ |
3767 | 209 | var $dbhost = 'localhost'; | 173 | var $dbhost = 'localhost'; |
3768 | 210 | |||
3769 | 211 | /** | 174 | /** |
3770 | 212 | * Current connection charset | 175 | * Current connection charset |
3771 | 213 | * @var string | 176 | * @var string |
3772 | 214 | * @see DB::set_connection_charset() | 177 | * @see DB::set_connection_charset() |
3773 | 215 | */ | 178 | */ |
3774 | 216 | var $connection_charset; | 179 | var $connection_charset; |
3775 | 217 | |||
3776 | 218 | |||
3777 | 219 | // DEBUG: | ||
3778 | 220 | |||
3779 | 221 | /** | 180 | /** |
3780 | 222 | * Do we want to log queries? | 181 | * Do we want to log queries? |
3783 | 223 | * If null, it gets set according to {@link $debug}. | 182 | * |
3784 | 224 | * A subclass may set it by default (e.g. DbUnitTestCase_DB). | 183 | * If null, it gets set according to {@link $debug}. A subclass may set it by |
3785 | 184 | * default (e.g. DbUnitTestCase_DB). | ||
3786 | 185 | * | ||
3787 | 225 | * @var boolean | 186 | * @var boolean |
3788 | 226 | */ | 187 | */ |
3789 | 227 | var $log_queries; | 188 | var $log_queries; |
3790 | 228 | |||
3791 | 229 | /** | 189 | /** |
3793 | 230 | * Log of queries: | 190 | * Log of queries |
3794 | 231 | * @var array | 191 | * @var array |
3795 | 232 | */ | 192 | */ |
3796 | 233 | var $queries = array(); | 193 | var $queries = array(); |
3797 | 234 | |||
3798 | 235 | /** | 194 | /** |
3799 | 236 | * Do we want to explain joins? | 195 | * Do we want to explain joins? |
3800 | 196 | * | ||
3801 | 237 | * This requires {@link DB::$log_queries} to be true. | 197 | * This requires {@link DB::$log_queries} to be true. |
3802 | 238 | * | 198 | * |
3805 | 239 | * @todo fp> we'd probably want to group all the advanced debug vars under a single setting now. We might even auto enable it when $debug=2. (And we might actually want to include a $debug="cookie" mode for easy switching with bookmarks or a bookmarklet) | 199 | * @todo (0000) fp> we'd probably want to group all the advanced debug vars under a single setting now. We might even auto enable it when $debug=2. (And we might actually want to include a $debug="cookie" mode for easy switching with bookmarks or a bookmarklet) |
3804 | 240 | * | ||
3806 | 241 | * @var boolean | 200 | * @var boolean |
3807 | 242 | */ | 201 | */ |
3808 | 243 | var $debug_explain_joins = false; | 202 | var $debug_explain_joins = false; |
3809 | 244 | |||
3810 | 245 | /** | 203 | /** |
3811 | 246 | * Do we want to output a function backtrace for every query? | 204 | * Do we want to output a function backtrace for every query? |
3812 | 205 | * | ||
3813 | 247 | * Number of stack entries to show (from last to first) (Default: 0); true means 'all'. | 206 | * Number of stack entries to show (from last to first) (Default: 0); true means 'all'. |
3814 | 248 | * | ||
3815 | 249 | * This requires {@link DB::$log_queries} to be true. | 207 | * This requires {@link DB::$log_queries} to be true. |
3816 | 250 | * | 208 | * |
3817 | 251 | * @var integer | 209 | * @var integer |
3818 | 252 | */ | 210 | */ |
3819 | 253 | var $debug_dump_function_trace_for_queries = 0; | 211 | var $debug_dump_function_trace_for_queries = 0; |
3820 | 254 | |||
3821 | 255 | /** | 212 | /** |
3822 | 256 | * Number of rows we want to dump in debug output (0 disables it) | 213 | * Number of rows we want to dump in debug output (0 disables it) |
3823 | 214 | * | ||
3824 | 257 | * This requires {@link DB::$log_queries} to be true. | 215 | * This requires {@link DB::$log_queries} to be true. |
3825 | 216 | * | ||
3826 | 258 | * @var integer | 217 | * @var integer |
3827 | 259 | */ | 218 | */ |
3828 | 260 | var $debug_dump_rows = 0; | 219 | var $debug_dump_rows = 0; |
3829 | 261 | |||
3830 | 262 | /** | 220 | /** |
3832 | 263 | * Time in seconds that is considered a fast query (green). | 221 | * Time in seconds that is considered a fast query (green) |
3833 | 222 | * @see dump_queries() | ||
3834 | 264 | * @var float | 223 | * @var float |
3835 | 265 | * @see dump_queries() | ||
3836 | 266 | */ | 224 | */ |
3837 | 267 | var $query_duration_fast = 0.05; | 225 | var $query_duration_fast = 0.05; |
3838 | 268 | |||
3839 | 269 | /** | 226 | /** |
3841 | 270 | * Time in seconds that is considered a slow query (red). | 227 | * Time in seconds that is considered a slow query (red) |
3842 | 228 | * @see dump_queries() | ||
3843 | 271 | * @var float | 229 | * @var float |
3844 | 272 | * @see dump_queries() | ||
3845 | 273 | */ | 230 | */ |
3846 | 274 | var $query_duration_slow = 0.3; | 231 | var $query_duration_slow = 0.3; |
3847 | 275 | 232 | ||
3848 | @@ -279,32 +236,36 @@ | |||
3849 | 279 | * | 236 | * |
3850 | 280 | * Connects to the server and selects a database. | 237 | * Connects to the server and selects a database. |
3851 | 281 | * | 238 | * |
3852 | 239 | * Mandatory parameters: | ||
3853 | 240 | * - 'user': username to connect with | ||
3854 | 241 | * - 'password': password to connect with OR | ||
3855 | 242 | * - 'handle': a MySQL Database handle (from a previous {@link mysql_connect()}) | ||
3856 | 243 | * | ||
3857 | 244 | * Optional parameters: | ||
3858 | 245 | * - 'name': the name of the default database, see {@link DB::select()} | ||
3859 | 246 | * - 'host': host of the database; Default: 'localhost' | ||
3860 | 247 | * - 'show_errors': Display SQL errors? (true/false); Default: don't change member | ||
3861 | 248 | * default ({@link $show_errors}) | ||
3862 | 249 | * - 'halt_on_error': Halt on error? (true/false); Default: don't change member | ||
3863 | 250 | * default ({@link $halt_on_error}) | ||
3864 | 251 | * - 'table_options': sets {@link $table_options} | ||
3865 | 252 | * - 'use_transactions': sets {@link $use_transactions} | ||
3866 | 253 | * - 'aliases': Aliases for tables (array( alias => table name )); Default: no aliases. | ||
3867 | 254 | * - 'new_link': create a new link to the DB, even if there was a mysql_connect() with | ||
3868 | 255 | * the same params before. (requires PHP 4.2) | ||
3869 | 256 | * - 'client_flags': optional settings like compression or SSL encryption. See | ||
3870 | 257 | * {@link http://www.php.net/manual/en/ref.mysql.php#mysql.client-flags}. | ||
3871 | 258 | * | ||
3872 | 282 | * @param array An array of parameters. | 259 | * @param array An array of parameters. |
3873 | 283 | * Manadatory: | ||
3874 | 284 | * - 'user': username to connect with | ||
3875 | 285 | * - 'password': password to connect with | ||
3876 | 286 | * OR | ||
3877 | 287 | * - 'handle': a MySQL Database handle (from a previous {@link mysql_connect()}) | ||
3878 | 288 | * Optional: | ||
3879 | 289 | * - 'name': the name of the default database, see {@link DB::select()} | ||
3880 | 290 | * - 'host': host of the database; Default: 'localhost' | ||
3881 | 291 | * - 'show_errors': Display SQL errors? (true/false); Default: don't change member default ({@link $show_errors}) | ||
3882 | 292 | * - 'halt_on_error': Halt on error? (true/false); Default: don't change member default ({@link $halt_on_error}) | ||
3883 | 293 | * - 'table_options': sets {@link $table_options} | ||
3884 | 294 | * - 'use_transactions': sets {@link $use_transactions} | ||
3885 | 295 | * - 'aliases': Aliases for tables (array( alias => table name )); Default: no aliases. | ||
3886 | 296 | * - 'new_link': create a new link to the DB, even if there was a mysql_connect() with | ||
3887 | 297 | * the same params before. (requires PHP 4.2) | ||
3888 | 298 | * - 'client_flags': optional settings like compression or SSL encryption. See {@link http://www.php.net/manual/en/ref.mysql.php#mysql.client-flags}. | ||
3889 | 299 | * (requires PHP 4.3) | ||
3890 | 300 | */ | 260 | */ |
3891 | 301 | function DB( $params ) | 261 | function DB( $params ) |
3892 | 302 | { | 262 | { |
3893 | 303 | global $debug; | 263 | global $debug; |
3894 | 304 | 264 | ||
3896 | 305 | // Mandatory parameters: | 265 | // Mandatory parameters |
3897 | 306 | if( isset( $params['handle'] ) ) | 266 | if( isset( $params['handle'] ) ) |
3899 | 307 | { // DB-Link provided: | 267 | { |
3900 | 268 | // DB-Link provided | ||
3901 | 308 | $this->dbhandle = $params['handle']; | 269 | $this->dbhandle = $params['handle']; |
3902 | 309 | } | 270 | } |
3903 | 310 | else | 271 | else |
3904 | @@ -313,35 +274,73 @@ | |||
3905 | 313 | $this->dbpassword = $params['password']; | 274 | $this->dbpassword = $params['password']; |
3906 | 314 | } | 275 | } |
3907 | 315 | 276 | ||
3921 | 316 | // Optional parameters (Allow overriding through $params): | 277 | // Optional parameters (Allow overriding through $params) |
3922 | 317 | if( isset($params['name']) ) $this->dbname = $params['name']; | 278 | if( isset( $params['name'] ) ) |
3923 | 318 | if( isset($params['host']) ) $this->dbhost = $params['host']; | 279 | { |
3924 | 319 | if( isset($params['show_errors']) ) $this->show_errors = $params['show_errors']; | 280 | $this->dbname = $params['name']; |
3925 | 320 | if( isset($params['halt_on_error']) ) $this->halt_on_error = $params['halt_on_error']; | 281 | } |
3926 | 321 | if( isset($params['table_options']) ) $this->table_options = $params['table_options']; | 282 | |
3927 | 322 | if( isset($params['use_transactions']) ) $this->use_transactions = $params['use_transactions']; | 283 | if( isset( $params['host'] ) ) |
3928 | 323 | if( isset($params['debug_dump_rows']) ) $this->debug_dump_rows = $params['debug_dump_rows']; // Nb of rows to dump | 284 | { |
3929 | 324 | if( isset($params['debug_explain_joins']) ) $this->debug_explain_joins = $params['debug_explain_joins']; | 285 | $this->dbhost = $params['host']; |
3930 | 325 | if( isset($params['debug_dump_function_trace_for_queries']) ) $this->debug_dump_function_trace_for_queries = $params['debug_dump_function_trace_for_queries']; | 286 | } |
3931 | 326 | 287 | ||
3932 | 327 | if( isset($debug) && ! isset($this->log_queries) ) | 288 | if( isset( $params['show_errors'] ) ) |
3933 | 328 | { // $log_queries follows $debug and respects subclasses, which may define it: | 289 | { |
3934 | 290 | $this->show_errors = $params['show_errors']; | ||
3935 | 291 | } | ||
3936 | 292 | |||
3937 | 293 | if( isset( $params['halt_on_error'] ) ) | ||
3938 | 294 | { | ||
3939 | 295 | $this->halt_on_error = $params['halt_on_error']; | ||
3940 | 296 | } | ||
3941 | 297 | |||
3942 | 298 | if( isset( $params['table_options'] ) ) | ||
3943 | 299 | { | ||
3944 | 300 | $this->table_options = $params['table_options']; | ||
3945 | 301 | } | ||
3946 | 302 | |||
3947 | 303 | if( isset( $params['use_transactions'] ) ) | ||
3948 | 304 | { | ||
3949 | 305 | $this->use_transactions = $params['use_transactions']; | ||
3950 | 306 | } | ||
3951 | 307 | |||
3952 | 308 | if( isset( $params['debug_dump_rows'] ) ) | ||
3953 | 309 | { | ||
3954 | 310 | $this->debug_dump_rows = $params['debug_dump_rows']; // Nb of rows to dump | ||
3955 | 311 | } | ||
3956 | 312 | |||
3957 | 313 | if( isset( $params['debug_explain_joins'] ) ) | ||
3958 | 314 | { | ||
3959 | 315 | $this->debug_explain_joins = $params['debug_explain_joins']; | ||
3960 | 316 | } | ||
3961 | 317 | |||
3962 | 318 | if( isset( $params['debug_dump_function_trace_for_queries'] ) ) | ||
3963 | 319 | { | ||
3964 | 320 | $this->debug_dump_function_trace_for_queries = $params['debug_dump_function_trace_for_queries']; | ||
3965 | 321 | } | ||
3966 | 322 | |||
3967 | 323 | if( isset( $debug ) && ! isset( $this->log_queries ) ) | ||
3968 | 324 | { | ||
3969 | 325 | // $log_queries follows $debug and respects subclasses, which may define it | ||
3970 | 329 | $this->log_queries = $debug; | 326 | $this->log_queries = $debug; |
3971 | 330 | } | 327 | } |
3972 | 331 | 328 | ||
3975 | 332 | if( ! extension_loaded('mysql') ) | 329 | if( ! extension_loaded( 'mysql' ) ) |
3976 | 333 | { // The mysql extension is not loaded, try to dynamically load it: | 330 | { |
3977 | 331 | // The mysql extension is not loaded, try to dynamically load it | ||
3978 | 334 | $mysql_ext_file = is_windows() ? 'php_mysql.dll' : 'mysql.so'; | 332 | $mysql_ext_file = is_windows() ? 'php_mysql.dll' : 'mysql.so'; |
3979 | 335 | $php_errormsg = null; | 333 | $php_errormsg = null; |
3982 | 336 | $old_track_errors = ini_set('track_errors', 1); | 334 | $old_track_errors = ini_set( 'track_errors', 1 ); |
3983 | 337 | $old_html_errors = ini_set('html_errors', 0); | 335 | $old_html_errors = ini_set( 'html_errors', 0 ); |
3984 | 338 | @dl( $mysql_ext_file ); | 336 | @dl( $mysql_ext_file ); |
3985 | 339 | $error_msg = $php_errormsg; | 337 | $error_msg = $php_errormsg; |
3988 | 340 | if( $old_track_errors !== false ) ini_set('track_errors', $old_track_errors); | 338 | if( $old_track_errors !== false ) ini_set( 'track_errors', $old_track_errors ); |
3989 | 341 | if( $old_html_errors !== false ) ini_set('html_errors', $old_html_errors); | 339 | if( $old_html_errors !== false ) ini_set( 'html_errors', $old_html_errors ); |
3990 | 342 | 340 | ||
3993 | 343 | if( ! extension_loaded('mysql') ) | 341 | if( ! extension_loaded( 'mysql' ) ) |
3994 | 344 | { // Still not loaded: | 342 | { |
3995 | 343 | // Still not loaded | ||
3996 | 345 | $this->print_error( 'The PHP MySQL module could not be loaded.', ' | 344 | $this->print_error( 'The PHP MySQL module could not be loaded.', ' |
3997 | 346 | <p><strong>Error:</strong> '.$error_msg.'</p> | 345 | <p><strong>Error:</strong> '.$error_msg.'</p> |
3998 | 347 | <p>You probably have to edit your php configuration (php.ini) and enable this module ('.$mysql_ext_file.').</p> | 346 | <p>You probably have to edit your php configuration (php.ini) and enable this module ('.$mysql_ext_file.').</p> |
3999 | @@ -354,16 +353,17 @@ | |||
4000 | 354 | $client_flags = isset( $params['client_flags'] ) ? $params['client_flags'] : 0; | 353 | $client_flags = isset( $params['client_flags'] ) ? $params['client_flags'] : 0; |
4001 | 355 | 354 | ||
4002 | 356 | if( ! $this->dbhandle ) | 355 | if( ! $this->dbhandle ) |
4004 | 357 | { // Connect to the Database: | 356 | { |
4005 | 357 | // Connect to the Database | ||
4006 | 358 | // mysql_error() is tied to an established connection | 358 | // mysql_error() is tied to an established connection |
4007 | 359 | // if the connection fails we need a different method to get the error message | 359 | // if the connection fails we need a different method to get the error message |
4008 | 360 | $php_errormsg = null; | 360 | $php_errormsg = null; |
4011 | 361 | $old_track_errors = ini_set('track_errors', 1); | 361 | $old_track_errors = ini_set( 'track_errors', 1 ); |
4012 | 362 | $old_html_errors = ini_set('html_errors', 0); | 362 | $old_html_errors = ini_set( 'html_errors', 0 ); |
4013 | 363 | $this->dbhandle = @mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags ); | 363 | $this->dbhandle = @mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags ); |
4014 | 364 | $mysql_error = $php_errormsg; | 364 | $mysql_error = $php_errormsg; |
4017 | 365 | if( $old_track_errors !== false ) ini_set('track_errors', $old_track_errors); | 365 | if( $old_track_errors !== false ) ini_set( 'track_errors', $old_track_errors ); |
4018 | 366 | if( $old_html_errors !== false ) ini_set('html_errors', $old_html_errors); | 366 | if( $old_html_errors !== false ) ini_set( 'html_errors', $old_html_errors ); |
4019 | 367 | } | 367 | } |
4020 | 368 | 368 | ||
4021 | 369 | if( ! $this->dbhandle ) | 369 | if( ! $this->dbhandle ) |
4022 | @@ -371,18 +371,19 @@ | |||
4023 | 371 | $this->print_error( 'Error establishing a database connection!', ' | 371 | $this->print_error( 'Error establishing a database connection!', ' |
4024 | 372 | <p>('.$mysql_error.')</p> | 372 | <p>('.$mysql_error.')</p> |
4025 | 373 | <ol> | 373 | <ol> |
4029 | 374 | <li>Are you sure you have typed the correct user/password?</li> | 374 | <li>Are you sure you have typed the correct user/password?</li> |
4030 | 375 | <li>Are you sure that you have typed the correct hostname?</li> | 375 | <li>Are you sure that you have typed the correct hostname?</li> |
4031 | 376 | <li>Are you sure that the database server is running?</li> | 376 | <li>Are you sure that the database server is running?</li> |
4032 | 377 | </ol>', false ); | 377 | </ol>', false ); |
4033 | 378 | } | 378 | } |
4035 | 379 | elseif( isset($this->dbname) ) | 379 | elseif( isset( $this->dbname ) ) |
4036 | 380 | { | 380 | { |
4038 | 381 | $this->select($this->dbname); | 381 | $this->select( $this->dbname ); |
4039 | 382 | } | 382 | } |
4040 | 383 | 383 | ||
4043 | 384 | if( !empty($params['connection_charset']) ) | 384 | if( ! empty( $params['connection_charset'] ) ) |
4044 | 385 | { // Specify which charset we are using on the client: | 385 | { |
4045 | 386 | // Specify which charset we are using on the client | ||
4046 | 386 | $this->set_connection_charset( $params['connection_charset'] ); | 387 | $this->set_connection_charset( $params['connection_charset'] ); |
4047 | 387 | } | 388 | } |
4048 | 388 | 389 | ||
4049 | @@ -395,8 +396,9 @@ | |||
4050 | 395 | */ | 396 | */ |
4051 | 396 | 397 | ||
4052 | 397 | 398 | ||
4055 | 398 | if( isset($params['aliases']) ) | 399 | if( isset( $params['aliases'] ) ) |
4056 | 399 | { // Prepare aliases for replacements: | 400 | { |
4057 | 401 | // Prepare aliases for replacements | ||
4058 | 400 | foreach( $params['aliases'] as $dbalias => $dbreplace ) | 402 | foreach( $params['aliases'] as $dbalias => $dbreplace ) |
4059 | 401 | { | 403 | { |
4060 | 402 | $this->dbaliases[] = '#\b'.$dbalias.'\b#'; // \b = word boundary | 404 | $this->dbaliases[] = '#\b'.$dbalias.'\b#'; // \b = word boundary |
4061 | @@ -405,7 +407,8 @@ | |||
4062 | 405 | } | 407 | } |
4063 | 406 | 408 | ||
4064 | 407 | if( $debug ) | 409 | if( $debug ) |
4066 | 408 | { // Force MySQL strict mode | 410 | { |
4067 | 411 | // Force MySQL strict mode | ||
4068 | 409 | // TRADITIONAL mode is only available to mysql > 5.0.2 | 412 | // TRADITIONAL mode is only available to mysql > 5.0.2 |
4069 | 410 | $mysql_version = $this->get_version( 'we do this in DEBUG mode only' ); | 413 | $mysql_version = $this->get_version( 'we do this in DEBUG mode only' ); |
4070 | 411 | if( version_compare( $mysql_version, '5.0.2' ) > 0 ) | 414 | if( version_compare( $mysql_version, '5.0.2' ) > 0 ) |
4071 | @@ -419,15 +422,15 @@ | |||
4072 | 419 | /** | 422 | /** |
4073 | 420 | * Select a DB (if another one needs to be selected) | 423 | * Select a DB (if another one needs to be selected) |
4074 | 421 | */ | 424 | */ |
4076 | 422 | function select($db) | 425 | function select( $db ) |
4077 | 423 | { | 426 | { |
4079 | 424 | if( !@mysql_select_db($db, $this->dbhandle) ) | 427 | if( !@mysql_select_db( $db, $this->dbhandle ) ) |
4080 | 425 | { | 428 | { |
4081 | 426 | $this->print_error( 'Error selecting database ['.$db.']!', ' | 429 | $this->print_error( 'Error selecting database ['.$db.']!', ' |
4082 | 427 | <ol> | 430 | <ol> |
4086 | 428 | <li>Are you sure the database exists?</li> | 431 | <li>Are you sure the database exists?</li> |
4087 | 429 | <li>Are you sure the DB user is allowed to use that database?</li> | 432 | <li>Are you sure the DB user is allowed to use that database?</li> |
4088 | 430 | <li>Are you sure there is a valid database connection?</li> | 433 | <li>Are you sure there is a valid database connection?</li> |
4089 | 431 | </ol>', false ); | 434 | </ol>', false ); |
4090 | 432 | } | 435 | } |
4091 | 433 | } | 436 | } |
4092 | @@ -436,19 +439,19 @@ | |||
4093 | 436 | /** | 439 | /** |
4094 | 437 | * Format a string correctly for safe insert under all PHP conditions | 440 | * Format a string correctly for safe insert under all PHP conditions |
4095 | 438 | */ | 441 | */ |
4097 | 439 | function escape($str) | 442 | function escape( $str ) |
4098 | 440 | { | 443 | { |
4100 | 441 | return mysql_real_escape_string($str, $this->dbhandle); | 444 | return mysql_real_escape_string( $str, $this->dbhandle ); |
4101 | 442 | } | 445 | } |
4102 | 443 | 446 | ||
4103 | 444 | 447 | ||
4104 | 445 | /** | 448 | /** |
4106 | 446 | * Quote a value, either in single quotes (and escaped) or if it's NULL as 'NULL'. | 449 | * Quote a value, either in single quotes (and escaped) or if it's NULL as 'NULL' |
4107 | 447 | * | 450 | * |
4108 | 448 | * @param string|array|null | 451 | * @param string|array|null |
4109 | 449 | * @return string Quoted (and escaped) value or 'NULL'. | 452 | * @return string Quoted (and escaped) value or 'NULL'. |
4110 | 450 | */ | 453 | */ |
4112 | 451 | function quote($str) | 454 | function quote( $str ) |
4113 | 452 | { | 455 | { |
4114 | 453 | if( is_null( $str ) ) | 456 | if( is_null( $str ) ) |
4115 | 454 | { | 457 | { |
4116 | @@ -459,26 +462,30 @@ | |||
4117 | 459 | $r = ''; | 462 | $r = ''; |
4118 | 460 | foreach( $str as $elt ) | 463 | foreach( $str as $elt ) |
4119 | 461 | { | 464 | { |
4121 | 462 | $r .= $this->quote($elt).','; | 465 | $r .= $this->quote( $elt ).','; |
4122 | 463 | } | 466 | } |
4123 | 464 | return substr( $r, 0, -1 ); | 467 | return substr( $r, 0, -1 ); |
4124 | 465 | } | 468 | } |
4125 | 466 | else | 469 | else |
4126 | 467 | { | 470 | { |
4128 | 468 | return "'".mysql_real_escape_string($str, $this->dbhandle)."'"; | 471 | return "'".mysql_real_escape_string( $str, $this->dbhandle )."'"; |
4129 | 469 | } | 472 | } |
4130 | 470 | } | 473 | } |
4131 | 471 | 474 | ||
4132 | 472 | 475 | ||
4133 | 473 | /** | 476 | /** |
4135 | 474 | * @return string Return the given value or 'NULL', if it's === NULL. | 477 | * @return string Return the given value or 'NULL', if it's === NULL |
4136 | 475 | */ | 478 | */ |
4138 | 476 | function null($val) | 479 | function null( $val ) |
4139 | 477 | { | 480 | { |
4140 | 478 | if( $val === NULL ) | 481 | if( $val === NULL ) |
4141 | 482 | { | ||
4142 | 479 | return 'NULL'; | 483 | return 'NULL'; |
4143 | 484 | } | ||
4144 | 480 | else | 485 | else |
4145 | 486 | { | ||
4146 | 481 | return $val; | 487 | return $val; |
4147 | 488 | } | ||
4148 | 482 | } | 489 | } |
4149 | 483 | 490 | ||
4150 | 484 | 491 | ||
4151 | @@ -486,7 +493,6 @@ | |||
4152 | 486 | * Returns the correct WEEK() function to get the week number for the given date. | 493 | * Returns the correct WEEK() function to get the week number for the given date. |
4153 | 487 | * | 494 | * |
4154 | 488 | * @link http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html | 495 | * @link http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html |
4155 | 489 | * | ||
4156 | 490 | * @todo disable when MySQL < 4 | 496 | * @todo disable when MySQL < 4 |
4157 | 491 | * @param string will be used as is | 497 | * @param string will be used as is |
4158 | 492 | * @param integer 0 for sunday, 1 for monday | 498 | * @param integer 0 for sunday, 1 for monday |
4159 | @@ -494,20 +500,18 @@ | |||
4160 | 494 | function week( $date, $startofweek ) | 500 | function week( $date, $startofweek ) |
4161 | 495 | { | 501 | { |
4162 | 496 | if( $startofweek == 1 ) | 502 | if( $startofweek == 1 ) |
4164 | 497 | { // Week starts on Monday, week 1 must have a monday in this year: | 503 | { |
4165 | 504 | // Week starts on Monday, week 1 must have a monday in this year | ||
4166 | 498 | return ' WEEK( '.$date.', 5 ) '; | 505 | return ' WEEK( '.$date.', 5 ) '; |
4167 | 499 | } | 506 | } |
4168 | 500 | 507 | ||
4170 | 501 | // Week starts on Sunday, week 1 must have a sunday in this year: | 508 | // Week starts on Sunday, week 1 must have a sunday in this year |
4171 | 502 | return ' WEEK( '.$date.', 0 ) '; | 509 | return ' WEEK( '.$date.', 0 ) '; |
4172 | 503 | } | 510 | } |
4173 | 504 | 511 | ||
4174 | 505 | 512 | ||
4175 | 506 | /** | 513 | /** |
4180 | 507 | * Print SQL/DB error. | 514 | * Print SQL/DB error |
4177 | 508 | * | ||
4178 | 509 | * TODO: fp> bloated: it probably doesn't make sense to display errors if we don't stop. Any use case? | ||
4179 | 510 | * dh> Sure. Local testing (and test cases). | ||
4181 | 511 | * | 515 | * |
4182 | 512 | * @param string Short error (no HTML) | 516 | * @param string Short error (no HTML) |
4183 | 513 | * @param string Extended description/help for the error (for HTML) | 517 | * @param string Extended description/help for the error (for HTML) |
4184 | @@ -515,17 +519,19 @@ | |||
4185 | 515 | */ | 519 | */ |
4186 | 516 | function print_error( $title = '', $html_str = '', $query_title = '' ) | 520 | function print_error( $title = '', $html_str = '', $query_title = '' ) |
4187 | 517 | { | 521 | { |
4190 | 518 | // All errors go to the global error array $EZSQL_ERROR.. | 522 | // All errors go to the global error array $EZSQL_ERROR |
4191 | 519 | global $EZSQL_ERROR, $is_cli; | 523 | global $EZSQL_ERROR; |
4192 | 524 | global $is_cli; | ||
4193 | 520 | 525 | ||
4194 | 521 | $this->error = true; | 526 | $this->error = true; |
4195 | 522 | 527 | ||
4198 | 523 | // If no special error string then use mysql default.. | 528 | // If no special error string then use mysql default |
4199 | 524 | if( ! strlen($title) ) | 529 | if( ! strlen( $title ) ) |
4200 | 525 | { | 530 | { |
4204 | 526 | if( is_resource($this->dbhandle) ) | 531 | if( is_resource( $this->dbhandle ) ) |
4205 | 527 | { // use mysql_error: | 532 | { |
4206 | 528 | $this->last_error = mysql_error($this->dbhandle).'(Errno='.mysql_errno($this->dbhandle).')'; | 533 | // use mysql_error |
4207 | 534 | $this->last_error = mysql_error( $this->dbhandle ).'(Errno='.mysql_errno( $this->dbhandle ).')'; | ||
4208 | 529 | } | 535 | } |
4209 | 530 | else | 536 | else |
4210 | 531 | { | 537 | { |
4211 | @@ -540,23 +546,26 @@ | |||
4212 | 540 | // Log this error to the global array.. | 546 | // Log this error to the global array.. |
4213 | 541 | $EZSQL_ERROR[] = array( | 547 | $EZSQL_ERROR[] = array( |
4214 | 542 | 'query' => $this->last_query, | 548 | 'query' => $this->last_query, |
4216 | 543 | 'error_str' => $this->last_error | 549 | 'error_str' => $this->last_error |
4217 | 544 | ); | 550 | ); |
4218 | 545 | 551 | ||
4219 | 546 | if( ! ( $this->halt_on_error || $this->show_errors ) ) | 552 | if( ! ( $this->halt_on_error || $this->show_errors ) ) |
4221 | 547 | { // no reason to generate a nice message: | 553 | { |
4222 | 554 | // no reason to generate a nice message | ||
4223 | 548 | return; | 555 | return; |
4224 | 549 | } | 556 | } |
4225 | 550 | 557 | ||
4226 | 551 | if( $this->halt_on_error && ! $this->show_errors ) | 558 | if( $this->halt_on_error && ! $this->show_errors ) |
4228 | 552 | { // do not show errors, just die: | 559 | { |
4229 | 560 | // do not show errors, just die | ||
4230 | 553 | die(); | 561 | die(); |
4231 | 554 | } | 562 | } |
4232 | 555 | 563 | ||
4233 | 556 | if( $is_cli ) | 564 | if( $is_cli ) |
4235 | 557 | { // Clean error message for command line interface: | 565 | { |
4236 | 566 | // Clean error message for command line interface | ||
4237 | 558 | $err_msg = "MySQL error!\n{$this->last_error}\n"; | 567 | $err_msg = "MySQL error!\n{$this->last_error}\n"; |
4239 | 559 | if( ! empty($this->last_query) && $query_title !== false ) | 568 | if( ! empty( $this->last_query ) && $query_title !== false ) |
4240 | 560 | { | 569 | { |
4241 | 561 | $err_msg .= "Your query: $query_title\n"; | 570 | $err_msg .= "Your query: $query_title\n"; |
4242 | 562 | $err_msg .= $this->format_query( $this->last_query, false ); | 571 | $err_msg .= $this->format_query( $this->last_query, false ); |
4243 | @@ -567,7 +576,7 @@ | |||
4244 | 567 | $err_msg = '<p class="error">MySQL error!</p>'."\n"; | 576 | $err_msg = '<p class="error">MySQL error!</p>'."\n"; |
4245 | 568 | $err_msg .= "<div><p><strong>{$this->last_error}</strong></p>\n"; | 577 | $err_msg .= "<div><p><strong>{$this->last_error}</strong></p>\n"; |
4246 | 569 | $err_msg .= $html_str; | 578 | $err_msg .= $html_str; |
4248 | 570 | if( !empty($this->last_query) && $query_title !== false ) | 579 | if( ! empty( $this->last_query ) && $query_title !== false ) |
4249 | 571 | { | 580 | { |
4250 | 572 | $err_msg .= '<p class="error">Your query: '.$query_title.'</p>'; | 581 | $err_msg .= '<p class="error">Your query: '.$query_title.'</p>'; |
4251 | 573 | $err_msg .= '<pre>'; | 582 | $err_msg .= '<pre>'; |
4252 | @@ -579,7 +588,7 @@ | |||
4253 | 579 | 588 | ||
4254 | 580 | if( $this->halt_on_error ) | 589 | if( $this->halt_on_error ) |
4255 | 581 | { | 590 | { |
4257 | 582 | if( function_exists('debug_die') ) | 591 | if( function_exists( 'debug_die' ) ) |
4258 | 583 | { | 592 | { |
4259 | 584 | debug_die( $err_msg ); | 593 | debug_die( $err_msg ); |
4260 | 585 | } | 594 | } |
4261 | @@ -589,7 +598,8 @@ | |||
4262 | 589 | } | 598 | } |
4263 | 590 | } | 599 | } |
4264 | 591 | elseif( $this->show_errors ) | 600 | elseif( $this->show_errors ) |
4266 | 592 | { // If there is an error then take note of it | 601 | { |
4267 | 602 | // If there is an error then take note of it | ||
4268 | 593 | echo '<div class="error">'; | 603 | echo '<div class="error">'; |
4269 | 594 | echo $err_msg; | 604 | echo $err_msg; |
4270 | 595 | echo '</div>'; | 605 | echo '</div>'; |
4271 | @@ -623,8 +633,9 @@ | |||
4272 | 623 | $this->show_errors = false; | 633 | $this->show_errors = false; |
4273 | 624 | $this->halt_on_error = false; | 634 | $this->halt_on_error = false; |
4274 | 625 | 635 | ||
4277 | 626 | if( ($this->version_long = $this->get_var( 'SELECT VERSION()', 0, 0, $query_title ) ) === NULL ) | 636 | if( ( $this->version_long = $this->get_var( 'SELECT VERSION()', 0, 0, $query_title ) ) === NULL ) |
4278 | 627 | { // Very old version ( < 4.0 ) | 637 | { |
4279 | 638 | // Very old version ( < 4.0 ) | ||
4280 | 628 | $this->version = ''; | 639 | $this->version = ''; |
4281 | 629 | $this->version_long = ''; | 640 | $this->version_long = ''; |
4282 | 630 | } | 641 | } |
4283 | @@ -646,10 +657,10 @@ | |||
4284 | 646 | function save_error_state() | 657 | function save_error_state() |
4285 | 647 | { | 658 | { |
4286 | 648 | $this->saved_error_states[] = array( | 659 | $this->saved_error_states[] = array( |
4288 | 649 | 'show_errors' => $this->show_errors, | 660 | 'show_errors' => $this->show_errors, |
4289 | 650 | 'halt_on_error' => $this->halt_on_error, | 661 | 'halt_on_error' => $this->halt_on_error, |
4292 | 651 | 'last_error' => $this->last_error, | 662 | 'last_error' => $this->last_error, |
4293 | 652 | 'error' => $this->error, | 663 | 'error' => $this->error, |
4294 | 653 | ); | 664 | ); |
4295 | 654 | } | 665 | } |
4296 | 655 | 666 | ||
4297 | @@ -661,17 +672,16 @@ | |||
4298 | 661 | */ | 672 | */ |
4299 | 662 | function restore_error_state() | 673 | function restore_error_state() |
4300 | 663 | { | 674 | { |
4303 | 664 | if( empty($this->saved_error_states) | 675 | if( empty( $this->saved_error_states ) || ! is_array( $this->saved_error_states ) ) |
4302 | 665 | || ! is_array($this->saved_error_states) ) | ||
4304 | 666 | { | 676 | { |
4305 | 667 | return false; | 677 | return false; |
4306 | 668 | } | 678 | } |
4308 | 669 | $state = array_pop($this->saved_error_states); | 679 | $state = array_pop( $this->saved_error_states ); |
4309 | 670 | 680 | ||
4311 | 671 | $this->show_errors = $state['show_errors']; | 681 | $this->show_errors = $state['show_errors']; |
4312 | 672 | $this->halt_on_error = $state['halt_on_error']; | 682 | $this->halt_on_error = $state['halt_on_error']; |
4315 | 673 | $this->last_error = $state['last_error']; | 683 | $this->last_error = $state['last_error']; |
4316 | 674 | $this->error = $state['error']; | 684 | $this->error = $state['error']; |
4317 | 675 | } | 685 | } |
4318 | 676 | 686 | ||
4319 | 677 | 687 | ||
4320 | @@ -690,54 +700,63 @@ | |||
4321 | 690 | // initialise return | 700 | // initialise return |
4322 | 691 | $return_val = 0; | 701 | $return_val = 0; |
4323 | 692 | 702 | ||
4325 | 693 | // Flush cached values.. | 703 | // Flush cached values |
4326 | 694 | $this->flush(); | 704 | $this->flush(); |
4327 | 695 | 705 | ||
4330 | 696 | // Replace aliases: | 706 | // Replace aliases |
4331 | 697 | if( ! empty($this->dbaliases) ) | 707 | if( ! empty( $this->dbaliases ) ) |
4332 | 698 | { | 708 | { |
4337 | 699 | // TODO: this should only replace the table name part(s), not the whole query! | 709 | // @todo (0000) this should only replace the table name part(s), not the whole |
4338 | 700 | // blueyed> I've changed it to replace in table name parts for UPDATE, INSERT and REPLACE, because | 710 | // query! blueyed> I've changed it to replace in table name parts for UPDATE, |
4339 | 701 | // it corrupted serialized data.. | 711 | // INSERT and REPLACE, because it corrupted serialized data. IMHO, a cleaner |
4340 | 702 | // IMHO, a cleaner solution would be to use {T_xxx} in the queries and replace it here. In object properties (e.g. DataObject::$dbtablename), only "T_xxx" would get used and surrounded by "{..}" in the queries it creates. | 712 | // solution would be to use {T_xxx} in the queries and replace it here. In |
4341 | 713 | // object properties (e.g. DataObject::$dbtablename), only "T_xxx" would get | ||
4342 | 714 | // used and surrounded by "{..}" in the queries it creates. | ||
4343 | 703 | 715 | ||
4344 | 704 | if( preg_match( '~^\s*(UPDATE\s+)(.*?)(\sSET\s.*)$~is', $query, $match ) ) | 716 | if( preg_match( '~^\s*(UPDATE\s+)(.*?)(\sSET\s.*)$~is', $query, $match ) ) |
4346 | 705 | { // replace only between UPDATE and SET: | 717 | { |
4347 | 718 | // replace only between UPDATE and SET | ||
4348 | 706 | $query = $match[1].preg_replace( $this->dbaliases, $this->dbreplaces, $match[2] ).$match[3]; | 719 | $query = $match[1].preg_replace( $this->dbaliases, $this->dbreplaces, $match[2] ).$match[3]; |
4349 | 707 | } | 720 | } |
4350 | 708 | elseif( preg_match( '~^\s*(INSERT|REPLACE\s+)(.*?)(\s(VALUES|SET)\s.*)$~is', $query, $match ) ) | 721 | elseif( preg_match( '~^\s*(INSERT|REPLACE\s+)(.*?)(\s(VALUES|SET)\s.*)$~is', $query, $match ) ) |
4352 | 709 | { // replace only between INSERT|REPLACE and VALUES|SET: | 722 | { |
4353 | 723 | // replace only between INSERT|REPLACE and VALUES|SET | ||
4354 | 710 | $query = $match[1].preg_replace( $this->dbaliases, $this->dbreplaces, $match[2] ).$match[3]; | 724 | $query = $match[1].preg_replace( $this->dbaliases, $this->dbreplaces, $match[2] ).$match[3]; |
4355 | 711 | } | 725 | } |
4356 | 712 | else | 726 | else |
4358 | 713 | { // replace in whole query: | 727 | { |
4359 | 728 | // replace in whole query | ||
4360 | 714 | $query = preg_replace( $this->dbaliases, $this->dbreplaces, $query ); | 729 | $query = preg_replace( $this->dbaliases, $this->dbreplaces, $query ); |
4361 | 715 | 730 | ||
4364 | 716 | if( ! empty($this->table_options) && preg_match( '#^ \s* create \s* table \s #ix', $query) ) | 731 | if( ! empty( $this->table_options ) && preg_match( '#^ \s* create \s* table \s #ix', $query ) ) |
4365 | 717 | { // Query is a table creation, we add table options: | 732 | { |
4366 | 733 | // Query is a table creation, we add table options | ||
4367 | 718 | $query = preg_replace( '~;\s*$~', '', $query ); // remove any ";" at the end | 734 | $query = preg_replace( '~;\s*$~', '', $query ); // remove any ";" at the end |
4368 | 719 | $query .= ' '.$this->table_options; | 735 | $query .= ' '.$this->table_options; |
4369 | 720 | } | 736 | } |
4370 | 721 | } | 737 | } |
4371 | 722 | } | 738 | } |
4374 | 723 | elseif( ! empty($this->table_options) ) | 739 | elseif( ! empty( $this->table_options ) ) |
4375 | 724 | { // No aliases, but table_options: | 740 | { |
4376 | 741 | // No aliases, but table_options | ||
4377 | 725 | if( preg_match( '#^ \s* create \s* table \s #ix', $query) ) | 742 | if( preg_match( '#^ \s* create \s* table \s #ix', $query) ) |
4379 | 726 | { // Query is a table creation, we add table options: | 743 | { |
4380 | 744 | // Query is a table creation, we add table options | ||
4381 | 727 | $query = preg_replace( '~;\s*$~', '', $query ); // remove any ";" at the end | 745 | $query = preg_replace( '~;\s*$~', '', $query ); // remove any ";" at the end |
4382 | 728 | $query .= $this->table_options; | 746 | $query .= $this->table_options; |
4383 | 729 | } | 747 | } |
4384 | 730 | } | 748 | } |
4385 | 731 | 749 | ||
4387 | 732 | // Keep track of the last query for debug.. | 750 | // Keep track of the last query for debug |
4388 | 733 | $this->last_query = $query; | 751 | $this->last_query = $query; |
4389 | 734 | 752 | ||
4391 | 735 | // Perform the query via std mysql_query function.. | 753 | // Perform the query via std mysql_query function |
4392 | 736 | $this->num_queries++; | 754 | $this->num_queries++; |
4393 | 737 | 755 | ||
4394 | 738 | if( $this->log_queries ) | 756 | if( $this->log_queries ) |
4397 | 739 | { // We want to log queries: | 757 | { |
4398 | 740 | $this->queries[ $this->num_queries - 1 ] = array( | 758 | // We want to log queries |
4399 | 759 | $this->queries[$this->num_queries-1] = array( | ||
4400 | 741 | 'title' => $title, | 760 | 'title' => $title, |
4401 | 742 | 'sql' => $query, | 761 | 'sql' => $query, |
4402 | 743 | 'rows' => -1, | 762 | 'rows' => -1, |
4403 | @@ -745,67 +764,73 @@ | |||
4404 | 745 | 'results' => 'unknown' ); | 764 | 'results' => 'unknown' ); |
4405 | 746 | } | 765 | } |
4406 | 747 | 766 | ||
4408 | 748 | if( is_object($Timer) ) | 767 | if( is_object( $Timer ) ) |
4409 | 749 | { | 768 | { |
4410 | 750 | // Resume global query timer | 769 | // Resume global query timer |
4411 | 751 | $Timer->resume( 'sql_queries' ); | 770 | $Timer->resume( 'sql_queries' ); |
4413 | 752 | // Start a timer for this particular query: | 771 | // Start a timer for this particular query |
4414 | 753 | $Timer->start( 'sql_query', false ); | 772 | $Timer->start( 'sql_query', false ); |
4415 | 754 | 773 | ||
4417 | 755 | // Run query: | 774 | // Run query |
4418 | 756 | $this->result = @mysql_query( $query, $this->dbhandle ); | 775 | $this->result = @mysql_query( $query, $this->dbhandle ); |
4419 | 757 | 776 | ||
4420 | 758 | if( $this->log_queries ) | 777 | if( $this->log_queries ) |
4424 | 759 | { // We want to log queries: | 778 | { |
4425 | 760 | // Get duration for last query: | 779 | // We want to log queries |
4426 | 761 | $this->queries[ $this->num_queries - 1 ]['time'] = $Timer->get_duration( 'sql_query', 10 ); | 780 | // Get duration for last query |
4427 | 781 | $this->queries[$this->num_queries-1]['time'] = $Timer->get_duration( 'sql_query', 10 ); | ||
4428 | 762 | } | 782 | } |
4429 | 763 | 783 | ||
4431 | 764 | // Pause global query timer: | 784 | // Pause global query timer |
4432 | 765 | $Timer->pause( 'sql_queries' ); | 785 | $Timer->pause( 'sql_queries' ); |
4433 | 766 | } | 786 | } |
4434 | 767 | else | 787 | else |
4435 | 768 | { | 788 | { |
4437 | 769 | // Run query: | 789 | // Run query |
4438 | 770 | $this->result = @mysql_query( $query, $this->dbhandle ); | 790 | $this->result = @mysql_query( $query, $this->dbhandle ); |
4439 | 771 | } | 791 | } |
4440 | 772 | 792 | ||
4443 | 773 | // If there is an error then take note of it.. | 793 | // If there is an error then take note of it |
4444 | 774 | if( is_resource($this->dbhandle) && mysql_error($this->dbhandle) ) | 794 | if( is_resource( $this->dbhandle ) && mysql_error( $this->dbhandle ) ) |
4445 | 775 | { | 795 | { |
4447 | 776 | @mysql_free_result($this->result); | 796 | @mysql_free_result( $this->result ); |
4448 | 777 | $this->print_error( '', '', $title ); | 797 | $this->print_error( '', '', $title ); |
4449 | 778 | return false; | 798 | return false; |
4450 | 779 | } | 799 | } |
4451 | 780 | 800 | ||
4452 | 781 | if( preg_match( '#^\s*(INSERT|DELETE|UPDATE|REPLACE)\s#i', $query, $match ) ) | 801 | if( preg_match( '#^\s*(INSERT|DELETE|UPDATE|REPLACE)\s#i', $query, $match ) ) |
4454 | 782 | { // Query was an insert, delete, update, replace: | 802 | { |
4455 | 803 | // Query was an insert, delete, update, replace | ||
4456 | 783 | 804 | ||
4458 | 784 | $this->rows_affected = mysql_affected_rows($this->dbhandle); | 805 | $this->rows_affected = mysql_affected_rows( $this->dbhandle ); |
4459 | 785 | if( $this->log_queries ) | 806 | if( $this->log_queries ) |
4462 | 786 | { // We want to log queries: | 807 | { |
4463 | 787 | $this->queries[ $this->num_queries - 1 ]['rows'] = $this->rows_affected; | 808 | // We want to log queries |
4464 | 809 | $this->queries[$this->num_queries-1]['rows'] = $this->rows_affected; | ||
4465 | 788 | } | 810 | } |
4466 | 789 | 811 | ||
4469 | 790 | // Take note of the insert_id, for INSERT and REPLACE: | 812 | // Take note of the insert_id, for INSERT and REPLACE |
4470 | 791 | $match[1] = strtoupper($match[1]); | 813 | $match[1] = strtoupper( $match[1] ); |
4471 | 792 | if( $match[1] == 'INSERT' || $match[1] == 'REPLACE' ) | 814 | if( $match[1] == 'INSERT' || $match[1] == 'REPLACE' ) |
4472 | 793 | { | 815 | { |
4474 | 794 | $this->insert_id = mysql_insert_id($this->dbhandle); | 816 | $this->insert_id = mysql_insert_id( $this->dbhandle ); |
4475 | 795 | } | 817 | } |
4476 | 796 | 818 | ||
4477 | 797 | // Return number of rows affected | 819 | // Return number of rows affected |
4478 | 798 | $return_val = $this->rows_affected; | 820 | $return_val = $this->rows_affected; |
4479 | 799 | } | 821 | } |
4480 | 800 | else | 822 | else |
4482 | 801 | { // Query was a select, alter, etc...: | 823 | { |
4483 | 824 | // Query was a select, alter, etc...: | ||
4484 | 802 | $this->num_rows = 0; | 825 | $this->num_rows = 0; |
4485 | 803 | 826 | ||
4488 | 804 | if( is_resource($this->result) ) | 827 | if( is_resource( $this->result ) ) |
4489 | 805 | { // It's not a resource for CREATE or DROP for example and can even trigger a fatal error (see http://forums.b2evolution.net//viewtopic.php?t=9529) | 828 | { |
4490 | 829 | // It's not a resource for CREATE or DROP for example and can even trigger | ||
4491 | 830 | // a fatal error (see http://forums.b2evolution.net//viewtopic.php?t=9529) | ||
4492 | 806 | 831 | ||
4493 | 807 | // Store Query Results | 832 | // Store Query Results |
4495 | 808 | while( $row = mysql_fetch_object($this->result) ) | 833 | while( $row = mysql_fetch_object( $this->result ) ) |
4496 | 809 | { | 834 | { |
4497 | 810 | // Store relults as an objects within main array | 835 | // Store relults as an objects within main array |
4498 | 811 | $this->last_result[$this->num_rows] = $row; | 836 | $this->last_result[$this->num_rows] = $row; |
4499 | @@ -814,8 +839,9 @@ | |||
4500 | 814 | } | 839 | } |
4501 | 815 | 840 | ||
4502 | 816 | if( $this->log_queries ) | 841 | if( $this->log_queries ) |
4505 | 817 | { // We want to log queries: | 842 | { |
4506 | 818 | $this->queries[ $this->num_queries - 1 ]['rows'] = $this->num_rows; | 843 | // We want to log queries |
4507 | 844 | $this->queries[$this->num_queries-1]['rows'] = $this->num_rows; | ||
4508 | 819 | } | 845 | } |
4509 | 820 | 846 | ||
4510 | 821 | // Return number of rows selected | 847 | // Return number of rows selected |
4511 | @@ -823,26 +849,28 @@ | |||
4512 | 823 | } | 849 | } |
4513 | 824 | 850 | ||
4514 | 825 | if( $this->log_queries ) | 851 | if( $this->log_queries ) |
4516 | 826 | { // We want to log queries: | 852 | { |
4517 | 853 | // We want to log queries | ||
4518 | 827 | if( $this->debug_dump_function_trace_for_queries ) | 854 | if( $this->debug_dump_function_trace_for_queries ) |
4519 | 828 | { | 855 | { |
4521 | 829 | $this->queries[ $this->num_queries - 1 ]['function_trace'] = debug_get_backtrace( $this->debug_dump_function_trace_for_queries, array( array( 'class' => 'DB' ) ), 1 ); // including first stack entry from class DB | 856 | $this->queries[$this->num_queries-1]['function_trace'] = debug_get_backtrace( $this->debug_dump_function_trace_for_queries, array( array( 'class' => 'DB' ) ), 1 ); // including first stack entry from class DB |
4522 | 830 | } | 857 | } |
4523 | 831 | 858 | ||
4524 | 832 | if( $this->debug_dump_rows ) | 859 | if( $this->debug_dump_rows ) |
4525 | 833 | { | 860 | { |
4527 | 834 | $this->queries[ $this->num_queries - 1 ]['results'] = $this->debug_get_rows_table( $this->debug_dump_rows ); | 861 | $this->queries[$this->num_queries-1]['results'] = $this->debug_get_rows_table( $this->debug_dump_rows ); |
4528 | 835 | } | 862 | } |
4529 | 836 | } | 863 | } |
4530 | 837 | 864 | ||
4533 | 838 | // Free original query's result: | 865 | // Free original query's result |
4534 | 839 | @mysql_free_result($this->result); | 866 | @mysql_free_result( $this->result ); |
4535 | 840 | 867 | ||
4536 | 841 | // EXPLAIN JOINS ?? | 868 | // EXPLAIN JOINS ?? |
4537 | 842 | if( $this->log_queries && $this->debug_explain_joins && preg_match( '#^ [\s(]* SELECT \s #ix', $query) ) | 869 | if( $this->log_queries && $this->debug_explain_joins && preg_match( '#^ [\s(]* SELECT \s #ix', $query) ) |
4539 | 843 | { // Query was a select, let's try to explain joins... | 870 | { |
4540 | 871 | // Query was a select, let's try to explain joins... | ||
4541 | 844 | 872 | ||
4543 | 845 | // save values: | 873 | // save values |
4544 | 846 | $saved_last_result = $this->last_result; | 874 | $saved_last_result = $this->last_result; |
4545 | 847 | $saved_num_rows = $this->num_rows; | 875 | $saved_num_rows = $this->num_rows; |
4546 | 848 | 876 | ||
4547 | @@ -853,19 +881,19 @@ | |||
4548 | 853 | 881 | ||
4549 | 854 | // Store Query Results | 882 | // Store Query Results |
4550 | 855 | $this->num_rows = 0; | 883 | $this->num_rows = 0; |
4552 | 856 | while( $row = @mysql_fetch_object($this->result) ) | 884 | while( $row = @mysql_fetch_object( $this->result ) ) |
4553 | 857 | { | 885 | { |
4554 | 858 | // Store results as an objects within main array | 886 | // Store results as an objects within main array |
4555 | 859 | $this->last_result[$this->num_rows] = $row; | 887 | $this->last_result[$this->num_rows] = $row; |
4556 | 860 | $this->num_rows++; | 888 | $this->num_rows++; |
4557 | 861 | } | 889 | } |
4558 | 862 | 890 | ||
4565 | 863 | $this->queries[ $this->num_queries - 1 ]['explain'] = $this->debug_get_rows_table( 100, true ); | 891 | $this->queries[$this->num_queries-1]['explain'] = $this->debug_get_rows_table( 100, true ); |
4566 | 864 | 892 | ||
4567 | 865 | // Free "EXPLAIN" result resource: | 893 | // Free "EXPLAIN" result resource |
4568 | 866 | @mysql_free_result($this->result); | 894 | @mysql_free_result( $this->result ); |
4569 | 867 | 895 | ||
4570 | 868 | // Restore: | 896 | // Restore |
4571 | 869 | $this->last_result = $saved_last_result; | 897 | $this->last_result = $saved_last_result; |
4572 | 870 | $this->num_rows = $saved_num_rows; | 898 | $this->num_rows = $saved_num_rows; |
4573 | 871 | } | 899 | } |
4574 | @@ -875,28 +903,28 @@ | |||
4575 | 875 | 903 | ||
4576 | 876 | 904 | ||
4577 | 877 | /** | 905 | /** |
4579 | 878 | * Get one variable from the DB - see docs for more detail | 906 | * Get one variable from the DB |
4580 | 879 | * | 907 | * |
4581 | 880 | * Note: To be sure that you received NULL from the DB and not "no rows" check | 908 | * Note: To be sure that you received NULL from the DB and not "no rows" check |
4583 | 881 | * for {@link $num_rows}. | 909 | * for {@link $num_rows}. |
4584 | 882 | * | 910 | * |
4585 | 883 | * @return mixed NULL if not found, the value otherwise (which may also be NULL). | 911 | * @return mixed NULL if not found, the value otherwise (which may also be NULL). |
4586 | 884 | */ | 912 | */ |
4587 | 885 | function get_var( $query = NULL, $x = 0, $y = 0, $title = '' ) | 913 | function get_var( $query = NULL, $x = 0, $y = 0, $title = '' ) |
4588 | 886 | { | 914 | { |
4590 | 887 | // If there is a query then perform it if not then use cached results.. | 915 | // If there is a query then perform it if not then use cached results |
4591 | 888 | if( $query ) | 916 | if( $query ) |
4592 | 889 | { | 917 | { |
4594 | 890 | $this->query($query, $title); | 918 | $this->query( $query, $title ); |
4595 | 891 | } | 919 | } |
4596 | 892 | 920 | ||
4597 | 893 | // Extract var out of cached results based x,y vals | 921 | // Extract var out of cached results based x,y vals |
4598 | 894 | if( $this->last_result[$y] ) | 922 | if( $this->last_result[$y] ) |
4599 | 895 | { | 923 | { |
4601 | 896 | $values = array_values(get_object_vars($this->last_result[$y])); | 924 | $values = array_values( get_object_vars( $this->last_result[$y] ) ); |
4602 | 897 | } | 925 | } |
4603 | 898 | 926 | ||
4605 | 899 | if( isset($values[$x]) ) | 927 | if( isset( $values[$x] ) ) |
4606 | 900 | { | 928 | { |
4607 | 901 | return $values[$x]; | 929 | return $values[$x]; |
4608 | 902 | } | 930 | } |
4609 | @@ -906,40 +934,40 @@ | |||
4610 | 906 | 934 | ||
4611 | 907 | 935 | ||
4612 | 908 | /** | 936 | /** |
4614 | 909 | * Get one row from the DB - see docs for more detail | 937 | * Get one row from the DB |
4615 | 910 | * | 938 | * |
4616 | 911 | * @return mixed | 939 | * @return mixed |
4617 | 912 | */ | 940 | */ |
4618 | 913 | function get_row( $query = NULL, $output = OBJECT, $y = 0, $title = '' ) | 941 | function get_row( $query = NULL, $output = OBJECT, $y = 0, $title = '' ) |
4619 | 914 | { | 942 | { |
4621 | 915 | // If there is a query then perform it if not then use cached results.. | 943 | // If there is a query then perform it if not then use cached results |
4622 | 916 | if( $query ) | 944 | if( $query ) |
4623 | 917 | { | 945 | { |
4625 | 918 | $this->query($query, $title); | 946 | $this->query( $query, $title ); |
4626 | 919 | } | 947 | } |
4627 | 920 | 948 | ||
4629 | 921 | // If the output is an object then return object using the row offset.. | 949 | // If the output is an object then return object using the row offset |
4630 | 922 | if( $output == OBJECT ) | 950 | if( $output == OBJECT ) |
4631 | 923 | { | 951 | { |
4632 | 924 | return $this->last_result[$y] | 952 | return $this->last_result[$y] |
4633 | 925 | ? $this->last_result[$y] | 953 | ? $this->last_result[$y] |
4634 | 926 | : NULL; | 954 | : NULL; |
4635 | 927 | } | 955 | } |
4637 | 928 | // If the output is an associative array then return row as such.. | 956 | // If the output is an associative array then return row as such |
4638 | 929 | elseif( $output == ARRAY_A ) | 957 | elseif( $output == ARRAY_A ) |
4639 | 930 | { | 958 | { |
4640 | 931 | return $this->last_result[$y] | 959 | return $this->last_result[$y] |
4641 | 932 | ? get_object_vars( $this->last_result[$y] ) | 960 | ? get_object_vars( $this->last_result[$y] ) |
4642 | 933 | : array(); | 961 | : array(); |
4643 | 934 | } | 962 | } |
4645 | 935 | // If the output is an numerical array then return row as such.. | 963 | // If the output is an numerical array then return row as such |
4646 | 936 | elseif( $output == ARRAY_N ) | 964 | elseif( $output == ARRAY_N ) |
4647 | 937 | { | 965 | { |
4648 | 938 | return $this->last_result[$y] | 966 | return $this->last_result[$y] |
4650 | 939 | ? array_values( get_object_vars($this->last_result[$y]) ) | 967 | ? array_values( get_object_vars( $this->last_result[$y] ) ) |
4651 | 940 | : array(); | 968 | : array(); |
4652 | 941 | } | 969 | } |
4654 | 942 | // If invalid output type was specified.. | 970 | // If invalid output type was specified |
4655 | 943 | else | 971 | else |
4656 | 944 | { | 972 | { |
4657 | 945 | $this->print_error('DB::get_row(string query, output type, int offset) -- Output type must be one of: OBJECT, ARRAY_A, ARRAY_N', '', false); | 973 | $this->print_error('DB::get_row(string query, output type, int offset) -- Output type must be one of: OBJECT, ARRAY_A, ARRAY_N', '', false); |
4658 | @@ -949,13 +977,12 @@ | |||
4659 | 949 | 977 | ||
4660 | 950 | /** | 978 | /** |
4661 | 951 | * Function to get 1 column from the cached result set based on X index | 979 | * Function to get 1 column from the cached result set based on X index |
4662 | 952 | * see docs for usage and info | ||
4663 | 953 | * | 980 | * |
4664 | 954 | * @return array | 981 | * @return array |
4665 | 955 | */ | 982 | */ |
4666 | 956 | function get_col( $query = NULL, $x = 0, $title = '' ) | 983 | function get_col( $query = NULL, $x = 0, $title = '' ) |
4667 | 957 | { | 984 | { |
4669 | 958 | // If there is a query then perform it if not then use cached results.. | 985 | // If there is a query then perform it if not then use cached results |
4670 | 959 | if( $query ) | 986 | if( $query ) |
4671 | 960 | { | 987 | { |
4672 | 961 | $this->query( $query, $title ); | 988 | $this->query( $query, $title ); |
4673 | @@ -963,7 +990,7 @@ | |||
4674 | 963 | 990 | ||
4675 | 964 | // Extract the column values | 991 | // Extract the column values |
4676 | 965 | $new_array = array(); | 992 | $new_array = array(); |
4678 | 966 | for( $i = 0, $count = count($this->last_result); $i < $count; $i++ ) | 993 | for( $i = 0, $count = count( $this->last_result ); $i < $count; $i++ ) |
4679 | 967 | { | 994 | { |
4680 | 968 | $new_array[$i] = $this->get_var( NULL, $x, $i ); | 995 | $new_array[$i] = $this->get_var( NULL, $x, $i ); |
4681 | 969 | } | 996 | } |
4682 | @@ -979,7 +1006,7 @@ | |||
4683 | 979 | */ | 1006 | */ |
4684 | 980 | function get_assoc( $query = NULL, $title = '' ) | 1007 | function get_assoc( $query = NULL, $title = '' ) |
4685 | 981 | { | 1008 | { |
4687 | 982 | // If there is a query then perform it if not then use cached results.. | 1009 | // If there is a query then perform it if not then use cached results |
4688 | 983 | if( $query ) | 1010 | if( $query ) |
4689 | 984 | { | 1011 | { |
4690 | 985 | $this->query( $query, $title ); | 1012 | $this->query( $query, $title ); |
4691 | @@ -987,7 +1014,7 @@ | |||
4692 | 987 | 1014 | ||
4693 | 988 | // Extract the column values | 1015 | // Extract the column values |
4694 | 989 | $new_array = array(); | 1016 | $new_array = array(); |
4696 | 990 | for( $i = 0, $count = count($this->last_result); $i < $count; $i++ ) | 1017 | for( $i = 0, $count = count( $this->last_result ); $i < $count; $i++ ) |
4697 | 991 | { | 1018 | { |
4698 | 992 | $key = $this->get_var( NULL, 0, $i ); | 1019 | $key = $this->get_var( NULL, 0, $i ); |
4699 | 993 | 1020 | ||
4700 | @@ -999,16 +1026,16 @@ | |||
4701 | 999 | 1026 | ||
4702 | 1000 | 1027 | ||
4703 | 1001 | /** | 1028 | /** |
4705 | 1002 | * Return the the query as a result set - see docs for more details | 1029 | * Return the the query as a result set |
4706 | 1003 | * | 1030 | * |
4707 | 1004 | * @return mixed | 1031 | * @return mixed |
4708 | 1005 | */ | 1032 | */ |
4709 | 1006 | function get_results( $query = NULL, $output = OBJECT, $title = '' ) | 1033 | function get_results( $query = NULL, $output = OBJECT, $title = '' ) |
4710 | 1007 | { | 1034 | { |
4712 | 1008 | // If there is a query then perform it if not then use cached results.. | 1035 | // If there is a query then perform it if not then use cached results |
4713 | 1009 | if( $query ) | 1036 | if( $query ) |
4714 | 1010 | { | 1037 | { |
4716 | 1011 | $this->query($query, $title); | 1038 | $this->query( $query, $title ); |
4717 | 1012 | } | 1039 | } |
4718 | 1013 | 1040 | ||
4719 | 1014 | // Send back array of objects. Each row is an object | 1041 | // Send back array of objects. Each row is an object |
4720 | @@ -1026,11 +1053,11 @@ | |||
4721 | 1026 | 1053 | ||
4722 | 1027 | foreach( $this->last_result as $row ) | 1054 | foreach( $this->last_result as $row ) |
4723 | 1028 | { | 1055 | { |
4725 | 1029 | $new_array[$i] = get_object_vars($row); | 1056 | $new_array[$i] = get_object_vars( $row ); |
4726 | 1030 | 1057 | ||
4727 | 1031 | if( $output == ARRAY_N ) | 1058 | if( $output == ARRAY_N ) |
4728 | 1032 | { | 1059 | { |
4730 | 1033 | $new_array[$i] = array_values($new_array[$i]); | 1060 | $new_array[$i] = array_values( $new_array[$i] ); |
4731 | 1034 | } | 1061 | } |
4732 | 1035 | 1062 | ||
4733 | 1036 | $i++; | 1063 | $i++; |
4734 | @@ -1047,7 +1074,7 @@ | |||
4735 | 1047 | 1074 | ||
4736 | 1048 | 1075 | ||
4737 | 1049 | /** | 1076 | /** |
4739 | 1050 | * Get a table (or "<p>No Results.</p>") for the SELECT query results. | 1077 | * Get a table (or "<p>No Results.</p>") for the SELECT query results |
4740 | 1051 | * | 1078 | * |
4741 | 1052 | * @return string HTML table or "No Results" if the | 1079 | * @return string HTML table or "No Results" if the |
4742 | 1053 | */ | 1080 | */ |
4743 | @@ -1055,36 +1082,34 @@ | |||
4744 | 1055 | { | 1082 | { |
4745 | 1056 | $r = ''; | 1083 | $r = ''; |
4746 | 1057 | 1084 | ||
4748 | 1058 | if( ! is_resource($this->result) ) | 1085 | if( ! is_resource( $this->result ) ) |
4749 | 1059 | { | 1086 | { |
4750 | 1060 | return '<p>No Results.</p>'; | 1087 | return '<p>No Results.</p>'; |
4751 | 1061 | } | 1088 | } |
4752 | 1062 | 1089 | ||
4754 | 1063 | // Get column info: | 1090 | // Get column info |
4755 | 1064 | $col_info = array(); | 1091 | $col_info = array(); |
4757 | 1065 | $n = mysql_num_fields($this->result); | 1092 | $n = mysql_num_fields( $this->result ); |
4758 | 1066 | $i = 0; | 1093 | $i = 0; |
4759 | 1067 | while( $i < $n ) | 1094 | while( $i < $n ) |
4760 | 1068 | { | 1095 | { |
4762 | 1069 | $col_info[$i] = mysql_fetch_field($this->result, $i); | 1096 | $col_info[$i] = mysql_fetch_field( $this->result, $i ); |
4763 | 1070 | $i++; | 1097 | $i++; |
4764 | 1071 | } | 1098 | } |
4765 | 1072 | 1099 | ||
4766 | 1073 | // ===================================================== | ||
4767 | 1074 | // Results top rows | 1100 | // Results top rows |
4768 | 1075 | $r .= '<table cellspacing="0" summary="Results for query"><tr>'; | 1101 | $r .= '<table cellspacing="0" summary="Results for query"><tr>'; |
4770 | 1076 | for( $i = 0, $count = count($col_info); $i < $count; $i++ ) | 1102 | for( $i = 0, $count = count( $col_info ); $i < $count; $i++ ) |
4771 | 1077 | { | 1103 | { |
4772 | 1078 | $r .= '<th><span class="type">'.$col_info[$i]->type.' '.$col_info[$i]->max_length.'</span><br />' | 1104 | $r .= '<th><span class="type">'.$col_info[$i]->type.' '.$col_info[$i]->max_length.'</span><br />' |
4773 | 1079 | .$col_info[$i]->name.'</th>'; | 1105 | .$col_info[$i]->name.'</th>'; |
4774 | 1080 | } | 1106 | } |
4775 | 1081 | $r .= '</tr>'; | 1107 | $r .= '</tr>'; |
4776 | 1082 | 1108 | ||
4777 | 1083 | // ====================================================== | ||
4778 | 1084 | // print main results | 1109 | // print main results |
4779 | 1085 | if( $this->last_result ) | 1110 | if( $this->last_result ) |
4780 | 1086 | { | 1111 | { |
4782 | 1087 | for( $i = 0, $n = min(count($this->last_result), $max_lines); $i < $n; $i++ ) | 1112 | for( $i = 0, $n = min( count( $this->last_result ), $max_lines ); $i < $n; $i++ ) |
4783 | 1088 | { | 1113 | { |
4784 | 1089 | $one_row = $this->get_row(NULL, ARRAY_N, $i); | 1114 | $one_row = $this->get_row(NULL, ARRAY_N, $i); |
4785 | 1090 | $r .= '<tr>'; | 1115 | $r .= '<tr>'; |
4786 | @@ -1111,7 +1136,7 @@ | |||
4787 | 1111 | { | 1136 | { |
4788 | 1112 | $item = substr( $item, 0, 50 ).'...'; | 1137 | $item = substr( $item, 0, 50 ).'...'; |
4789 | 1113 | } | 1138 | } |
4791 | 1114 | $r .= htmlspecialchars($item); | 1139 | $r .= htmlspecialchars( $item ); |
4792 | 1115 | } | 1140 | } |
4793 | 1116 | $r .= '</td>'; | 1141 | $r .= '</td>'; |
4794 | 1117 | } | 1142 | } |
4795 | @@ -1119,14 +1144,14 @@ | |||
4796 | 1119 | $r .= '</tr>'; | 1144 | $r .= '</tr>'; |
4797 | 1120 | } | 1145 | } |
4798 | 1121 | 1146 | ||
4800 | 1122 | } // if last result | 1147 | } |
4801 | 1123 | else | 1148 | else |
4802 | 1124 | { | 1149 | { |
4804 | 1125 | $r .= '<tr><td colspan="'.(count($col_info)+1).'">No Results</td></tr>'; | 1150 | $r .= '<tr><td colspan="'.( count( $col_info )+1 ).'">No Results</td></tr>'; |
4805 | 1126 | } | 1151 | } |
4806 | 1127 | if( $i >= $max_lines ) | 1152 | if( $i >= $max_lines ) |
4807 | 1128 | { | 1153 | { |
4809 | 1129 | $r .= '<tr><td colspan="'.(count($col_info)+1).'">Max number of dumped rows has been reached.</td></tr>'; | 1154 | $r .= '<tr><td colspan="'.( count( $col_info )+1 ).'">Max number of dumped rows has been reached.</td></tr>'; |
4810 | 1130 | } | 1155 | } |
4811 | 1131 | 1156 | ||
4812 | 1132 | $r .= '</table>'; | 1157 | $r .= '</table>'; |
4813 | @@ -1137,8 +1162,7 @@ | |||
4814 | 1137 | 1162 | ||
4815 | 1138 | /** | 1163 | /** |
4816 | 1139 | * Format a SQL query | 1164 | * Format a SQL query |
4819 | 1140 | * @static | 1165 | * |
4818 | 1141 | * @todo dh> Steal the code from phpMyAdmin :) | ||
4820 | 1142 | * @param string SQL | 1166 | * @param string SQL |
4821 | 1143 | * @param boolean Format with/for HTML? | 1167 | * @param boolean Format with/for HTML? |
4822 | 1144 | */ | 1168 | */ |
4823 | @@ -1156,7 +1180,6 @@ | |||
4824 | 1156 | } | 1180 | } |
4825 | 1157 | 1181 | ||
4826 | 1158 | // Split by FROM, WHERE, .. and AND, OR (if there's no comment sign before) | 1182 | // Split by FROM, WHERE, .. and AND, OR (if there's no comment sign before) |
4827 | 1159 | // TODO: dh> should not wrap in comments/string literals | ||
4828 | 1160 | $search = array( | 1183 | $search = array( |
4829 | 1161 | '~(FROM|WHERE|GROUP BY|ORDER BY|LIMIT|VALUES)~', | 1184 | '~(FROM|WHERE|GROUP BY|ORDER BY|LIMIT|VALUES)~', |
4830 | 1162 | '~(AND |OR )~', | 1185 | '~(AND |OR )~', |
4831 | @@ -1179,6 +1202,7 @@ | |||
4832 | 1179 | function dump_queries( $html = true ) | 1202 | function dump_queries( $html = true ) |
4833 | 1180 | { | 1203 | { |
4834 | 1181 | global $Timer; | 1204 | global $Timer; |
4835 | 1205 | |||
4836 | 1182 | if( is_object( $Timer ) ) | 1206 | if( is_object( $Timer ) ) |
4837 | 1183 | { | 1207 | { |
4838 | 1184 | $time_queries = $Timer->get_duration( 'sql_queries' ); | 1208 | $time_queries = $Timer->get_duration( 'sql_queries' ); |
4839 | @@ -1191,7 +1215,7 @@ | |||
4840 | 1191 | $count_queries = 0; | 1215 | $count_queries = 0; |
4841 | 1192 | $count_rows = 0; | 1216 | $count_rows = 0; |
4842 | 1193 | 1217 | ||
4844 | 1194 | if ( $html ) | 1218 | if( $html ) |
4845 | 1195 | { | 1219 | { |
4846 | 1196 | echo '<strong>DB queries:</strong> '.$this->num_queries."<br />\n"; | 1220 | echo '<strong>DB queries:</strong> '.$this->num_queries."<br />\n"; |
4847 | 1197 | } | 1221 | } |
4848 | @@ -1201,11 +1225,12 @@ | |||
4849 | 1201 | } | 1225 | } |
4850 | 1202 | 1226 | ||
4851 | 1203 | if( ! $this->log_queries ) | 1227 | if( ! $this->log_queries ) |
4853 | 1204 | { // nothing more to do here.. | 1228 | { |
4854 | 1229 | // nothing more to do here | ||
4855 | 1205 | return; | 1230 | return; |
4856 | 1206 | } | 1231 | } |
4857 | 1207 | 1232 | ||
4859 | 1208 | // Javascript function to toggle DIVs (EXPLAIN, results, backtraces). | 1233 | // Javascript function to toggle DIVs (EXPLAIN, results, backtraces) |
4860 | 1209 | if( $html ) | 1234 | if( $html ) |
4861 | 1210 | { | 1235 | { |
4862 | 1211 | echo '<script type="text/javascript"> | 1236 | echo '<script type="text/javascript"> |
4863 | @@ -1232,11 +1257,13 @@ | |||
4864 | 1232 | </script>'; | 1257 | </script>'; |
4865 | 1233 | } | 1258 | } |
4866 | 1234 | 1259 | ||
4867 | 1260 | ?><?php | ||
4868 | 1261 | |||
4869 | 1235 | foreach( $this->queries as $i => $query ) | 1262 | foreach( $this->queries as $i => $query ) |
4870 | 1236 | { | 1263 | { |
4871 | 1237 | $count_queries++; | 1264 | $count_queries++; |
4872 | 1238 | 1265 | ||
4874 | 1239 | if ( $html ) | 1266 | if( $html ) |
4875 | 1240 | { | 1267 | { |
4876 | 1241 | echo '<h4>Query #'.$count_queries.': '.$query['title']."</h4>\n"; | 1268 | echo '<h4>Query #'.$count_queries.': '.$query['title']."</h4>\n"; |
4877 | 1242 | echo '<code>'; | 1269 | echo '<code>'; |
4878 | @@ -1270,7 +1297,7 @@ | |||
4879 | 1270 | } | 1297 | } |
4880 | 1271 | 1298 | ||
4881 | 1272 | // Number of rows with time (percentage and graph, if total time available) | 1299 | // Number of rows with time (percentage and graph, if total time available) |
4883 | 1273 | if ( $html ) | 1300 | if( $html ) |
4884 | 1274 | { | 1301 | { |
4885 | 1275 | echo '<div class="query_info">'; | 1302 | echo '<div class="query_info">'; |
4886 | 1276 | echo 'Rows: '.$query['rows']; | 1303 | echo 'Rows: '.$query['rows']; |
4887 | @@ -1289,7 +1316,8 @@ | |||
4888 | 1289 | echo number_format( $query['time'], 4 ).'s'; | 1316 | echo number_format( $query['time'], 4 ).'s'; |
4889 | 1290 | 1317 | ||
4890 | 1291 | if( $time_queries > 0 ) | 1318 | if( $time_queries > 0 ) |
4892 | 1292 | { // We have a total time we can use to calculate percentage: | 1319 | { |
4893 | 1320 | // We have a total time we can use to calculate percentage | ||
4894 | 1293 | echo ' ('.number_format( 100/$time_queries * $query['time'], 2 ).'%)'; | 1321 | echo ' ('.number_format( 100/$time_queries * $query['time'], 2 ).'%)'; |
4895 | 1294 | } | 1322 | } |
4896 | 1295 | 1323 | ||
4897 | @@ -1299,67 +1327,72 @@ | |||
4898 | 1299 | } | 1327 | } |
4899 | 1300 | 1328 | ||
4900 | 1301 | if( $time_queries > 0 ) | 1329 | if( $time_queries > 0 ) |
4902 | 1302 | { // We have a total time we can use to display a graph/bar: | 1330 | { |
4903 | 1331 | // We have a total time we can use to display a graph/bar | ||
4904 | 1303 | $perc = round( 100/$time_queries * $query['time'] ); | 1332 | $perc = round( 100/$time_queries * $query['time'] ); |
4905 | 1304 | 1333 | ||
4907 | 1305 | if ( $html ) | 1334 | if( $html ) |
4908 | 1306 | { | 1335 | { |
4909 | 1307 | echo '<div style="margin:0; padding:0; height:12px; width:'.$perc.'%;'.$style_time_graph.'"></div>'; | 1336 | echo '<div style="margin:0; padding:0; height:12px; width:'.$perc.'%;'.$style_time_graph.'"></div>'; |
4910 | 1308 | } | 1337 | } |
4911 | 1309 | else | 1338 | else |
4913 | 1310 | { // display an ASCII bar | 1339 | { |
4914 | 1340 | // display an ASCII bar | ||
4915 | 1311 | printf( "\n".'[%-50s]', str_repeat( '=', $perc / 2 ) ); | 1341 | printf( "\n".'[%-50s]', str_repeat( '=', $perc / 2 ) ); |
4916 | 1312 | } | 1342 | } |
4917 | 1313 | } | 1343 | } |
4918 | 1314 | echo $html ? '</div>' : "\n\n"; | 1344 | echo $html ? '</div>' : "\n\n"; |
4919 | 1315 | 1345 | ||
4922 | 1316 | // Explain: | 1346 | // Explain |
4923 | 1317 | if( isset($query['explain']) ) | 1347 | if( isset( $query['explain'] ) ) |
4924 | 1318 | { | 1348 | { |
4925 | 1319 | if( $html ) | 1349 | if( $html ) |
4926 | 1320 | { | 1350 | { |
4928 | 1321 | $div_id = 'db_query_explain_'.$i.'_'.md5(serialize($query)); | 1351 | $div_id = 'db_query_explain_'.$i.'_'.md5( serialize( $query ) ); |
4929 | 1322 | echo '<div id="'.$div_id.'">'; | 1352 | echo '<div id="'.$div_id.'">'; |
4930 | 1323 | echo $query['explain']; | 1353 | echo $query['explain']; |
4931 | 1324 | echo '</div>'; | 1354 | echo '</div>'; |
4932 | 1325 | echo '<script type="text/javascript">debug_onclick_toggle_div("'.$div_id.'", "Show EXPLAIN", "Hide EXPLAIN");</script>'; | 1355 | echo '<script type="text/javascript">debug_onclick_toggle_div("'.$div_id.'", "Show EXPLAIN", "Hide EXPLAIN");</script>'; |
4933 | 1326 | } | 1356 | } |
4934 | 1327 | else | 1357 | else |
4936 | 1328 | { // TODO: dh> contains html. | 1358 | { |
4937 | 1359 | // @todo (0000) dh> contains html | ||
4938 | 1329 | echo $query['explain']; | 1360 | echo $query['explain']; |
4939 | 1330 | } | 1361 | } |
4940 | 1331 | } | 1362 | } |
4941 | 1332 | 1363 | ||
4943 | 1333 | // Results: | 1364 | // Results |
4944 | 1334 | if( $query['results'] != 'unknown' ) | 1365 | if( $query['results'] != 'unknown' ) |
4945 | 1335 | { | 1366 | { |
4946 | 1336 | if( $html ) | 1367 | if( $html ) |
4947 | 1337 | { | 1368 | { |
4949 | 1338 | $div_id = 'db_query_results_'.$i.'_'.md5(serialize($query)); | 1369 | $div_id = 'db_query_results_'.$i.'_'.md5( serialize( $query ) ); |
4950 | 1339 | echo '<div id="'.$div_id.'">'; | 1370 | echo '<div id="'.$div_id.'">'; |
4951 | 1340 | echo $query['results']; | 1371 | echo $query['results']; |
4952 | 1341 | echo '</div>'; | 1372 | echo '</div>'; |
4953 | 1342 | echo '<script type="text/javascript">debug_onclick_toggle_div("'.$div_id.'", "Show results", "Hide results");</script>'; | 1373 | echo '<script type="text/javascript">debug_onclick_toggle_div("'.$div_id.'", "Show results", "Hide results");</script>'; |
4954 | 1343 | } | 1374 | } |
4955 | 1344 | else | 1375 | else |
4957 | 1345 | { // TODO: dh> contains html. | 1376 | { |
4958 | 1377 | // @todo (0000) dh> contains html. | ||
4959 | 1346 | echo $query['results']; | 1378 | echo $query['results']; |
4960 | 1347 | } | 1379 | } |
4961 | 1348 | } | 1380 | } |
4962 | 1349 | 1381 | ||
4963 | 1350 | // Function trace: | 1382 | // Function trace: |
4965 | 1351 | if( isset($query['function_trace']) ) | 1383 | if( isset( $query['function_trace'] ) ) |
4966 | 1352 | { | 1384 | { |
4967 | 1353 | if( $html ) | 1385 | if( $html ) |
4968 | 1354 | { | 1386 | { |
4970 | 1355 | $div_id = 'db_query_backtrace_'.$i.'_'.md5(serialize($query)); | 1387 | $div_id = 'db_query_backtrace_'.$i.'_'.md5( serialize( $query ) ); |
4971 | 1356 | echo '<div id="'.$div_id.'">'; | 1388 | echo '<div id="'.$div_id.'">'; |
4972 | 1357 | echo $query['function_trace']; | 1389 | echo $query['function_trace']; |
4973 | 1358 | echo '</div>'; | 1390 | echo '</div>'; |
4974 | 1359 | echo '<script type="text/javascript">debug_onclick_toggle_div("'.$div_id.'", "Show function trace", "Hide function trace");</script>'; | 1391 | echo '<script type="text/javascript">debug_onclick_toggle_div("'.$div_id.'", "Show function trace", "Hide function trace");</script>'; |
4975 | 1360 | } | 1392 | } |
4976 | 1361 | else | 1393 | else |
4978 | 1362 | { // TODO: dh> contains html. | 1394 | { |
4979 | 1395 | // @todo (0000) dh> contains html. | ||
4980 | 1363 | echo $query['function_trace']; | 1396 | echo $query['function_trace']; |
4981 | 1364 | } | 1397 | } |
4982 | 1365 | } | 1398 | } |
4983 | @@ -1376,7 +1409,7 @@ | |||
4984 | 1376 | $count_rows += $query['rows']; | 1409 | $count_rows += $query['rows']; |
4985 | 1377 | } | 1410 | } |
4986 | 1378 | 1411 | ||
4988 | 1379 | if ( $html ) | 1412 | if( $html ) |
4989 | 1380 | { | 1413 | { |
4990 | 1381 | echo "\n<strong>Total rows:</strong> $count_rows<br />\n"; | 1414 | echo "\n<strong>Total rows:</strong> $count_rows<br />\n"; |
4991 | 1382 | } | 1415 | } |
4992 | @@ -1390,14 +1423,13 @@ | |||
4993 | 1390 | /** | 1423 | /** |
4994 | 1391 | * BEGIN A TRANSCATION | 1424 | * BEGIN A TRANSCATION |
4995 | 1392 | * | 1425 | * |
4996 | 1393 | * Note: By default, MySQL runs with autocommit mode enabled. | ||
4997 | 1394 | * This means that as soon as you execute a statement that updates (modifies) | ||
4998 | 1395 | * a table, MySQL stores the update on disk. | ||
4999 | 1396 | * Once you execute a BEGIN, the updates are "pending" until you execute a | ||
5000 | 1397 | * {@link DB::commit() COMMIT} or a {@link DB:rollback() ROLLBACK} |
The diff has been truncated for viewing.