uid) { if (preg_match('!^((([01]?[0-9])|(2[0-3])):([0-5][0-9])(:([0-5][0-9]))?([:\^][0-9]|¹|²|³)?) s(.)(.*[^\\\])\9(.*[^\\\])\9([ig]?)$!', $post['message'], $matches)) { $clock = $matches[1]; $posts = tribune_get_posts_from_clock($clock); if (count($posts)) { $separator = $matches[9]; $from = str_replace('\\'.$separator, $separator, $matches[10]); $to = str_replace('\\'.$separator, $separator, $matches[11]); $options = $matches[12]; $limit = 1; if (strpos($options, 'g') !== false) { $limit = -1; $options = str_replace('g', '', $options); } $from = str_replace('/', '\\/', $from); $expression = 's/'.$from.'/'.$to.'/'.$options; foreach ($posts as $id) { $ref_post = tribune_get_post($id); if ($ref_post and (tribune_variable_get('tribune_regex_allow_all_posts', false) or $ref_post['uid'] == $user->uid)) { $new_message = preg_replace('/'.$from.'/'.$options, $to, $ref_post['message'], $limit, $count); if ($count and $new_message) { $ref_post['message'] = $new_message; if (tribune_variable_get('tribune_regex_in_place', false)) { $ref_post['parsed'] = print_message(tribune_slip($new_message)); tribune_update_post($ref_post); if (!tribune_variable_get('tribune_regex_show_posts', true)) { $post = null; } } else { if (tribune_variable_get('tribune_regex_show_posts', true)) { $post['message'] .= ': '.$ref_post['message']; } else { $post['message'] = $ref_post['message']; } } } } } } } } } function tribune_regex_settings () { $form = array(); $form['tribune_regex_show_posts'] = array( '#type' => "checkbox", '#title' => t("Show modification posts"), '#default_value' => tribune_variable_get('tribune_regex_show_posts', true), '#description' => t("If this is unchecked, posts which modify another post will not be shown (this means that there will be no way whatsoever to know which posts have been modified)"), ); $form['tribune_regex_allow_all_posts'] = array( '#type' => "checkbox", '#title' => t("Allow everybody to modify all posts"), '#default_value' => tribune_variable_get('tribune_regex_allow_all_posts', false), '#description' => t("If this is checked, everybody (including anonymous users) will be able to modify any post. Otherwise, only registered users can change their own posts."), ); $form['tribune_regex_allow_anonymous'] = array( '#type' => "checkbox", '#title' => t("Allow corrections by anonymous users"), '#default_value' => tribune_variable_get('tribune_regex_allow_anonymous', true), ); $form['tribune_regex_in_place'] = array( '#type' => "checkbox", '#title' => t("Modify posts in place"), '#default_value' => tribune_variable_get('tribune_regex_in_place', false), '#description' => t("If this is unchecked, instead of modifying posts « in place » the correction will be shown in a new post."), ); return tribune_settings_form($form); }