Index: trunk/extensions/SemanticForms/includes/SF_FormPrinter.php |
— | — | @@ -124,6 +124,25 @@ |
125 | 125 | return false; |
126 | 126 | } |
127 | 127 | |
| 128 | + /** |
| 129 | + * Like PHP's str_replace(), but only replaces the first found instance - |
| 130 | + * unfortunately, str_replace() doesn't allow for that. |
| 131 | + * This code is basically copied directly from |
| 132 | + * http://www.php.net/manual/en/function.str-replace.php#86177 |
| 133 | + * - this might make sense in some SF utils class, if it's useful in |
| 134 | + * other places. |
| 135 | + */ |
| 136 | + function strReplaceOnce( $search, $replace, $subject) { |
| 137 | + $firstChar = strpos( $subject, $search ); |
| 138 | + if ( $firstChar !== false ) { |
| 139 | + $beforeStr = substr( $subject, 0, $firstChar ); |
| 140 | + $afterStr = substr( $subject, $firstChar + strlen( $search ) ); |
| 141 | + return $beforeStr . $replace . $afterStr; |
| 142 | + } else { |
| 143 | + return $subject; |
| 144 | + } |
| 145 | + } |
| 146 | + |
128 | 147 | function formHTML( $form_def, $form_submitted, $source_is_page, $form_id = null, $existing_page_content = null, $page_name = null, $page_name_formula = null, $is_query = false, $embedded = false ) { |
129 | 148 | global $wgRequest, $wgUser, $wgParser; |
130 | 149 | global $sfgTabIndex; // used to represent the current tab index in the form |
— | — | @@ -421,7 +440,7 @@ |
422 | 441 | $existing_page_content = str_replace( $existing_template_text, '{{{insertionpoint}}}', $existing_page_content ); |
423 | 442 | } |
424 | 443 | } else { |
425 | | - $existing_page_content = str_replace( $existing_template_text, '', $existing_page_content ); |
| 444 | + $existing_page_content = self::strReplaceOnce( $existing_template_text, '', $existing_page_content ); |
426 | 445 | } |
427 | 446 | // if this is not a multiple-instance template, and we've found |
428 | 447 | // a match in the source page, there's a good chance that this |