Merge lp:~quam-plures-core/quam-plures/bug-566226.tblue into lp:quam-plures

Proposed by Tilman Blumenbach
Status: Merged
Merged at revision: not available
Proposed branch: lp:~quam-plures-core/quam-plures/bug-566226.tblue
Merge into: lp:quam-plures
Diff against target: 217 lines (+51/-116)
3 files modified
inc/_core/_template.funcs.php (+1/-1)
inc/items/model/_itemlist.class.php (+50/-114)
inc/items/views/_item_expert.form.php (+0/-1)
To merge this branch: bzr merge lp:~quam-plures-core/quam-plures/bug-566226.tblue
Reviewer Review Type Date Requested Status
EdB Approve
Review via email: mp+23678@code.launchpad.net

Description of the change

This fixes bug 566226 by refactoring the preview code. It has gone from horrible to ugly, and that's an improvement!

To post a comment you must log in.
7465. By Tilman Blumenbach

Reverted useless fixing attempt

7466. By Tilman Blumenbach

[Minor] Fixed typo in comment

Revision history for this message
EdB (edb) wrote :

Will grab branch later today (local time of course) and give it a test run. Actually, I'll get the branch now and test it when I get back home :)

Revision history for this message
EdB (edb) wrote :

Yay! Will merge inaminitor2 cuz that's the way I roll

review: Approve
Revision history for this message
EdB (edb) wrote :

