function tsearch($name, $answer, $s, $t, $sb = '', $sa = '') { require_once 'class.ilannotations-searchmanager.php'; $sm = new ILAnnotations_Searchmanager($s, $t, $sb, $sa); $rg = $sm->solve(); $nt = preg_replace($rg, '$1[annot]$2[/annot]$3', $t); if ($answer == $nt) { echo "<h3 style='color:white; background-color:green;'>" . $name . " passed</h3>"; } else { echo "<h1 style='color:white; background-color:red;'>" . $name . " failed</h1>"; } echo "<ul>"; echo "<li>Searchstring: " . htmlentities($s) . "</li>"; echo "<li>Search Regex: " . htmlentities($rg) . "</li>"; echo "<li>Text: " . htmlentities($t) . "</li>"; echo "<li>New Text: " . htmlentities($nt) . "</li>"; echo "</ul>"; return $nt; }
/** * wp_insert_comment hook callback * Adds the annotation shortcodes to the content of the post * @param $id the id of the comment * @param $comment the Comment */ public static function wp_insert_comment_handle_annotation($id, $comment) { if (array_key_exists("comment_quote", $_POST)) { $postid = $comment->comment_post_ID; $post = get_post($postid); $content = $post->post_content; $idprev = intval($_POST["comment_quote_idprev"]); $idafter = intval($_POST["comment_quote_idafter"]); $elements = preg_split('/\\n\\s*\\n/', $content, -1, PREG_SPLIT_NO_EMPTY); if ($idprev > 0) { $elements[$idprev - 1] = $elements[$idprev - 1] . '[ILAS-aasdfklahsdkfahslödfkahsdöf]'; } if ($idafter > 0) { $elements[$idafter - 1] = $elements[$idafter - 1] . '[ILAS-aasdfklahsdkfahslödfkahsdöf]'; } $content = implode("\n\n", $elements); if (!($idprev > 0)) { $content = '[ILAS-aasdfklahsdkfahslödfkahsdöf]' . $content; } if (!($idafter > 0)) { $content = $content . '[ILAS-aasdfklahsdkfahslödfkahsdöf]'; } $contents = explode('[ILAS-aasdfklahsdkfahslödfkahsdöf]', $content); require_once 'class.ilannotations-searchmanager.php'; //find the right regex expression to add the shortcodes $sm = new ILAnnotations_Searchmanager($_POST["comment_quote"], $contents[1], $_POST["comment_quote_prev"], $_POST["comment_quote_after"]); $rg = $sm->solve(); //add the shortcodes to the content if ($rg !== false && $rg != "") { $contents[1] = preg_replace($rg, '$1[annot-s c="' . $id . '"/]$2[annot-e c="' . $id . '"/]$3', $contents[1]); } else { $contents[1] = '[annot-s c="' . $id . '"/]' . $contents[1] . '[annot-e c="' . $id . '"/]'; } $nc = implode("", $contents); //save the post $new_post = array('ID' => $postid, 'post_content' => $nc); wp_update_post(add_magic_quotes($new_post)); } }