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