I think I broke something :(

It's been an hour and (a) this branch didn't figure out to get out of the "request to merge" section and (b) https://code.launchpad.net/~quam-plures-gatekeepers/quam-plures/trunk is still saying "updating branch blah blah blah reload in a few minutes".

Ruh roh!

Revision history for this message
Tilman Blumenbach (tblue) wrote :

I fixed it for you.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'inc/_core/_template.funcs.php'
2--- inc/_core/_template.funcs.php 2010-03-30 19:16:12 +0000
3+++ inc/_core/_template.funcs.php 2010-04-19 16:19:23 +0000
4@@ -884,7 +884,7 @@
5 {
6 $Item = & $MainList->get_item();
7
8- if( $Item && $Item->ID == $featured_displayed_item_ID )
9+ if( $Item && $Item->ID === $featured_displayed_item_ID )
10 { // This post was already displayed as a Featured post, let's skip it and get the next one:
11 $Item = & $MainList->get_item();
12 }
13
14=== modified file 'inc/items/model/_itemlist.class.php'
15--- inc/items/model/_itemlist.class.php 2010-02-19 10:50:37 +0000
16+++ inc/items/model/_itemlist.class.php 2010-04-19 16:19:23 +0000
17@@ -82,131 +82,53 @@
18 */
19 function preview_from_request()
20 {
21- global $current_User;
22+ global $current_User, $Plugins, $Messages, $localtimenow;
23+ global $post_category, $post_extracats, $post_status;
24
25 if( empty($current_User) )
26 { // dh> only logged in user's can preview. Alternatively we need those checks where $current_User gets used below.
27 return;
28 }
29
30- global $DB, $localtimenow, $Messages, $BlogCache;
31- global $Plugins;
32-
33- $preview_userid = param( 'preview_userid', 'integer', true );
34- $post_status = param( 'post_status', 'string', true );
35- $post_locale = param( 'post_locale', 'string', $current_User->locale );
36- $content = param( 'content', 'html', true );
37- $post_title = param( 'post_title', 'html', true );
38- $post_titletag = param( 'titletag', 'string', true );
39- $post_metadesc = param( 'metadesc', 'string', true );
40- $post_metakeywords = param( 'metakeywords', 'string', true );
41- $post_excerpt = param( 'post_excerpt', 'string', true );
42- $post_url = param( 'post_url', 'string', '' );
43- $post_category = param( 'post_category', 'integer', true );
44- $post_views = param( 'post_views', 'integer', 0 );
45- $renderers = param( 'renderers', 'array', array('default') );
46- if( ! is_array($renderers) )
47- { // dh> workaround for param() bug. See rev 1.93 of /inc/_misc/_misc.funcs.php
48- $renderers = array('default');
49- }
50- $comment_Blog = & $BlogCache->get_by_ID( get_catblog( $post_category ) );
51- if( $comment_Blog->allowcomments == 'post_by_post' )
52- { // param is required
53- $post_comment_status = param( 'post_comment_status', 'string', true );
54- }
55- else
56- {
57- $post_comment_status = $comment_Blog->allowcomments;
58- }
59-
60-
61- // Get issue date, using the user's locale (because it's entered like this in the form):
62- locale_temp_switch( $current_User->locale );
63-
64- param_date( 'item_issue_date', T_('Please enter a valid issue date.'), false );
65- // TODO: dh> get_param() is always true here, also on invalid dates:
66- if( strlen(get_param('item_issue_date')) )
67- { // only set it, if a date was given:
68- param_time( 'item_issue_time' );
69- $item_issue_date = form_date( get_param( 'item_issue_date' ), get_param( 'item_issue_time' ) ); // TODO: cleanup...
70- }
71- else
72- {
73- $item_issue_date = date( 'Y-m-d H:i:s', $localtimenow );
74- }
75- locale_restore_previous();
76-
77-
78- if( !($item_typ_ID = param( 'item_typ_ID', 'integer', NULL )) )
79- $item_typ_ID = NULL;
80- if( !($item_st_ID = param( 'item_st_ID', 'integer', NULL )) )
81- $item_st_ID = NULL;
82- if( !($item_assigned_user_ID = param( 'item_assigned_user_ID', 'integer', NULL )) )
83- $item_assigned_user_ID = NULL;
84- if( !($item_deadline = param( 'item_deadline', 'string', NULL )) )
85- $item_deadline = NULL;
86- $item_priority = param( 'item_priority', 'integer', NULL ); // QUESTION: can this be also empty/NULL?
87-
88- // Do some optional filtering on the content
89- // Typically stuff that will help the content to validate
90- // Useful for code display.
91- // Will probably be used for validation also.
92- $Plugins_admin = & get_Cache('Plugins_admin');
93- $Plugins_admin->filter_contents( $post_title /* by ref */, $content /* by ref */, $renderers );
94-
95- $post_title = format_to_post( $post_title );
96- $content = format_to_post( $content );
97-
98-
99- $this->sql = "SELECT
100- 0 AS post_ID,
101- $preview_userid AS post_creator_user_ID,
102- $preview_userid AS post_lastedit_user_ID,
103- '$item_issue_date' AS post_datestart,
104- '$item_issue_date' AS post_datecreated,
105- '$item_issue_date' AS post_datemodified,
106- '".$DB->escape($post_status)."' AS post_status,
107- '".$DB->escape($post_locale)."' AS post_locale,
108- '".$DB->escape($content)."' AS post_content,
109- '".$DB->escape($post_title)."' AS post_title,
110- '".$DB->escape($post_titletag)."' AS post_titletag,
111- '".$DB->escape($post_metadesc)."' AS post_metadesc,
112- '".$DB->escape($post_metakeywords)."' AS post_metakeywords,
113- '".$DB->escape($post_excerpt)."' AS post_excerpt,
114- NULL AS post_urltitle,
115- '".$DB->escape($post_url)."' AS post_url,
116- $post_category AS post_main_cat_ID,
117- $post_views AS post_views,
118- '' AS post_flags,
119- 'noreq' AS post_notifications_status,
120- NULL AS post_notifications_ctsk_ID,
121- ".bpost_count_words( $content )." AS post_wordcount,
122- ".$DB->quote($post_comment_status)." AS post_comment_status,
123- '".$DB->escape( implode( '.', $renderers ) )."' AS post_renderers,
124- ".$DB->quote($item_assigned_user_ID)." AS post_assigned_user_ID,
125- ".$DB->quote($item_typ_ID)." AS post_ptyp_ID,
126- ".$DB->quote($item_st_ID)." AS post_pst_ID,
127- ".$DB->quote($item_deadline)." AS post_datedeadline,
128- ".$DB->quote($item_priority)." AS post_priority,
129- NULL AS post_editor_code,";
130-
131- $this->sql .= $DB->quote(param( 'item_order', 'double', NULL )).' AS post_order'.",\n"
132- .$DB->quote(param( 'item_featured', 'integer', NULL )).' AS post_featured'."\n";
133- $this->total_rows = 1;
134- $this->total_pages = 1;
135- $this->page = 1;
136-
137- // ATTENTION: we skip the parent on purpose here!! fp> refactor
138- DataObjectList2::query( false, false, false, 'PREVIEW QUERY' );
139-
140- $Item = & $this->Cache->instantiate( $this->rows[0] );
141+ // Get basic params:
142+ param( 'post_category', 'integer', true );
143+ param( 'post_extracats', 'array', array() );
144+ param( 'post_status', 'string', 'published' );
145+
146+ // Make sure main cat is in extracat list and there are no duplicates:
147+ $post_extracats[] = $post_category;
148+ $post_extracats = array_unique( $post_extracats );
149+ // Check permission on statuses:
150+ $current_User->check_perm( 'cats_post!'.$post_status, 'edit', true, $post_extracats );
151+
152+ // Create new item:
153+ $Item = new Item();
154+
155+ // Set the params we already got:
156+ $Item->set( 'status', $post_status );
157+ $Item->set( 'main_cat_ID', $post_category );
158+ $Item->set( 'extra_cat_IDs', $post_extracats );
159+
160+ // Set more params, just to be sure everything works.
161+ $localtimenow_sql = date2mysql( $localtimenow );
162+ $Item->set_param( 'datemodified', 'date', $localtimenow_sql );
163+ $Item->set_param( 'datecreated', 'date', $localtimenow_sql );
164+ // Pretend notifications are already done:
165+ $Item->set( 'notifications_status', 'finished' );
166+
167+ // Set user info:
168+ $Item->set_creator_User( $current_User );
169+ $Item->set( 'lastedit_user_ID', $current_User->ID );
170+
171+ // Load all the other params (from the form):
172+ $Item->load_from_Request();
173
174 // Trigger plugin event, allowing to manipulate or validate the item before it gets previewed
175 $Plugins->trigger_event( 'AppendItemPreviewTransact', array( 'Item' => & $Item ) );
176
177 if( $errcontent = $Messages->display( T_('Invalid post, please correct these errors:'), '', false, 'error' ) )
178- {
179- $Item->content = $errcontent."\n<hr />\n".$content;
180+ { // There have been errors:
181+ $Item->content = $errcontent."\n<hr />\n".$Item->content;
182 }
183
184 // little funky fix for IEwin, rawk on that code
185@@ -215,6 +137,20 @@
186 { // QUESTION: Is this still needed? What about $IEWin_bookmarklet_fix? (blueyed)
187 $Item->content = preg_replace('/\%u([0-9A-F]{4,4})/e', "'&#'.base_convert('\\1',16,10). ';'", $Item->content);
188 }
189+
190+ // Add the forged Item to the cache:
191+ $this->Cache->add( $Item );
192+
193+ // The really ugly code starts here -- we are going to add a fake row
194+ // to accommodate DateObjectList2::get_by_idx().
195+ // First, increase number of rows:
196+ $this->result_num_rows++;
197+
198+ // Now create the fake row. It only contains the item ID.
199+ $fake_row = new stdClass();
200+ $fake_row->post_ID = 0;
201+
202+ $this->rows[] = & $fake_row;
203 }
204
205
206
207=== modified file 'inc/items/views/_item_expert.form.php'
208--- inc/items/views/_item_expert.form.php 2010-02-19 10:50:37 +0000
209+++ inc/items/views/_item_expert.form.php 2010-04-19 16:19:23 +0000
210@@ -82,7 +82,6 @@
211 // In case we send this to the blog for a preview :
212 $Form->hidden( 'preview', 1 );
213 $Form->hidden( 'more', 1 );
214-$Form->hidden( 'preview_userid', $current_User->ID );
215 ?>
216
217 <div class="left_col">

Subscribers

People subscribed via source and target branches