function test_embed_filter_and_lookup() { // Test filter returns non-empty ID $html = 'testing<br />'; $id = admin_embed_filter($html); $this->assertGreaterThan(0, strlen($id)); // Perform lookup $this->assertEquals($html, admin_embed_lookup($id)); // Filter in reverse, same as lookup $this->assertEquals($html, admin_embed_filter($id, true)); }
/** * The filter to save dynamic HTML embeds and get an ID value for them. * Saves to `cache/html/${md5($html)}.html`. * * If `$reverse` is set to true, it will call `admin_embed_lookup()` * instead to retrieve the original value, as dynamic embed filters * are supposed to do. */ function admin_embed_filter($html, $reverse = false) { if ($reverse) { return admin_embed_lookup($html); } if (!@file_exists('cache/html')) { mkdir('cache/html', 0777); } $id = md5($html); file_put_contents('cache/html/' . $id . '.html', $html); return $id; }
<?php /** * Reverse lookup of HTML code from ID values. * Used in dynamic embeds so you can paste arbitrary * HTML into a page without alteration by the * WYSIWYG editor. */ require_once 'apps/admin/lib/Functions.php'; echo admin_embed_lookup($data['id']);