@@ -86,7 +86,9 @@ public static function getSubscribedEvents()
8686 'core.viewtopic_modify_page_title ' => 'show_idea ' ,
8787 'core.viewtopic_add_quickmod_option_before ' => 'adjust_quickmod_tools ' ,
8888 'core.viewonline_overwrite_location ' => 'viewonline_ideas ' ,
89- 'core.posting_modify_submit_post_after ' => 'edit_idea_title ' ,
89+ 'core.posting_modify_template_vars ' => 'submit_idea_template ' ,
90+ 'core.posting_modify_submit_post_before ' => 'submit_idea_before ' ,
91+ 'core.posting_modify_submit_post_after ' => ['submit_idea_after ' , 'edit_idea_title ' ],
9092 );
9193 }
9294
@@ -275,26 +277,81 @@ public function adjust_quickmod_tools($event)
275277 */
276278 public function viewonline_ideas ($ event )
277279 {
278- if ($ event ['on_page ' ][1 ] === 'app ' )
279- {
280- if (strrpos ($ event ['row ' ]['session_page ' ], 'app. ' . $ this ->php_ext . '/ideas/post ' ) === 0 )
281- {
282- $ event ['location ' ] = $ this ->language ->lang ('POSTING_NEW_IDEA ' );
283- $ event ['location_url ' ] = $ this ->helper ->route ('phpbb_ideas_index_controller ' );
284- }
285- else if (strrpos ($ event ['row ' ]['session_page ' ], 'app. ' . $ this ->php_ext . '/ideas ' ) === 0 )
286- {
287- $ event ['location ' ] = $ this ->language ->lang ('VIEWING_IDEAS ' );
288- $ event ['location_url ' ] = $ this ->helper ->route ('phpbb_ideas_index_controller ' );
289- }
290- }
291- else if ($ event ['on_page ' ][1 ] === 'viewtopic ' && $ event ['row ' ]['session_forum_id ' ] == $ this ->config ['ideas_forum_id ' ])
280+ if (($ event ['on_page ' ][1 ] === 'viewtopic ' && $ event ['row ' ]['session_forum_id ' ] == $ this ->config ['ideas_forum_id ' ]) ||
281+ ($ event ['on_page ' ][1 ] === 'app ' && strrpos ($ event ['row ' ]['session_page ' ], 'app. ' . $ this ->php_ext . '/ideas ' ) === 0 ))
292282 {
293283 $ event ['location ' ] = $ this ->language ->lang ('VIEWING_IDEAS ' );
294284 $ event ['location_url ' ] = $ this ->helper ->route ('phpbb_ideas_index_controller ' );
295285 }
296286 }
297287
288+ /**
289+ * Modify the Ideas forum's posting page
290+ *
291+ * @param \phpbb\event\data $event The event object
292+ */
293+ public function submit_idea_template ($ event )
294+ {
295+ if (!$ this ->is_ideas_forum ($ event ['forum_id ' ]))
296+ {
297+ return ;
298+ }
299+
300+ // Alter some posting page template vars
301+ if ($ event ['mode ' ] === 'post ' )
302+ {
303+ $ event ['page_title ' ] = $ this ->language ->lang ('POST_IDEA ' );
304+ $ event ->update_subarray ('page_data ' , 'L_POST_A ' , $ this ->language ->lang ('POST_IDEA ' ));
305+ $ event ->update_subarray ('page_data ' , 'U_VIEW_FORUM ' , $ this ->helper ->route ('phpbb_ideas_index_controller ' ));
306+ }
307+
308+ // Alter posting page breadcrumbs to link to the ideas controller
309+ $ this ->template ->alter_block_array ('navlinks ' , [
310+ 'U_BREADCRUMB ' => $ this ->helper ->route ('phpbb_ideas_index_controller ' ),
311+ 'BREADCRUMB_NAME ' => $ this ->language ->lang ('IDEAS ' ),
312+ ], false , 'change ' );
313+ }
314+
315+ /**
316+ * Prepare post data vars before posting a new idea/topic.
317+ *
318+ * @param \phpbb\event\data $event The event object
319+ */
320+ public function submit_idea_before ($ event )
321+ {
322+ if (!$ this ->is_post_idea ($ event ['mode ' ], $ event ['data ' ]['forum_id ' ], empty ($ event ['data ' ]['topic_id ' ])))
323+ {
324+ return ;
325+ }
326+
327+ // We need $post_time after submit_post(), but it's not available in the post $data, unless we set it now
328+ $ event ->update_subarray ('data ' , 'post_time ' , time ());
329+ }
330+
331+ /**
332+ * Submit the idea data after posting a new idea/topic.
333+ *
334+ * @param \phpbb\event\data $event The event object
335+ */
336+ public function submit_idea_after ($ event )
337+ {
338+ if (!$ this ->is_post_idea ($ event ['mode ' ], $ event ['data ' ]['forum_id ' ], !empty ($ event ['data ' ]['topic_id ' ])))
339+ {
340+ return ;
341+ }
342+
343+ $ this ->ideas ->submit ($ event ['data ' ]);
344+
345+ // Show users who's posts need approval a special message
346+ if (!$ this ->auth ->acl_get ('f_noapprove ' , $ event ['data ' ]['forum_id ' ]))
347+ {
348+ // Using refresh and trigger error because we can't throw http_exceptions from posting.php
349+ $ url = $ this ->helper ->route ('phpbb_ideas_index_controller ' );
350+ meta_refresh (10 , $ url );
351+ trigger_error ($ this ->language ->lang ('IDEA_STORED_MOD ' , $ url ));
352+ }
353+ }
354+
298355 /**
299356 * Update the idea's title when post title is edited.
300357 *
@@ -316,6 +373,31 @@ public function edit_idea_title($event)
316373 $ this ->ideas ->set_title ($ idea ['idea_id ' ], $ event ['post_data ' ]['post_subject ' ]);
317374 }
318375
376+ /**
377+ * Test if we are on the posting page for a new idea
378+ *
379+ * @param string $mode Mode should be post
380+ * @param int $forum_id The forum posting is being made in
381+ * @param bool $topic_flag Flag for the state of the topic_id
382+ *
383+ * @return bool True if mode is post, forum is Ideas forum, and a topic id is
384+ * expected to exist yet, false if any of these tests failed.
385+ */
386+ protected function is_post_idea ($ mode , $ forum_id , $ topic_flag = true )
387+ {
388+ if ($ mode !== 'post ' )
389+ {
390+ return false ;
391+ }
392+
393+ if (!$ this ->is_ideas_forum ($ forum_id ))
394+ {
395+ return false ;
396+ }
397+
398+ return $ topic_flag ;
399+ }
400+
319401 /**
320402 * Check if forum id is for the ideas the forum
321403 *
0 commit comments